NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/51530: ldexp(2.0,INT_MAX) still zero on mips64el
The following reply was made to PR lib/51530; it has been noted by GNATS.
From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: lib/51530: ldexp(2.0,INT_MAX) still zero on mips64el
Date: Thu, 6 Oct 2016 03:42:14 +0000
On Thu, Oct 06, 2016 at 01:30:01AM +0000, coypu%SDF.ORG@localhost wrote:
> So:
>
> MIPS has its own implementation of ldexp: lib/libc/arch/mips/gen/ldexp.S
>
>
> 71 addu t1, t1, a2 # scale exponent
> 72 sll v0, a2, 20 # position N for addition
> 73 bge t1, DEXP_INF, 8f # overflow?
> 74 addu v0, v0, v1 # multiply by (2**N)
> 75 ble t1, zero, 4f # underflow?
>
>
> The exponent will never underflow, because addu is 'add unsigned'.
That's not the problem - the problem is that because the bias
correction hasn't been applied to the exponent from the float
argument, INT_MAX added to that exponent becomes negative so it goes
to the underflow case (which produces 0) instead of the overflow
case.
One way to fix this is to change the bge to bgeu, but then INT_MIN
will also be treated as an overflow and that's still wrong.
It needs to apply the bias correction before doing those comparisons.
(Or compare to bounds that have the bias correction built into them,
but that will take more instructions.)
It should be sufficient to apply it to t1 after line 71... but then
the underflow/denormal logic, and anything else subsequent using the
value of t1, needs to either take it off again or be adjusted to
match, which is not entirely trivial.
It might be expedient to check for large-magnitude negative values of
the N argument (ones that will never produce a valid result no matter
the number applied to, like say < -32768) and return zero directly.
something like
slti t4, a2, -32768
bnez t4, 5f
and
5:
mtc1 zero, $f1
mtc1 zero, $f0
j ra
except it might want to return -0 for some cases. There's code like
this at 7:, but it wants the sign of the x argument in t0 which won't
have happened yet.
(also, this file is too large to be using numbered scratch labels for
large jumps. those should get names.)
--
David A. Holland
dholland%netbsd.org@localhost
Home |
Main Index |
Thread Index |
Old Index