On Wed, 2020-07-01 at 12:00 -0500, Segher Boessenkool wrote: > Hi! > > On Mon, Jun 29, 2020 at 03:31:48PM -0700, Carl Love wrote: > > On Mon, 2020-06-29 at 16:58 -0500, Segher Boessenkool wrote: > > > On Mon, Jun 29, 2020 at 02:29:54PM -0700, Carl Love wrote: > > > > Segher: > > > > > > > > On Thu, 2020-06-25 at 17:39 -0500, Segher Boessenkool wrote: > > > > > > +;; Return 1 if op is a constant 32-bit floating point > > > > > > value > > > > > > +(define_predicate "f32bit_const_operand" > > > > > > + (match_code "const_double") > > > > > > +{ > > > > > > + if (GET_MODE (op) == SFmode) > > > > > > + return 1; > > > > > > + > > > > > > + else if ((GET_MODE (op) == DFmode) && ((UINTVAL (op) >> > > > > > > 32) > > > > > > == > > > > > > 0)) > > > > > > + { > > > > > > + /* Value fits in 32-bits */ > > > > > > + return 1; > > > > > > + } > > > > > > + else > > > > > > + /* Not the expected mode. */ > > > > > > + return 0; > > > > > > +}) > > > > > > > > > > I don't think this is the correct test. What you want to see > > > > > is > > > > > if > > > > > the > > > > > number in "op" can be converted to an IEEE single-precision > > > > > number, > > > > > and > > > > > back again, losslessly. (And subnormal SP numbers aren't > > > > > allowed > > > > > either, but NaNs and infinities are). > > > > > > > > The predicate is used with the xxsplitw_v4sf > > > > define_expand. The > > > > "user" > > > > claims the given immediate bit pattern is the bit pattern for a > > > > single > > > > precision floating point number. The immediate value is not > > > > converted > > > > to a float. Rather we are splatting a bit pattern that the > > > > "user" > > > > already claims represents a 32-bit floating point value. I > > > > just > > > > need > > > > to make sure the immediate value actually fits into 32-bits. > > > > > > > > I don't see that I need to check that the value can be > > > > converted to > > > > IEEE float and back. > > > > > > Ah, okay. Can you please put that in the function comment > > > then? Right > > > now it says > > > ;; Return 1 if op is a constant 32-bit floating point value > > > and that is quite misleading. > > > > Would the following be more clear > > > > ;; Return 1 if op is a constant bit pattern representing a floating > > ;; point value that fits in 32-bits. > > Yes... But I still don't get it. > > Say you have the number 785.066650390625 . As a single-precision > IEEE > float, that is x4444_4444. But as a double-precision IEEE float, it > is > 0x4088_8888_8000_0000, which does not fit in 32 bits!
The value 0x4444_4444 would be mode SFmode and the test would return 1. We would be able to splat that 32-bit wide pattern. The value 0x4088_8888_8000_0000 would be DFmode but when you shift it right 32 bits it would be non-zero and else if ((GET_MODE (op) == DFmode) && ((UINTVAL (op) >> 32) would be true and the function would return 1 incorrectly. Argh! So yes, we have a problem. The second part is supposed to be checking for all zero not non zero. The test should be: else if ((GET_MODE (op) == DFmode) && (((UINTVAL (op) >> 32) == 0) Carl