Skip to content

Commit

Permalink
or1k: Fix issue with soft-div + test
Browse files Browse the repository at this point in the history
Plus test for soft div/mul
  • Loading branch information
stffrdhrn committed May 6, 2019
1 parent 03f7ee7 commit c892a0d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 31 additions & 0 deletions gcc/testsuite/gcc.target/or1k/div-mul-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* { dg-do run } */
/* { dg-options "-O2 -msoft-div -msoft-mul" } */

struct testcase {
int a;
int b;
int c;
int expected;
};

struct testcase tests[] = {
{2, 200, 3, 133},
{3, 300, 3, 300},
{2, 500, 3, 333},
{4, 250, 3, 333},
{0, 0, 0, 0}
};

int calc (int a, int b, int c) {
return a * b / c;
}

int main () {
int fail = 0;
struct testcase *tc;

for (int i = 0; (tc = &tests[i], tc->c); i++)
fail |= (calc (tc->a, tc->b, tc->c) != tc->expected);

return fail;
}
6 changes: 3 additions & 3 deletions libgcc/config/or1k/lib1funcs.S
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ __udivmodsi3_internal:
is not clobbered by this routine, and use that as to
save a return address without creating a stack frame. */

l.sfeqi r4, 0 /* division by zero; return 0. */
l.sfeq r4, r0 /* division by zero; return 0. */
l.ori r11, r0, 0 /* initial quotient */
l.bf 9f
l.ori r12, r3, 0 /* initial remainder */

/* Given X/Y, shift Y left until Y >= X. */
l.ori r6, r0, 1 /* mask = 1 */
1: l.sfltsi r4, 0 /* y has msb set */
1: l.sflts r4, r0 /* y has msb set */
l.bf 2f
l.sfltu r4, r12 /* y < x */
l.add r4, r4, r4 /* y <<= 1 */
l.bnf 1b
l.bf 1b
l.add r6, r6, r6 /* mask <<= 1 */

/* Shift Y back to the right again, subtracting from X. */
Expand Down

0 comments on commit c892a0d

Please sign in to comment.