[Mesa-dev] [PATCH 3/3] nir/algebraic: Support lowering for bot 64 and 32-bit ldexp
Samuel Iglesias Gonsálvez
siglesias at igalia.com
Thu Apr 28 06:10:49 UTC 2016
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
s/bot/both
Patches 1-3 are:
Reviewed-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
On 27/04/16 20:25, Jason Ekstrand wrote:
> --- src/compiler/nir/nir_opt_algebraic.py | 31
> ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9
> deletions(-)
>
> diff --git a/src/compiler/nir/nir_opt_algebraic.py
> b/src/compiler/nir/nir_opt_algebraic.py index 2ad1c70..dd89c6f
> 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++
> b/src/compiler/nir/nir_opt_algebraic.py @@ -378,11 +378,16 @@
> optimizations = [ 'options->lower_unpack_snorm_4x8'), ]
>
> -def fexp2i(exp): - # We assume that exp is already in the range
> [-126, 127]. - return ('ishl', ('iadd', exp, 127), 23) - -def
> ldexp32(f, exp): +def fexp2i(exp, bits): + # We assume that exp
> is already in the right range. + if bits == 32: + return
> ('ishl', ('iadd', exp, 127), 23) + elif bits == 64: + return
> ('pack_double_2x32_split', 0, ('ishl', ('iadd', exp, 1023), 20)) +
> else: + assert False + +def ldexp(f, exp, bits): # First, we
> clamp exp to a reasonable range. The maximum possible range # for
> a normal exponent is [-126, 127] and, throwing in denormals, you
> get # a maximum range of [-149, 127]. This means that we can
> potentially have @@ -393,7 +398,12 @@ def ldexp32(f, exp): #
> 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. -
> exp = ('imin', ('imax', exp, -252), 254) + if bits == 32: +
> exp = ('imin', ('imax', exp, -252), 254) + elif bits == 64: +
> exp = ('imin', ('imax', exp, -2044), 2046) + else: + assert
> False
>
> # Now we compute two powers of 2, one for exp/2 and one for
> exp-exp/2. # (We use ishr which isn't the same for -1, but the -1
> case still works @@ -403,11 +413,14 @@ def ldexp32(f, exp): # that
> you can get with normalized values. Instead, we create two powers
> # of two and multiply by them each in turn. That way the effective
> range # of our exponent is doubled. - pow2_1 = fexp2i(('ishr',
> exp, 1)) - pow2_2 = fexp2i(('isub', exp, ('ishr', exp, 1))) +
> pow2_1 = fexp2i(('ishr', exp, 1), bits) + pow2_2 =
> fexp2i(('isub', exp, ('ishr', exp, 1)), bits) return ('fmul',
> ('fmul', f, pow2_1), pow2_2)
>
> -optimizations += [(('ldexp', 'x', 'exp'), ldexp32('x', 'exp'))]
> +optimizations += [ + (('ldexp at 32', 'x', 'exp'), ldexp('x',
> 'exp', 32)), + (('ldexp at 64', 'x', 'exp'), ldexp('x', 'exp',
> 64)), +]
>
> # Unreal Engine 4 demo applications open-codes bitfieldReverse()
> def bitfield_reverse(u):
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJXIalpAAoJEH/0ujLxfcNDoqIP/iOFyuX9XD3saN28rl+1Radd
TV6ZVg5PVXR05TXVfMeNeMI1wXkLBXBlVRQkWoJ0QoOhbRQvwEyywgFTcDJ3qnEC
RMrnt+R4zT0Qr01zSrcUFcveK0lkutUoYAZVbkb6kM3woZ9sfBsSaQ8lXYZRx7Vg
sfPRqHtnN6qlf3ltl6jTaH7s6UCPwRhExBCvJTgVoGDzxDvXWE3rPh0D+FikSD0/
3j0ODs1F5JIrfOxpjF56C9dFMdK+cUhKuhKYesXE3A5zSXKwN9ThSSLyd3kdsdUH
GF3Inef0erQ07lToMkj4dTsL9fq1Ohp2V9uf13EBOeU323L5B54hLIIZZU+TLcjo
/89dsF+RTkCQumyu6HTzWy/fmxIWgXfIuKCJPy0fVrnv/xWj42Zeus20MoJ4TpD3
XFcV2HwETbc4lA5QwaPAkYMIICrnEYYUkYsKyDg1t55RQjvobVB0YeBcEV1OqAjP
a9BkNwd2JxisRgr4LYQQ/XRz8FSVPqkOtX9ombUtlXGqr1yL8Mo1M8raBEIVktb4
SwzQ8A9HiZSLss+W8QCsLu5ys0cDqs4VEaVX/bgoQemZkM0G3fOO0Y4/jlmomYWv
c66ynnkXapUqTF0PP9oo4eMPct6dOj04AnEUcU06w4HBHRTTCB6Bl4HvRYS9heUY
bEoKn3kK+BeBW14M7TXK
=DNht
-----END PGP SIGNATURE-----
More information about the mesa-dev
mailing list