| 1 |
/* Contributed by Jack Lloyd <[email protected]> */ |
| 2 |
|
| 3 |
/* { dg-do run } */ |
| 4 |
/* { dg-options "-O2 -ftree-vectorize" } */ |
| 5 |
/* { dg-options "-O2 -ftree-vectorize -march=nocona" { target { i?86-*-* x86_64-*-* } } } */ |
| 6 |
|
| 7 |
typedef unsigned long long word; |
| 8 |
|
| 9 |
const unsigned int MP_WORD_BITS = 64; |
| 10 |
const word MP_WORD_MASK = ~((word)0); |
| 11 |
const word MP_WORD_TOP_BIT = (word)1 << (8*sizeof(word) - 1); |
| 12 |
|
| 13 |
extern void abort (void); |
| 14 |
|
| 15 |
word do_div(word n1, word n0, word d) |
| 16 |
{ |
| 17 |
word high = n1 % d, quotient = 0; |
| 18 |
unsigned int j; |
| 19 |
|
| 20 |
for(j = 0; j != MP_WORD_BITS; ++j) |
| 21 |
{ |
| 22 |
word high_top_bit = (high & MP_WORD_TOP_BIT); |
| 23 |
|
| 24 |
high <<= 1; |
| 25 |
high |= (n0 >> (MP_WORD_BITS-1-j)) & 1; |
| 26 |
quotient <<= 1; |
| 27 |
|
| 28 |
if(high_top_bit || high >= d) |
| 29 |
{ |
| 30 |
high -= d; |
| 31 |
quotient |= 1; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
return quotient; |
| 36 |
} |
| 37 |
|
| 38 |
int main() |
| 39 |
{ |
| 40 |
word result; |
| 41 |
|
| 42 |
result = do_div(0x0000000000200000ll, |
| 43 |
0x0000000000000000ll, |
| 44 |
0x86E53497CE000000ll); |
| 45 |
|
| 46 |
|
| 47 |
if (result != 0x3CBA83) |
| 48 |
abort (); |
| 49 |
|
| 50 |
return 0; |
| 51 |
} |