Fixing d2f in interpreter (Was: Re: [kaffe] Re: Re: NetBSD/ppc now works)

Dalibor Topic robilad at kaffe.org
Fri Apr 30 06:57:08 PDT 2004


Riccardo wrote:
>>I've looked more closely into this one. Something goes bad when d2f 
>>bytecode instruction is exectued in this case. the implementation in 
>>intrp/icode.h looks innocent enough, but I'm not sure what should 
>>happen  precisely when max double is assigned to a float in C. I've 
>>written a  test case, and attached it, so it'd be nice if you could 
>>run it on your  netbsd-ppc machine and report the results.
> 
> 
> NetBSD/ppc 2.0 beta, gcc 3.3.3:
> d = 1.79769e+308         f = inf         g=inf
> d = 1    f = 7fefffff    g=ffffffff
> f.f = 3.40282e+38        f.i = 7f7fffff
> 
> OpenBSD/sparc 3.4, gcc 2.95.2
> d = 1.79769e+308         f = Inf         g=Inf
> d = 7fefffff     f = ffffffff    g=7f800000
> f.f = 3.40282e+38        f.i = 7f7fffff
> 
> Darwin 6.8, apple cc
> d = 1.79769e+308         f = Inf         g=Inf
> d = 7fefffff     f = ffffffff    g=7f800000
> f.f = 3.40282e+38        f.i = 7f7fffff
> 
> the behavior seems consistent to me
> what is the result at your place?

The only thing that's consistent is the last line :)  Looks like my test 
was broken, could you try this version on NetBSD ppc?

I suspect that d2f is broken in the interpreter. The Java language spec 
demands that in case of overflow the value of float is a signed 
infinity, but the C standard says oveflow results in undefined 
behaviour. So I assume we'd have to check whether the double is 
representable as a float before we convert it, and handle the special 
cases that would invoke undefined behaviour ourself.

I'm working on a patch.

cheers,
dalibor topic
-------------- next part --------------
A non-text attachment was scrubbed...
Name: d2f.c
Type: text/x-csrc
Size: 1292 bytes
Desc: not available
Url : http://kaffe.org/pipermail/kaffe/attachments/20040430/2910be34/attachment-0002.c 


More information about the kaffe mailing list