Skip to content

Commit

Permalink
sse2neon: update library
Browse files Browse the repository at this point in the history
fix: double calculation of angle vectors with sse instructions
fix:  cr::abs behavior for floating point arguments
  • Loading branch information
jeefo committed Oct 27, 2024
1 parent c0d1357 commit 63cfde1
Show file tree
Hide file tree
Showing 7 changed files with 413 additions and 304 deletions.
5 changes: 0 additions & 5 deletions crlib/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ template <typename T, size_t N> constexpr size_t bufsize (const T (&)[N]) {
return N - 1;
}

template <typename T> constexpr T abs (const T &a) {
return a > 0 ? a : -a;
}

template <typename T> constexpr T bit (const T &a) {
return static_cast <T> (1ULL << a);
}
Expand All @@ -41,7 +37,6 @@ template <typename T> constexpr T max (const T &a, const T &b) {
return a > b ? a : b;
}


template <typename T> constexpr T clamp (const T &x, const T &a, const T &b) {
return min (max (x, a), b);
}
Expand Down
2 changes: 1 addition & 1 deletion crlib/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ template <typename K, typename V, typename H = Hash <K>> class HashMap {

++length_;

const auto length = static_cast<float> (length_);
const auto length = static_cast <float> (length_);
const auto capacity = static_cast <float> (contents_.length ());

if (!contents_.empty () && length / capacity >= kLoadFactor) {
Expand Down
2 changes: 1 addition & 1 deletion crlib/lambda.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <typename R, typename ...Args> class Lambda <R (Args...)> final {

public:
constexpr LambdaFunctor (const LambdaFunctor &rhs) : callee_ { rhs.callee_ } {}
constexpr LambdaFunctor (LambdaFunctor &&rhs) : callee_ { cr::move (rhs.callee_) } {}
constexpr LambdaFunctor (LambdaFunctor &&rhs) noexcept : callee_ { cr::move (rhs.callee_) } {}
constexpr LambdaFunctor (const T &callee) : callee_ { callee } {}
constexpr LambdaFunctor (T &&callee) : callee_ { cr::move (callee) } {}

Expand Down
13 changes: 12 additions & 1 deletion crlib/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,20 @@ constexpr float kRadiansToDegree = 180.0f / kMathPi;
CR_NAMESPACE_END

#include <crlib/simd.h>
#include <crlib/traits.h>

CR_NAMESPACE_BEGIN

// abs() overload
template <typename T> constexpr T abs (const T &a) {
if constexpr (is_same <T, float>::value) {
return ::fabs (a);
}
else if constexpr (is_same <T, int>::value) {
return ::abs (a);
}
}

#if defined (CR_HAS_SIMD_SSE)
template <> CR_FORCE_INLINE float abs (const float &x) {
return _mm_cvtss_f32 (simd::fabs_ps (_mm_load_ss (&x)));
Expand Down Expand Up @@ -214,7 +225,7 @@ namespace detail {
#endif

template <int D> CR_FORCE_INLINE float scalar_wrapAngleFn (float x) {
return x - 2.0f * static_cast <float> (D) * cr::floorf (x / (2.0f * static_cast <float> (D)) + 0.5f);
return x - 2.0f * static_cast <float> (D) * ::floorf (x / (2.0f * static_cast <float> (D)) + 0.5f);
}

template <int D> CR_FORCE_INLINE float _wrapAngleFn (float x) {
Expand Down
7 changes: 6 additions & 1 deletion crlib/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ struct Platform : public Singleton <Platform> {
bool x64 = false;
bool arm = false;
bool ppc = false;
bool simd = false;

char appName[64] = {};

Expand Down Expand Up @@ -281,6 +282,10 @@ struct Platform : public Singleton <Platform> {
#if defined(CR_ARCH_PPC)
ppc = true;
#endif

#if !defined(CR_DISABLE_SIMD)
simd = true;
#endif
}

// set the app name
Expand All @@ -304,7 +309,7 @@ struct Platform : public Singleton <Platform> {
MEMORY_BASIC_INFORMATION mbi {};

if (VirtualQuery (reinterpret_cast <LPVOID> (ptr), &mbi, sizeof (mbi))) {
auto result = (mbi.Protect & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY));
auto result = !!(mbi.Protect & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY));

if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) {
result = false;
Expand Down
Loading

0 comments on commit 63cfde1

Please sign in to comment.