def fexp2i(exp, bits):
# We assume that exp is already in the right range.
- if bits == 32:
+ if bits == 16:
+ return ('i2i16', ('ishl', ('iadd', exp, 15), 10))
+ elif bits == 32:
return ('ishl', ('iadd', exp, 127), 23)
elif bits == 64:
return ('pack_64_2x32_split', 0, ('ishl', ('iadd', exp, 1023), 20))
# handles a range on exp of [-252, 254] which allows you to create any
# value (including denorms if the hardware supports it) and to adjust the
# exponent of any normal value to anything you want.
- if bits == 32:
+ if bits == 16:
+ exp = ('imin', ('imax', exp, -28), 30)
+ elif bits == 32:
exp = ('imin', ('imax', exp, -252), 254)
elif bits == 64:
exp = ('imin', ('imax', exp, -2044), 2046)
return ('fmul', ('fmul', f, pow2_1), pow2_2)
optimizations += [
+ (('ldexp@16', 'x', 'exp'), ldexp('x', 'exp', 16), 'options->lower_ldexp'),
(('ldexp@32', 'x', 'exp'), ldexp('x', 'exp', 32), 'options->lower_ldexp'),
(('ldexp@64', 'x', 'exp'), ldexp('x', 'exp', 64), 'options->lower_ldexp'),
]