Skip to content

Commit

Permalink
msvc: add simde_MemoryBarrier to avoid including <windows.h>
Browse files Browse the repository at this point in the history
  • Loading branch information
Epixu authored and mr-c committed Aug 12, 2024
1 parent bd05320 commit f47e3c5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
57 changes: 51 additions & 6 deletions simde/x86/sse.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,60 @@
#include "mmx.h"
#include "../simde-f16.h"

#if defined(_WIN32) && !defined(SIMDE_X86_SSE_NATIVE) && defined(_MSC_VER)
#define NOMINMAX
#include <windows.h>
#endif

#if defined(__ARM_ACLE)
#include <arm_acle.h>
#endif

#ifdef _MSC_VER
#if defined(SIMDE_ARCH_AARCH64)
#include <intrin.h>

typedef enum simde_tag_ARM64INTR_BARRIER_TYPE
{
SIMDE_ARM64_BARRIER_SY = 0xF,
}
SIMDE_ARM64INTR_BARRIER_TYPE;

HEDLEY_ALWAYS_INLINE
void simde_MemoryBarrier(void) {
__dmb(SIMDE_ARM64_BARRIER_SY);
}
#elif defined(SIMDE_ARCH_ARM)
#include <intrin.h>

typedef enum simde_tag_ARMINTR_BARRIER_TYPE
{
SIMDE_ARM_BARRIER_SY = 0xF,
}
SIMDE_ARMINTR_BARRIER_TYPE;

HEDLEY_ALWAYS_INLINE
void simde_MemoryBarrier(void) {
__dmb(SIMDE_ARM_BARRIER_SY);
}
#elif defined(SIMDE_ARCH_X86) || defined(SIMDE_ARCH_AMD64) || defined(SIMDE_ARCH_E2K)
#if !defined(SIMDE_X86_SSE_NO_NATIVE)
#include <intrin.h>
#endif

HEDLEY_ALWAYS_INLINE
void simde_MemoryBarrier(void) {
#if defined(SIMDE_X86_SSE_NO_NATIVE)
((void)0); // intentionally no-op
#elif defined(SIMDE_ARCH_AMD64)
__faststorefence();
#elif defined(SIMDE_ARCH_IA64)
__mf();
#else
long Barrier;
__asm { xchg Barrier, eax }
#endif
}
#else
#error "Missing implementation"
#endif
#endif

HEDLEY_DIAGNOSTIC_PUSH
SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
SIMDE_BEGIN_DECLS_
Expand Down Expand Up @@ -4007,7 +4052,7 @@ simde_mm_sfence (void) {
atomic_thread_fence(memory_order_seq_cst);
#endif
#elif defined(_MSC_VER)
MemoryBarrier();
simde_MemoryBarrier();
#elif HEDLEY_HAS_EXTENSION(c_atomic)
__c11_atomic_thread_fence(__ATOMIC_SEQ_CST);
#elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
Expand Down
2 changes: 1 addition & 1 deletion simde/x86/sse2.h
Original file line number Diff line number Diff line change
Expand Up @@ -4776,7 +4776,7 @@ simde_mm_pause (void) {
#endif
#elif defined(SIMDE_ARCH_ARM_NEON)
#if defined(_MSC_VER)
__isb(_ARM64_BARRIER_SY);
__isb(SIMDE_ARM64_BARRIER_SY);
#else
__asm__ __volatile__("isb\n");
#endif
Expand Down

0 comments on commit f47e3c5

Please sign in to comment.