Add some funcs with fast approximation for double as well

Actually all of them can be done with /fp:fast, but I don't bother enabling it
This commit is contained in:
korenkonder
2023-12-25 08:04:53 +03:00
parent b3b3ef9f64
commit 1cdc843de0
+33
View File
@@ -7,6 +7,7 @@
#include "../default.hpp"
#include <xmmintrin.h>
#include <emmintrin.h>
namespace prj {
inline int32_t extract_sign(float_t x) {
@@ -40,4 +41,36 @@ namespace prj {
else
return ceilf(x);
}
inline int32_t extract_sign(double_t x) {
return _mm_movemask_pd(_mm_set_sd(x)) & 0x01;
}
inline double_t ceil(double_t x) {
int64_t x_int = (int64_t)x;
if (x_int != 0x8000000000000000 && (float_t)x_int != x)
x = (float_t)(x_int + !extract_sign(x));
return x;
}
inline double_t floor(double_t x) {
int64_t x_int = (int64_t)x;
if (x_int != 0x8000000000000000 && (float_t)x_int != x)
x = (float_t)(x_int - extract_sign(x));
return x;
}
inline double_t roundf(double_t x) {
if (x >= 0.0f)
return floor(x + 0.5f);
else
return ceil(x - 0.5f);
}
inline double_t truncf(double_t x) {
if (x >= 0.0f)
return floor(x);
else
return ceil(x);
}
}