diff --git a/compiler-rt/lib/builtins/udivdi3.c b/compiler-rt/lib/builtins/udivdi3.c --- a/compiler-rt/lib/builtins/udivdi3.c +++ b/compiler-rt/lib/builtins/udivdi3.c @@ -15,5 +15,15 @@ // Returns: a / b COMPILER_RT_ABI du_int __udivdi3(du_int a, du_int b) { - return __udivmoddi4(a, b, 0); + const int N = sizeof(du_int) * CHAR_BIT; + du_int r = 0; + for (int i = 0; i < N; i++) { + r = (r << 1) | (a >> (N-1)); + a <<= 1; + if (r >= b) { + r -= b; + ++a; + } + } + return a; } diff --git a/compiler-rt/lib/builtins/umoddi3.c b/compiler-rt/lib/builtins/umoddi3.c --- a/compiler-rt/lib/builtins/umoddi3.c +++ b/compiler-rt/lib/builtins/umoddi3.c @@ -15,7 +15,15 @@ // Returns: a % b COMPILER_RT_ABI du_int __umoddi3(du_int a, du_int b) { - du_int r; - __udivmoddi4(a, b, &r); + const int N = sizeof(du_int) * CHAR_BIT; + du_int r = 0; + for (int i = 0; i < N; i++) { + r = (r << 1) | (a >> (N-1)); + a <<= 1; + if (r >= b) { + r -= b; + ++a; + } + } return r; }