summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-03-30 18:26:20 -0400
committera1xd <[email protected]>2021-03-30 18:26:20 -0400
commit4456e2bc8b9c1ef9c1aa2e3509adc8f456bb5fdc (patch)
tree1e6d3352665a0c70f5270d31c332e8950f80e3a6
parentadd zero/inf/nan guards (diff)
downloadrawaccel-4456e2bc8b9c1ef9c1aa2e3509adc8f456bb5fdc.tar.xz
rawaccel-4456e2bc8b9c1ef9c1aa2e3509adc8f456bb5fdc.zip
put utility in namespace
-rw-r--r--common/utility.hpp67
-rw-r--r--driver/driver.cpp4
2 files changed, 39 insertions, 32 deletions
diff --git a/common/utility.hpp b/common/utility.hpp
index d7b63cf..ae14b48 100644
--- a/common/utility.hpp
+++ b/common/utility.hpp
@@ -1,42 +1,49 @@
#pragma once
#ifdef _MANAGED
-
#include <math.h>
-inline double sqrtsd(double val) { return sqrt(val); }
-
#else
-
#include <emmintrin.h>
-inline double sqrtsd(double val) {
- __m128d src = _mm_load_sd(&val);
- __m128d dst = _mm_sqrt_sd(src, src);
- _mm_store_sd(&val, dst);
- return val;
-}
-
#endif
-inline constexpr double minsd(double a, double b) {
- return (a < b) ? a : b;
-}
+namespace rawaccel {
-inline constexpr double maxsd(double a, double b) {
- return (b < a) ? a : b;
-}
-
-inline constexpr double clampsd(double v, double lo, double hi) {
- return minsd(maxsd(v, lo), hi);
-}
+#ifdef _MANAGED
+ inline double sqrtsd(double val) { return sqrt(val); }
+#else
+ inline double sqrtsd(double val) {
+ __m128d src = _mm_load_sd(&val);
+ __m128d dst = _mm_sqrt_sd(src, src);
+ _mm_store_sd(&val, dst);
+ return val;
+ }
+#endif
-// returns the unbiased exponent of x if x is normal
-inline int ilogb(double x)
-{
- union { double f; unsigned long long i; } u = { x };
- return static_cast<int>((u.i >> 52) & 0x7ff) - 0x3ff;
-}
+ constexpr double minsd(double a, double b)
+ {
+ return (a < b) ? a : b;
+ }
+
+ constexpr double maxsd(double a, double b)
+ {
+ return (b < a) ? a : b;
+ }
+
+ constexpr double clampsd(double v, double lo, double hi)
+ {
+ return minsd(maxsd(v, lo), hi);
+ }
+
+ // returns the unbiased exponent of x if x is normal
+ inline int ilogb(double x)
+ {
+ union { double f; unsigned long long i; } u = { x };
+ return static_cast<int>((u.i >> 52) & 0x7ff) - 0x3ff;
+ }
+
+ inline bool infnan(double x)
+ {
+ return ilogb(x) == 0x400;
+ }
-inline bool infnan(double x)
-{
- return ilogb(x) == 0x400;
}
diff --git a/driver/driver.cpp b/driver/driver.cpp
index 5b9eca4..49f375d 100644
--- a/driver/driver.cpp
+++ b/driver/driver.cpp
@@ -82,7 +82,7 @@ Arguments:
counter_t ticks = now - devExt->counter;
devExt->counter = now;
milliseconds time = ticks * global.tick_interval;
- return clampsd(time, global.args.time_min, 100);
+ return ra::clampsd(time, global.args.time_min, 100);
};
global.modifier.apply_acceleration(input, time_supplier);
@@ -99,7 +99,7 @@ Arguments:
double carry_x = carried_result_x - out_x;
double carry_y = carried_result_y - out_y;
- if (!infnan(carry_x + carry_y)) {
+ if (!ra::infnan(carry_x + carry_y)) {
devExt->carry.x = carried_result_x - out_x;
devExt->carry.y = carried_result_y - out_y;
it->LastX = out_x;