On Tue, Aug 9, 2011 at 10:21 AM, Richard Guenther <rguent...@suse.de> wrote:
>> One notable omission from x87 rounding sequences is plain round(), >> since x87 does not support round-to-nearest, away-from-zero directly. >> However, this function can be synthesized as round(a) = sgn(a) * >> floor(fabs(a) + 0.5). Fortunately, we have all building blocks ready >> in i386.md, we should just wire them correctly. >> >> The x87 expansion is protected with flag_unsafe_math_optimizations, >> since the input range is reduced (true?) due to addition - OTOH, insn >> that calculates floor is protected by this flag anyway. > Can't you do sth similar to ix86_expand_round instead, > using trunc (fabs (a) + nextafter (0.5, 0.0)) * sgn(a) > (not sure with the sign multiply, copysign would be better)? No, you can't use nextafter due to inherent x87 XFmode extensions, and the sign multiply is a simple conditional change-sign with chs insn (the intermediate result is always positive at this point). > The addition doesn't really reduce the range if you guard the > round by a proper conditional like ix86_expand_round does. Do we need both, flag_trapping_math and flag_rounding_math in x87 case? The sequence _will_ trap due to frndint instruction, and will set correct rounding mode for frndint in any case. Uros.