Skip to content

Commit

Permalink
Fix __builtin_mul
Browse files Browse the repository at this point in the history
  • Loading branch information
shinh committed Mar 16, 2016
1 parent d7a64ff commit f47b571
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions libf.h
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion test/24_muldiv.c
@@ -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.