Skip to content

Commit

Permalink
Fix compiling for Arm64 Windows with MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Apr 10, 2024
1 parent 0c236df commit 67917bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 4 additions & 0 deletions common/math/emath.h
Expand Up @@ -15,6 +15,10 @@
#if defined(__ARM_NEON)
#include "../simd/arm/emulation.h"
#else
#if defined(_M_ARM64)
// Windows MSVC allows for *mmintrin.h on Arm64 but only with USE_SOFT_INTRINSICS.
#define USE_SOFT_INTRINSICS
#endif
#include <emmintrin.h>
#include <xmmintrin.h>
#include <immintrin.h>
Expand Down
18 changes: 8 additions & 10 deletions common/sys/intrinsics.h
Expand Up @@ -12,6 +12,10 @@
#if defined(__ARM_NEON)
#include "../simd/arm/emulation.h"
#else
#if defined(_M_ARM64)
// Windows MSVC allows for immintrin.h on Arm64 but only with USE_SOFT_INTRINSICS.
#define USE_SOFT_INTRINSICS
#endif
#include <immintrin.h>
#if defined(__EMSCRIPTEN__)
#include "../simd/wasm/emulation.h"
Expand Down Expand Up @@ -89,15 +93,13 @@ namespace embree
#endif
}

#if defined(__X86_64__) || defined (__aarch64__)
__forceinline size_t bsf(size_t v) {
__forceinline uint64_t bsf(uint64_t v) {
#if defined(__AVX2__)
return _tzcnt_u64(v);
#else
unsigned long r = 0; _BitScanForward64(&r,v); return r;
#endif
}
#endif

__forceinline int bscf(int& v)
{
Expand All @@ -113,14 +115,12 @@ namespace embree
return i;
}

#if defined(__X86_64__) || defined (__aarch64__)
__forceinline size_t bscf(size_t& v)
__forceinline uint64_t bscf(uint64_t& v)
{
size_t i = bsf(v);
uint64_t i = bsf(v);
v &= v-1;
return i;
}
#endif

__forceinline int bsr(int v) {
#if defined(__AVX2__) && !defined(__aarch64__)
Expand All @@ -138,15 +138,13 @@ namespace embree
#endif
}

#if defined(__X86_64__) || defined (__aarch64__)
__forceinline size_t bsr(size_t v) {
__forceinline uint64_t bsr(uint64_t v) {
#if defined(__AVX2__)
return 63 -_lzcnt_u64(v);
#else
unsigned long r = 0; _BitScanReverse64(&r, v); return r;
#endif
}
#endif

__forceinline int lzcnt(const int x)
{
Expand Down
2 changes: 1 addition & 1 deletion common/sys/platform.h
Expand Up @@ -58,7 +58,7 @@
#endif

/* detect 64 bit platform */
#if defined(__X86_64__) || defined(__aarch64__)
#if UINTPTR_MAX == UINT64_MAX
#define __64BIT__
#endif

Expand Down

0 comments on commit 67917bf

Please sign in to comment.