Why? Open Source Qt 5 will stop receiving updates rather sooner than later so it's worth switching to Qt 6 to remain compatible with modern systems. Reviewed-on: http://vub63vv26q6v27xzv2dtcd25xumubshogm67yrpaz2rculqxs7jlfqad.onion/torzu-emu/torzu/pulls/130
37 lines
714 B
C
37 lines
714 B
C
typedef unsigned __int128 tu_int;
|
|
|
|
tu_int __udivti3(tu_int a, tu_int b)
|
|
{
|
|
if (b == 0) {
|
|
// Handle division by zero (could also trigger a fault)
|
|
return 0;
|
|
}
|
|
|
|
if (b > a) {
|
|
return 0;
|
|
}
|
|
|
|
int shift;
|
|
for (shift = 0;; shift++) {
|
|
if (shift >= 128) {
|
|
break;
|
|
}
|
|
tu_int shifted_b = b << shift;
|
|
if (shifted_b > a || (shifted_b >> shift) != b) {
|
|
break;
|
|
}
|
|
}
|
|
shift--;
|
|
|
|
tu_int quotient = 0;
|
|
for (; shift >= 0; shift--) {
|
|
tu_int shifted_b = b << shift;
|
|
if (shifted_b <= a) {
|
|
quotient |= (tu_int) 1 << shift;
|
|
a -= shifted_b;
|
|
}
|
|
}
|
|
|
|
return quotient;
|
|
}
|