-#define ENABLE_OPERATORS_ON(T) \
-inline T operator+ (const T d1, const T d2) { return T(int(d1) + int(d2)); } \
-inline T operator- (const T d1, const T d2) { return T(int(d1) - int(d2)); } \
-inline T operator* (int i, const T d) { return T(i * int(d)); } \
-inline T operator* (const T d, int i) { return T(int(d) * i); } \
-inline T operator/ (const T d, int i) { return T(int(d) / i); } \
-inline T operator- (const T d) { return T(-int(d)); } \
-inline T operator++ (T& d, int) {d = T(int(d) + 1); return d; } \
-inline T operator-- (T& d, int) { d = T(int(d) - 1); return d; } \
-inline T& operator+= (T& d1, const T d2) { d1 = d1 + d2; return d1; } \
-inline T& operator-= (T& d1, const T d2) { d1 = d1 - d2; return d1; } \
-inline T& operator*= (T& d, int i) { d = T(int(d) * i); return d; } \
-inline T& operator/= (T& d, int i) { d = T(int(d) / i); return d; }
+/// On Intel 64 bit we have a small speed regression with the standard conforming
+/// version. Therefore, in this case we use faster code that, although not 100%
+/// standard compliant, seems to work for Intel and MSVC.
+#if defined(IS_64BIT) && (!defined(__GNUC__) || defined(__INTEL_COMPILER))
+
+inline Value eg_value(Score s) { return Value(int16_t(s & 0xffff)); }
+
+#else
+
+inline Value eg_value(Score s) {
+ return Value((int)(unsigned(s) & 0x7fffu) - (int)(unsigned(s) & 0x8000u));
+}
+
+#endif
+
+#define ENABLE_SAFE_OPERATORS_ON(T) \
+inline T operator+(const T d1, const T d2) { return T(int(d1) + int(d2)); } \
+inline T operator-(const T d1, const T d2) { return T(int(d1) - int(d2)); } \
+inline T operator*(int i, const T d) { return T(i * int(d)); } \
+inline T operator*(const T d, int i) { return T(int(d) * i); } \
+inline T operator-(const T d) { return T(-int(d)); } \
+inline T& operator+=(T& d1, const T d2) { return d1 = d1 + d2; } \
+inline T& operator-=(T& d1, const T d2) { return d1 = d1 - d2; } \
+inline T& operator*=(T& d, int i) { return d = T(int(d) * i); }
+
+#define ENABLE_OPERATORS_ON(T) ENABLE_SAFE_OPERATORS_ON(T) \
+inline T& operator++(T& d) { return d = T(int(d) + 1); } \
+inline T& operator--(T& d) { return d = T(int(d) - 1); } \
+inline T operator/(const T d, int i) { return T(int(d) / i); } \
+inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }