[CRT] Fix intrinsics definition with clang

This commit is contained in:
Jérôme Gardou 2020-09-10 23:24:59 +02:00 committed by Jérôme Gardou
parent edc1f3ca56
commit f96e47db43
3 changed files with 84 additions and 45 deletions

View file

@ -30,13 +30,21 @@
#ifndef RC_INVOKED
#ifdef __clang__
#define __INTRIN_INLINE __forceinline
#define HAS_BUILTIN(x) __has_builtin(x)
#else
#define HAS_BUILTIN(x) 0
#define __ATTRIBUTE_ARTIFICIAL __attribute__((artificial))
#define __INTRIN_INLINE extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) __ATTRIBUTE_ARTIFICIAL
#ifndef __INTRIN_INLINE
# ifdef __clang__
# define __ATTRIBUTE_ARTIFICIAL
# else
# define __ATTRIBUTE_ARTIFICIAL __attribute__((artificial))
# endif
# define __INTRIN_INLINE extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) __ATTRIBUTE_ARTIFICIAL
#endif
#ifndef HAS_BUILTIN
# ifdef __clang__
# define HAS_BUILTIN(x) __has_builtin(x)
# else
# define HAS_BUILTIN(x) 0
# endif
#endif
#ifndef _SIZE_T_DEFINED

View file

@ -133,15 +133,19 @@ __INTRIN_INLINE void __faststorefence(void)
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
#if !HAS_BUILTIN(_InterlockedCompareExchange8)
__INTRIN_INLINE char _InterlockedCompareExchange8(volatile char * Destination, char Exchange, char Comperand)
{
return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
}
#endif
#if !HAS_BUILTIN(_InterlockedCompareExchange16)
__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short * Destination, short Exchange, short Comperand)
{
return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
}
#endif
#if !HAS_BUILTIN(_InterlockedCompareExchange)
__INTRIN_INLINE long __cdecl _InterlockedCompareExchange(volatile long * Destination, long Exchange, long Comperand)
@ -157,19 +161,23 @@ __INTRIN_INLINE void * _InterlockedCompareExchangePointer(void * volatile * Dest
}
#endif
#if !HAS_BUILTIN(_InterlockedExchange8)
__INTRIN_INLINE char _InterlockedExchange8(volatile char * Target, char Value)
{
/* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we force a full barrier */
__sync_synchronize();
return __sync_lock_test_and_set(Target, Value);
}
#endif
#if !HAS_BUILTIN(_InterlockedExchange16)
__INTRIN_INLINE short _InterlockedExchange16(volatile short * Target, short Value)
{
/* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we force a full barrier */
__sync_synchronize();
return __sync_lock_test_and_set(Target, Value);
}
#endif
#if !HAS_BUILTIN(_InterlockedExchange)
__INTRIN_INLINE long __cdecl _InterlockedExchange(volatile long * Target, long Value)
@ -198,15 +206,19 @@ __INTRIN_INLINE long long _InterlockedExchange64(volatile long long * Target, lo
}
#endif
#if !HAS_BUILTIN(_InterlockedExchangeAdd8)
__INTRIN_INLINE char _InterlockedExchangeAdd8(char volatile * Addend, char Value)
{
return __sync_fetch_and_add(Addend, Value);
}
#endif
#if !HAS_BUILTIN(_InterlockedExchangeAdd16)
__INTRIN_INLINE short _InterlockedExchangeAdd16(volatile short * Addend, short Value)
{
return __sync_fetch_and_add(Addend, Value);
}
#endif
#if !HAS_BUILTIN(_InterlockedExchangeAdd)
__INTRIN_INLINE long __cdecl _InterlockedExchangeAdd(volatile long * Addend, long Value)
@ -222,20 +234,26 @@ __INTRIN_INLINE long long _InterlockedExchangeAdd64(volatile long long * Addend,
}
#endif
#if !HAS_BUILTIN(_InterlockedAnd8)
__INTRIN_INLINE char _InterlockedAnd8(volatile char * value, char mask)
{
return __sync_fetch_and_and(value, mask);
}
#endif
#if !HAS_BUILTIN(_InterlockedAnd16)
__INTRIN_INLINE short _InterlockedAnd16(volatile short * value, short mask)
{
return __sync_fetch_and_and(value, mask);
}
#endif
#if !HAS_BUILTIN(_InterlockedAnd)
__INTRIN_INLINE long _InterlockedAnd(volatile long * value, long mask)
{
return __sync_fetch_and_and(value, mask);
}
#endif
#if defined(__x86_64__)
__INTRIN_INLINE long long _InterlockedAnd64(volatile long long * value, long long mask)
@ -244,20 +262,26 @@ __INTRIN_INLINE long long _InterlockedAnd64(volatile long long * value, long lon
}
#endif
#if !HAS_BUILTIN(_InterlockedOr8)
__INTRIN_INLINE char _InterlockedOr8(volatile char * value, char mask)
{
return __sync_fetch_and_or(value, mask);
}
#endif
#if !HAS_BUILTIN(_InterlockedOr16)
__INTRIN_INLINE short _InterlockedOr16(volatile short * value, short mask)
{
return __sync_fetch_and_or(value, mask);
}
#endif
#if !HAS_BUILTIN(_InterlockedOr)
__INTRIN_INLINE long _InterlockedOr(volatile long * value, long mask)
{
return __sync_fetch_and_or(value, mask);
}
#endif
#if defined(__x86_64__)
__INTRIN_INLINE long long _InterlockedOr64(volatile long long * value, long long mask)
@ -266,20 +290,26 @@ __INTRIN_INLINE long long _InterlockedOr64(volatile long long * value, long long
}
#endif
#if !HAS_BUILTIN(_InterlockedXor8)
__INTRIN_INLINE char _InterlockedXor8(volatile char * value, char mask)
{
return __sync_fetch_and_xor(value, mask);
}
#endif
#if !HAS_BUILTIN(_InterlockedXor16)
__INTRIN_INLINE short _InterlockedXor16(volatile short * value, short mask)
{
return __sync_fetch_and_xor(value, mask);
}
#endif
#if !HAS_BUILTIN(_InterlockedXor)
__INTRIN_INLINE long _InterlockedXor(volatile long * value, long mask)
{
return __sync_fetch_and_xor(value, mask);
}
#endif
#if defined(__x86_64__)
__INTRIN_INLINE long long _InterlockedXor64(volatile long long * value, long long mask)
@ -302,15 +332,19 @@ __INTRIN_INLINE long __cdecl _InterlockedIncrement(volatile long * lpAddend)
}
#endif
#if !HAS_BUILTIN(_InterlockedDecrement16)
__INTRIN_INLINE short _InterlockedDecrement16(volatile short * lpAddend)
{
return __sync_sub_and_fetch(lpAddend, 1);
}
#endif
#if !HAS_BUILTIN(_InterlockedIncrement16)
__INTRIN_INLINE short _InterlockedIncrement16(volatile short * lpAddend)
{
return __sync_add_and_fetch(lpAddend, 1);
}
#endif
#if defined(__x86_64__)
__INTRIN_INLINE long long _InterlockedDecrement64(volatile long long * lpAddend)
@ -1696,13 +1730,6 @@ __INTRIN_INLINE void __writecr4(unsigned int Data)
__asm__("mov %[Data], %%cr4" : : [Data] "r" (Data) : "memory");
}
#if !HAS_BUILTIN(__writecr8)
__INTRIN_INLINE void __writecr8(unsigned int Data)
{
__asm__("mov %[Data], %%cr8" : : [Data] "r" (Data) : "memory");
}
#endif
__INTRIN_INLINE unsigned long __readcr0(void)
{
unsigned long value;
@ -1731,15 +1758,6 @@ __INTRIN_INLINE unsigned long __readcr4(void)
return value;
}
#if !HAS_BUILTIN(__readcr8)
__INTRIN_INLINE unsigned long __readcr8(void)
{
unsigned long value;
__asm__ __volatile__("mov %%cr8, %[value]" : [value] "=r" (value));
return value;
}
#endif
#endif /* __x86_64__ */
#ifdef __x86_64__

View file

@ -55,49 +55,62 @@ void _mm_setcsr(unsigned int);
#ifndef __clang__
#pragma intrinsic(_mm_xor_ps)
#pragma intrinsic(_mm_div_ps)
#else
/*
* Clang implements these as inline functions in the header instead of real builtins
*/
__forceinline __m128 _mm_xor_ps(__m128 a, __m128 b)
{
return (__m128)((__v4su)a ^ (__v4su)b);
}
__forceinline __m128 _mm_div_ps(__m128 a, __m128 b)
{
return (__m128)((__v4sf)a / (__v4sf)b);
}
#endif /* __clang__ */
#else /* _MSC_VER */
#if !defined(__INTRIN_INLINE) && !defined(__clang__)
#define __ATTRIBUTE_ARTIFICIAL __attribute__((artificial))
#define __INTRIN_INLINE extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) __ATTRIBUTE_ARTIFICIAL
#endif /* !__INTRIN_INLINE && !__clang__ */
#if !defined(__INTRIN_INLINE)
# ifdef __clang__
# define __ATTRIBUTE_ARTIFICIAL
# else
# define __ATTRIBUTE_ARTIFICIAL __attribute__((artificial))
# endif
# define __INTRIN_INLINE extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) __ATTRIBUTE_ARTIFICIAL
#endif /* !__INTRIN_INLINE */
/*
#ifndef HAS_BUILTIN
#ifdef __clang__
#define HAS_BUILTIN(x) __has_builtin(x)
#else
#define HAS_BUILTIN(x) 0
#endif
#endif
/*
* We can't use __builtin_ia32_* functions,
* are they are only available with the -msse2 compiler switch
*/
#if !HAS_BUILTIN(_mm_getcsr)
__INTRIN_INLINE unsigned int _mm_getcsr(void)
{
unsigned int retval;
__asm__ __volatile__("stmxcsr %0" : "=m"(retval));
return retval;
}
#endif
#if !HAS_BUILTIN(_mm_setcsr)
__INTRIN_INLINE void _mm_setcsr(unsigned int val)
{
__asm__ __volatile__("ldmxcsr %0" : : "m"(val));
}
#endif
#endif /* _MSC_VER */
#ifdef __clang__
#define __INTRIN_INLINE __forceinline
/*
* Clang implements these as inline functions in the header instead of real builtins
*/
__INTRIN_INLINE __m128 _mm_xor_ps(__m128 a, __m128 b)
{
return (__m128)((__v4su)a ^ (__v4su)b);
}
__INTRIN_INLINE __m128 _mm_div_ps(__m128 a, __m128 b)
{
return (__m128)((__v4sf)a / (__v4sf)b);
}
#endif /* __clang__ */
/* Alternate names */
#define _mm_cvtss_si32 _mm_cvt_ss2si