[PATCH 1/3] Optimize trunc() and truncf().

Joseph Myers joseph@codesourcery.com
Wed May 25 10:42:00 GMT 2016


On Tue, 24 May 2016, Matt Turner wrote:

> +  int64_t exp = (i0 >> 52) & 0x7ff;
> +  int64_t mask = UINT64_C(-1) << max(52 - (exp - 1023), 0);

This can involve undefined behavior (shift by more than 63), so ...

> +  if (exp < 1023)
> +    mask = UINT64_C(0x8000000000000000);

... the shift should only be done at all if exp is large enough.

Likewise for truncf.

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Libc-alpha mailing list