@@ -860,33 +860,33 @@ Unqual!(Largest!(F, H)) powmod(F, G, H)(F x, G n, H m) if (isUnsigned!F && isUns
860
860
return low;
861
861
}
862
862
else version (LDC ) {
863
- // LDC/GDC: Use GCC-style inline assembly
864
- ulong low, high;
863
+ uint low, high;
865
864
866
- asm pure @trusted nothrow @nogc {
867
- " mulq %[b] "
868
- : " =a" (low), " =d" (high)
869
- : [a] " a " (a ), [b] " r " (b)
870
- : " cc" ;
871
- };
865
+ asm pure @trusted nothrow @nogc {
866
+ " mull %2 "
867
+ : " =a" (low), " =d" (high)
868
+ : " r " (b ), " 0 " (a) // Ensure a is in eax
869
+ : " cc" ;
870
+ };
872
871
873
- if (high >= c) {
874
- high %= c;
875
- }
872
+ if (high >= c) {
873
+ high %= c;
874
+ }
876
875
877
- if (high == 0 ) {
878
- return low % c;
879
- }
876
+ if (high == 0 ) {
877
+ return low % c;
878
+ }
880
879
881
- asm pure @trusted nothrow @nogc {
882
- " divq %[c]"
883
- : " =a" (low), " =d" (high)
884
- : [a] " a" (low), " d" (high), [c] " r" (c)
885
- : " cc" ;
886
- };
880
+ asm pure @trusted nothrow @nogc {
881
+ " divl %2"
882
+ : " =a" (low), " =d" (high)
883
+ : " r" (c), " 0" (low), " 1" (high) // Ensure correct register allocation
884
+ : " cc" ;
885
+ };
886
+
887
+ return low;
888
+ }
887
889
888
- return low;
889
- }
890
890
else {
891
891
// Use 64-bit type for the calculation
892
892
ulong result = (cast (ulong )a * cast (ulong )b) % c;
@@ -895,7 +895,7 @@ Unqual!(Largest!(F, H)) powmod(F, G, H)(F x, G n, H m) if (isUnsigned!F && isUns
895
895
896
896
}
897
897
else static if (T.sizeof == 4 ) {
898
- version (D_InlineAsm_X86 ) {
898
+ version (D_InlineAsm_X86_64 ) {
899
899
uint low = void ;
900
900
uint high = void ;
901
901
0 commit comments