Просмотр исходного кода

fix test 92 not failing properly on GCC/amd64

tevador 6 лет назад
Родитель
Сommit
148b923f71
3 измененных файлов с 24 добавлено и 3 удалено
  1. 15 0
      src/instructions_portable.cpp
  2. 6 0
      src/intrin_portable.h
  3. 3 3
      src/tests/tests.cpp

+ 15 - 0
src/instructions_portable.cpp

@@ -157,6 +157,21 @@ void rx_set_rounding_mode(uint32_t mode) {
 	}
 }
 
+uint32_t rx_get_rounding_mode() {
+	switch (fegetround()) {
+	case FE_DOWNWARD:
+		return RoundDown;
+	case FE_UPWARD:
+		return RoundUp;
+	case FE_TOWARDZERO:
+		return RoundToZero;
+	case FE_TONEAREST:
+		return RoundToNearest;
+	default:
+		UNREACHABLE;
+	}
+}
+
 #endif
 
 #ifdef RANDOMX_USE_X87

+ 6 - 0
src/intrin_portable.h

@@ -173,6 +173,10 @@ FORCE_INLINE void rx_set_rounding_mode(uint32_t mode) {
 	_mm_setcsr(rx_mxcsr_default | (mode << 13));
 }
 
+FORCE_INLINE uint32_t rx_get_rounding_mode() {
+	return (_mm_getcsr() >> 13) & 3;
+}
+
 #elif defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__) //sadly only POWER7 and newer will be able to use SIMD acceleration. Earlier processors cant use doubles or 64 bit integers with SIMD
 #include <cstdint>
 #include <stdexcept>
@@ -736,6 +740,8 @@ void rx_reset_float_state();
 
 void rx_set_rounding_mode(uint32_t mode);
 
+uint32_t rx_get_rounding_mode();
+
 #endif
 
 double loadDoublePortable(const void* addr);

+ 3 - 3
src/tests/tests.cpp

@@ -4,7 +4,6 @@
 
 #include <cassert>
 #include <iomanip>
-#include <cfenv>
 #include "utility.hpp"
 #include "../bytecode_machine.hpp"
 #include "../dataset.hpp"
@@ -1076,10 +1075,11 @@ int main() {
 	});
 
 	runTest("Preserve rounding mode", RANDOMX_FREQ_CFROUND > 0, []() {
-		fesetround(FE_TONEAREST);
+		rx_set_rounding_mode(RoundToNearest);
 		char hash[RANDOMX_HASH_SIZE];
 		calcStringHash("test key 000", "Lorem ipsum dolor sit amet", &hash);
-		assert(fegetround() == FE_TONEAREST);
+		assert(equalsHex(hash, "300a0adb47603dedb42228ccb2b211104f4da45af709cd7547cd049e9489c969"));
+		assert(rx_get_rounding_mode() == RoundToNearest);
 	});
 
 	randomx_destroy_vm(vm);