[UCRT] Use GCC inline assembler

Clang requires the asm to be split, otherwise it complains that it doesn't have enough registers.
This commit is contained in:
Timo Kreuzer 2024-10-13 10:56:28 +03:00
parent 0cdde63c57
commit faedd8ff75
3 changed files with 54 additions and 2 deletions

View file

@ -130,7 +130,11 @@ _ACRTIMP int __cdecl fesetround(_In_ int _Round);
// next floating point instruction. If we're using /arch:IA32,
// force the exception to be raised immediately:
#if defined _M_IX86 && _M_IX86_FP == 0 && !defined _M_HYBRID_X86_ARM64
#ifdef _MSC_VER
__asm fwait;
#else
__asm__ __volatile__("fwait");
#endif
#endif
}
}

View file

@ -686,6 +686,7 @@ __forceinline uint32_t __cdecl count_sequential_high_zeroes(uint32_t const u) th
uint32_t const multiplier
) throw()
{
#ifdef _MSC_VER
__asm
{
mov eax, dword ptr [multiplicand + 4]
@ -698,6 +699,21 @@ __forceinline uint32_t __cdecl count_sequential_high_zeroes(uint32_t const u) th
add edx, ecx
}
#else // ^^^ _MSC_VER ^^^ // vvv !_MSC_VER vvv //
uint64_t retval;
__asm__(
"mull %[multiplier]\n"
"movl %%eax, %%ecx\n"
"movl %[multiplicand_lo], %%eax\n"
"mull %[multiplier]\n"
"addl %%ecx, %%edx\n"
: "=A" (retval)
: [multiplicand_hi] "a" ((uint32_t)((multiplicand >> 32) & 0xFFFFFFFF)),
[multiplicand_lo] "rm" ((uint32_t)((multiplicand >> 0) & 0xFFFFFFFF)),
[multiplier] "rm" (multiplier)
: "ecx" );
return retval;
#endif // !_MSC_VER
}
#else
__forceinline uint64_t __cdecl multiply_64_32(

View file

@ -166,7 +166,38 @@ extern "C" __declspec(noreturn) void __cdecl _invalid_parameter_noinfo_noreturn(
EXCEPTION_POINTERS ExceptionPointers = {&ExceptionRecord, &ContextRecord};
#ifdef _M_IX86
#if defined(__GNUC__) || defined(__clang__)
__asm__ __volatile__(
"movl %%eax, %[CxEax]\n\t"
"movl %%ecx, %[CxEcx]\n\t"
"movl %%edx, %[CxEdx]\n\t"
"movl %%ebx, %[CxEbx]\n\t"
"movl %%esi, %[CxEsi]\n\t"
"movl %%edi, %[CxEdi]\n\t"
: [CxEax] "=m" (ContextRecord.Eax),
[CxEcx] "=m" (ContextRecord.Ecx),
[CxEdx] "=m" (ContextRecord.Edx),
[CxEbx] "=m" (ContextRecord.Ebx),
[CxEsi] "=m" (ContextRecord.Esi),
[CxEdi] "=m" (ContextRecord.Edi));
__asm__ __volatile__(
"movw %%ss, %[CxSegSs]\n\t"
"movw %%cs, %[CxSegCs]\n\t"
"movw %%ds, %[CxSegDs]\n\t"
"movw %%es, %[CxSegEs]\n\t"
"movw %%fs, %[CxSegFs]\n\t"
"movw %%gs, %[CxSegGs]\n\t"
: [CxSegSs] "=m" (ContextRecord.SegSs),
[CxSegCs] "=m" (ContextRecord.SegCs),
[CxSegDs] "=m" (ContextRecord.SegDs),
[CxSegEs] "=m" (ContextRecord.SegEs),
[CxSegFs] "=m" (ContextRecord.SegFs),
[CxSegGs] "=m" (ContextRecord.SegGs));
__asm__ __volatile__(
"pushfl\n\t"
"popl %[CxEFlags]\n\t"
: [CxEFlags] "=m" (ContextRecord.EFlags));
#else // ^^^ __GNUC__ ^^^ // vvv !__GNUC__ vvv //
__asm
{
mov dword ptr [ContextRecord.Eax ], eax
@ -184,6 +215,7 @@ extern "C" __declspec(noreturn) void __cdecl _invalid_parameter_noinfo_noreturn(
pushfd
pop [ContextRecord.EFlags]
}
#endif // !__GNUC__
ContextRecord.ContextFlags = CONTEXT_CONTROL;