[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[microblaze-uclinux] Bug in software floating-point library
Hi,
The softfloat implementation embedded within the Petalinux MicroBlaze
toolchain produces incorrect answers. The following test code:
int main(void) {
double x;
x = 123456789.0L; printf("__fixdfsi(%f) = %li\n", x, __fixdfsi(x));
x = 1234567890.0L; printf("__fixdfsi(%f) = %li\n", x, __fixdfsi(x));
x = 12345678900.0L; printf("__fixdfsi(%f) = %li\n", x, __fixdfsi(x));
return 0;
}
...returns:
# ./testcase
__fixdfsi(123456789.000000) = 123456789
__fixdfsi(1234567890.000000) = 0
__fixdfsi(12345678900.000000) = 2147483647
The first and third cases appear to be correct. (2147483647 corresponds
to INT_MAX, and the third argument is out-of-range.) However, the second
case is unexpected. It produces erroneous results in an embedded Python:
# python
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python 2.5.1 (r251:54863, Jan 28 2008, 09:24:22)
[GCC 3.4.1 ( PetaLinux 0.20 Build -rc1 050607 )] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> int(1234567890.0)
0
From the toolchain sources, the offending code lives in
'srcs/newlib-3.4/libgloss/microblaze/floatlib/fixdfsi.c'. I've tried it
on an x86 with the same results.
The Python expression "long(1234567890.0)" works fine as an alternative,
but having to do so makes me nervous. (I'm actually quite surprised to
run into this bug, since this softfloat implementation seems to be
widely used. Perhaps it's not guaranteed to work with large arguments.)
regards,
Graeme
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/