Skip to content

Commit 658328c

Browse files
ahmedarif193tkreuzer
authored andcommitted
[ARM64][SDK] Fix MinGW intrinsic declarations
1 parent f6efc98 commit 658328c

2 files changed

Lines changed: 57 additions & 71 deletions

File tree

‎sdk/include/vcruntime/intrin.h‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,43 @@ int _isunorderedf(float, float);
10071007

10081008
#endif /* _M_ARM */
10091009

1010-
#ifdef _M_ARM64
1010+
#if defined(_M_ARM64)
1011+
void __break(int);
1012+
unsigned char _BitScanForward64(unsigned long * _Index, unsigned __int64 _Mask);
1013+
unsigned char _BitScanReverse64(unsigned long * _Index, unsigned __int64 _Mask);
1014+
unsigned int _CountLeadingZeros(unsigned long);
1015+
unsigned int _CountLeadingZeros64(unsigned __int64);
1016+
unsigned int _CountOneBits(unsigned long);
1017+
unsigned int _CountOneBits64(unsigned __int64);
10111018
unsigned __int64 __getReg(int);
1012-
#endif
1019+
__int64 _InterlockedAdd64(_Interlocked_operand_ __int64 volatile * _Addend, __int64 _Value);
1020+
long _InterlockedAdd(_Interlocked_operand_ long volatile * _Addend, long _Value);
1021+
__int64 _InterlockedAnd64(_Interlocked_operand_ __int64 volatile * _Value, __int64 _Mask);
1022+
unsigned char _InterlockedCompareExchange128(_Interlocked_operand_ __int64 volatile * _Destination, __int64 _ExchangeHigh, __int64 _ExchangeLow, __int64 * _ComparandResult);
1023+
__int64 _InterlockedDecrement64(_Interlocked_operand_ __int64 volatile * _Addend);
1024+
__int64 _InterlockedExchange64(_Interlocked_operand_ __int64 volatile * _Target, __int64 _Value);
1025+
__int64 _InterlockedExchangeAdd64(_Interlocked_operand_ __int64 volatile * _Addend, __int64 _Value);
1026+
__int64 _InterlockedIncrement64(_Interlocked_operand_ __int64 volatile * _Addend);
1027+
__int64 _InterlockedOr64(_Interlocked_operand_ __int64 volatile * _Value, __int64 _Mask);
1028+
__int64 _InterlockedXor64(_Interlocked_operand_ __int64 volatile * _Value, __int64 _Mask);
1029+
void __yield(void);
1030+
__int64 __mulh(__int64, __int64);
1031+
unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
1032+
unsigned char __readx18byte(unsigned long);
1033+
unsigned long __readx18dword(unsigned long);
1034+
unsigned __int64 __readx18qword(unsigned long);
1035+
unsigned short __readx18word(unsigned long);
1036+
void __writex18byte(unsigned long, unsigned char);
1037+
void __writex18dword(unsigned long, unsigned long);
1038+
void __writex18qword(unsigned long, unsigned __int64);
1039+
void __writex18word(unsigned long, unsigned short);
1040+
unsigned char _bittest64(__int64 const *, __int64);
1041+
unsigned char _bittestandcomplement64(__int64 *, __int64);
1042+
unsigned char _bittestandreset64(__int64 *, __int64);
1043+
unsigned char _bittestandset64(__int64 *, __int64);
1044+
unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
1045+
unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
1046+
#endif /* _M_ARM64 */
10131047

10141048
#if defined(_M_CEE_PURE)
10151049

‎sdk/include/vcruntime/mingw32/intrin_arm64.h‎

Lines changed: 21 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ __INTRIN_INLINE unsigned char _InterlockedCompareExchange128(
387387
[xl] "r"((unsigned __int64)ExchangeLow),
388388
[xh] "r"((unsigned __int64)ExchangeHigh)
389389
: "cc", "memory");
390+
__asm__ __volatile__("dmb ish" ::: "memory");
390391
if (status == 0)
391392
return 1;
392393
ComparandResult[0] = (__int64)old_lo;
@@ -395,13 +396,6 @@ __INTRIN_INLINE unsigned char _InterlockedCompareExchange128(
395396
}
396397
#endif
397398

398-
#if !HAS_BUILTIN(_mm_pause)
399-
__INTRIN_INLINE void _mm_pause(void)
400-
{
401-
__asm__ __volatile__("yield" : : : "memory");
402-
}
403-
#endif
404-
405399
#if !HAS_BUILTIN(__nop)
406400
__INTRIN_INLINE void __nop(void)
407401
{
@@ -632,72 +626,34 @@ __INTRIN_INLINE unsigned long __cdecl _lrotr(unsigned long value, int shift)
632626
}
633627
#endif
634628

635-
/*** 64-bit shifts ***/
636-
#if !HAS_BUILTIN(__ll_lshift)
637-
__INTRIN_INLINE unsigned long long __ll_lshift(unsigned long long Mask, int Bit)
638-
{
639-
return Mask << (Bit & 0x3F);
640-
}
641-
#endif
642-
643-
#if !HAS_BUILTIN(__ll_rshift)
644-
__INTRIN_INLINE long long __ll_rshift(long long Mask, int Bit)
645-
{
646-
return Mask >> (Bit & 0x3F);
647-
}
648-
#endif
649-
650-
#if !HAS_BUILTIN(__ull_rshift)
651-
__INTRIN_INLINE unsigned long long __ull_rshift(unsigned long long Mask, int Bit)
652-
{
653-
return Mask >> (Bit & 0x3F);
654-
}
655-
#endif
656-
657-
/*** Leading zero count and population count ***/
658-
#if !HAS_BUILTIN(__lzcnt)
659-
__INTRIN_INLINE unsigned int __lzcnt(unsigned int value)
629+
/*** Bit count ***/
630+
#if !HAS_BUILTIN(_CountLeadingZeros)
631+
__INTRIN_INLINE unsigned int _CountLeadingZeros(unsigned long value)
660632
{
661633
if (!value)
662-
return 32;
663-
return __builtin_clz(value);
634+
return sizeof(value) * 8;
635+
return __builtin_clzl(value);
664636
}
665637
#endif
666638

667-
#if !HAS_BUILTIN(__lzcnt16)
668-
__INTRIN_INLINE unsigned short __lzcnt16(unsigned short value)
669-
{
670-
if (!value)
671-
return 16;
672-
return (unsigned short)(__builtin_clz((unsigned int)value) - 16);
673-
}
674-
#endif
675-
676-
#if !HAS_BUILTIN(__lzcnt64)
677-
__INTRIN_INLINE unsigned long long __lzcnt64(unsigned long long value)
639+
#if !HAS_BUILTIN(_CountLeadingZeros64)
640+
__INTRIN_INLINE unsigned int _CountLeadingZeros64(unsigned __int64 value)
678641
{
679642
if (!value)
680643
return 64;
681644
return __builtin_clzll(value);
682645
}
683646
#endif
684647

685-
#if !HAS_BUILTIN(__popcnt)
686-
__INTRIN_INLINE unsigned int __popcnt(unsigned int value)
687-
{
688-
return __builtin_popcount(value);
689-
}
690-
#endif
691-
692-
#if !HAS_BUILTIN(__popcnt16)
693-
__INTRIN_INLINE unsigned short __popcnt16(unsigned short value)
648+
#if !HAS_BUILTIN(_CountOneBits)
649+
__INTRIN_INLINE unsigned int _CountOneBits(unsigned long value)
694650
{
695-
return __builtin_popcount(value);
651+
return __builtin_popcountl(value);
696652
}
697653
#endif
698654

699-
#if !HAS_BUILTIN(__popcnt64)
700-
__INTRIN_INLINE unsigned long long __popcnt64(unsigned long long value)
655+
#if !HAS_BUILTIN(_CountOneBits64)
656+
__INTRIN_INLINE unsigned int _CountOneBits64(unsigned __int64 value)
701657
{
702658
return __builtin_popcountll(value);
703659
}
@@ -794,18 +750,14 @@ __INTRIN_INLINE void __isb(unsigned int type)
794750
should use named MSR/MRS asm wrappers instead. */
795751

796752
#if !HAS_BUILTIN(__getReg)
797-
__INTRIN_INLINE unsigned __int64 __getReg(int reg)
798-
{
799-
unsigned __int64 value;
800-
801-
if (reg == 18)
802-
{
803-
__asm__ __volatile__("mov %0, x18" : "=r"(value));
804-
return value;
805-
}
806-
807-
__builtin_trap();
808-
}
753+
#define __getReg(reg) \
754+
__extension__({ \
755+
_Static_assert((unsigned long long)(reg) <= 31ULL, \
756+
"__getReg: register index out of range"); \
757+
unsigned __int64 _value; \
758+
__asm__ __volatile__("mov %0, x%c1" : "=r"(_value) : "i"(reg)); \
759+
_value; \
760+
})
809761
#endif
810762

811763
/*** _InterlockedAdd (returns the new, post-add value) ***/

0 commit comments

Comments
 (0)