Permalink
Browse files

Fix __builtin_mul

  • Loading branch information...
shinh committed Mar 16, 2016
1 parent d7a64ff commit f47b5712016998a52e248ec22526bcf8f5082c81
Showing with 11 additions and 6 deletions.
  1. +5 −5 libf.h
  2. +6 −1 test/24_muldiv.c
View
10 libf.h
@@ -564,26 +564,26 @@ static int __builtin_mul(int a, int b) {
int i, e, v;
int d[24];
int r[24];
for (i = 0, e = 1, v = a; e <= b; i++) {
for (i = 0, e = 1, v = a;; i++) {
d[i] = v;
r[i] = e;
v += v;
int ne = e + e;
if (ne < e)
if (ne < e || ne > b)
break;
e = ne;
}
int a = 0;
int x = 0;
for (;; i--) {
if (b >= r[i]) {
a += d[i];
x += d[i];
b -= r[i];
}
if (i == 0)
break;
}
return a;
return x;
}
static unsigned int __builtin_div(unsigned int a, unsigned int b) {
View
@@ -1,6 +1,11 @@
#include "../libf.h"
int main() {
printf("%d\n", 10777216 * 10777216);
int v = 10777216 * 9777219;
#ifndef __bfs__
v &= ((1 << 24) - 1);
#endif
printf("%d\n", v);
printf("%d\n", 10777216 * 0);
printf("%d\n", 10777216 / 2);
}

0 comments on commit f47b571

Please sign in to comment.