Skip to content

Commit faedd8f

Browse files
committed
[UCRT] Use GCC inline assembler
Clang requires the asm to be split, otherwise it complains that it doesn't have enough registers.
1 parent 0cdde63 commit faedd8f

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

sdk/include/ucrt/fenv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,11 @@ _ACRTIMP int __cdecl fesetround(_In_ int _Round);
130130
// next floating point instruction. If we're using /arch:IA32,
131131
// force the exception to be raised immediately:
132132
#if defined _M_IX86 && _M_IX86_FP == 0 && !defined _M_HYBRID_X86_ARM64
133+
#ifdef _MSC_VER
133134
__asm fwait;
135+
#else
136+
__asm__ __volatile__("fwait");
137+
#endif
134138
#endif
135139
}
136140
}

sdk/lib/ucrt/inc/corecrt_internal_big_integer.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ __forceinline uint32_t __cdecl count_sequential_high_zeroes(uint32_t const u) th
686686
uint32_t const multiplier
687687
) throw()
688688
{
689+
#ifdef _MSC_VER
689690
__asm
690691
{
691692
mov eax, dword ptr [multiplicand + 4]
@@ -698,6 +699,21 @@ __forceinline uint32_t __cdecl count_sequential_high_zeroes(uint32_t const u) th
698699

699700
add edx, ecx
700701
}
702+
#else // ^^^ _MSC_VER ^^^ // vvv !_MSC_VER vvv //
703+
uint64_t retval;
704+
__asm__(
705+
"mull %[multiplier]\n"
706+
"movl %%eax, %%ecx\n"
707+
"movl %[multiplicand_lo], %%eax\n"
708+
"mull %[multiplier]\n"
709+
"addl %%ecx, %%edx\n"
710+
: "=A" (retval)
711+
: [multiplicand_hi] "a" ((uint32_t)((multiplicand >> 32) & 0xFFFFFFFF)),
712+
[multiplicand_lo] "rm" ((uint32_t)((multiplicand >> 0) & 0xFFFFFFFF)),
713+
[multiplier] "rm" (multiplier)
714+
: "ecx" );
715+
return retval;
716+
#endif // !_MSC_VER
701717
}
702718
#else
703719
__forceinline uint64_t __cdecl multiply_64_32(
@@ -869,7 +885,7 @@ inline uint64_t __cdecl divide(
869885
}
870886

871887
// Multiply and subtract. Note that uu_quo may be one too large. If
872-
// we have a borrow at the end, we'll add the denominator back on and
888+
// we have a borrow at the end, we'll add the denominator back on and
873889
// decrement uu_quo.
874890
if (uu_quo > 0)
875891
{

sdk/lib/ucrt/misc/invalid_parameter.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,38 @@ extern "C" __declspec(noreturn) void __cdecl _invalid_parameter_noinfo_noreturn(
166166
EXCEPTION_POINTERS ExceptionPointers = {&ExceptionRecord, &ContextRecord};
167167

168168
#ifdef _M_IX86
169-
169+
#if defined(__GNUC__) || defined(__clang__)
170+
__asm__ __volatile__(
171+
"movl %%eax, %[CxEax]\n\t"
172+
"movl %%ecx, %[CxEcx]\n\t"
173+
"movl %%edx, %[CxEdx]\n\t"
174+
"movl %%ebx, %[CxEbx]\n\t"
175+
"movl %%esi, %[CxEsi]\n\t"
176+
"movl %%edi, %[CxEdi]\n\t"
177+
: [CxEax] "=m" (ContextRecord.Eax),
178+
[CxEcx] "=m" (ContextRecord.Ecx),
179+
[CxEdx] "=m" (ContextRecord.Edx),
180+
[CxEbx] "=m" (ContextRecord.Ebx),
181+
[CxEsi] "=m" (ContextRecord.Esi),
182+
[CxEdi] "=m" (ContextRecord.Edi));
183+
__asm__ __volatile__(
184+
"movw %%ss, %[CxSegSs]\n\t"
185+
"movw %%cs, %[CxSegCs]\n\t"
186+
"movw %%ds, %[CxSegDs]\n\t"
187+
"movw %%es, %[CxSegEs]\n\t"
188+
"movw %%fs, %[CxSegFs]\n\t"
189+
"movw %%gs, %[CxSegGs]\n\t"
190+
: [CxSegSs] "=m" (ContextRecord.SegSs),
191+
[CxSegCs] "=m" (ContextRecord.SegCs),
192+
[CxSegDs] "=m" (ContextRecord.SegDs),
193+
[CxSegEs] "=m" (ContextRecord.SegEs),
194+
[CxSegFs] "=m" (ContextRecord.SegFs),
195+
[CxSegGs] "=m" (ContextRecord.SegGs));
196+
__asm__ __volatile__(
197+
"pushfl\n\t"
198+
"popl %[CxEFlags]\n\t"
199+
: [CxEFlags] "=m" (ContextRecord.EFlags));
200+
#else // ^^^ __GNUC__ ^^^ // vvv !__GNUC__ vvv //
170201
__asm
171202
{
172203
mov dword ptr [ContextRecord.Eax ], eax
@@ -184,6 +215,7 @@ extern "C" __declspec(noreturn) void __cdecl _invalid_parameter_noinfo_noreturn(
184215
pushfd
185216
pop [ContextRecord.EFlags]
186217
}
218+
#endif // !__GNUC__
187219

188220
ContextRecord.ContextFlags = CONTEXT_CONTROL;
189221

0 commit comments

Comments
 (0)