The example below fails if it is compiled with the sx-gcc compiler (due to
this issue the "gcc.c-torture/execute/20021120-3.c" fails):
{{{
unsigned int foo (unsigned int x, unsigned int y)
{
return x / y;
}
int main ()
{
if (foo (~1U, 4) != (~1U / 4))
abort ();
exit (0);
}
}}}
It turns out that the problem is in the fact that since SX architecture
doesn't have instructions for the division of integers, it performs it by
casting integer to float (using the "flt" instruction), poerforming the
division on the floats and casting the result back to int.
Obviously, the converting of large integers to float results in a overflow,
which also corrupts an integer division. The code for performing the
integer deivision can be seen below:
ldl= $s35,12(,$s3)
ldl= $s36,20(,$s3)
flt $s37,$s35
flt $s35,$s36
fdv $s35,$s37,$s35
fixx $s35,$s35,1
The possible solutions for this problem:
* we implement the integer division function in assembler (i.e. __udivsi3)
* we replace the "flt" instruction with "fltx" which uses 64 bits.
Original issue reported on code.google.com by nou...@gmail.com on 28 Nov 2008 at 12:13
Original issue reported on code.google.com by
nou...@gmail.com
on 28 Nov 2008 at 12:13