diff options
author | Matt Turner <[email protected]> | 2016-01-21 09:09:29 -0800 |
---|---|---|
committer | Matt Turner <[email protected]> | 2016-01-25 14:24:07 -0800 |
commit | 26f0444ead45bd9d5f7fbbca6292b284f382ecd6 (patch) | |
tree | dcdb4422be3dd61dd665f62f9f13baf39499b0f2 /src/glsl/nir | |
parent | 26b2cc6f3a23d9e9047c9735d20e3fbcf2291ac2 (diff) |
nir: Add opcodes to extract bytes or words.
The uint versions zero extend while the int versions sign extend.
Diffstat (limited to 'src/glsl/nir')
-rw-r--r-- | src/glsl/nir/nir.h | 3 | ||||
-rw-r--r-- | src/glsl/nir/nir_opcodes.py | 9 | ||||
-rw-r--r-- | src/glsl/nir/nir_opt_algebraic.py | 16 |
3 files changed, 28 insertions, 0 deletions
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index 11130304170..7b39cbb4c12 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -1471,6 +1471,9 @@ typedef struct nir_shader_compiler_options { bool lower_pack_half_2x16; bool lower_unpack_half_2x16; + bool lower_extract_byte; + bool lower_extract_word; + /** * Does the driver support real 32-bit integers? (Otherwise, integers * are simulated by floats.) diff --git a/src/glsl/nir/nir_opcodes.py b/src/glsl/nir/nir_opcodes.py index a8bbe1a0b82..be3cd17193f 100644 --- a/src/glsl/nir/nir_opcodes.py +++ b/src/glsl/nir/nir_opcodes.py @@ -536,6 +536,15 @@ dst.x = src0.x; dst.y = src1.x; """) +# Byte extraction +binop("extract_ubyte", tuint, "", "(uint8_t)(src0 >> (src1 * 8))") +binop("extract_ibyte", tint, "", "(int8_t)(src0 >> (src1 * 8))") + +# Word extraction +binop("extract_uword", tuint, "", "(uint16_t)(src0 >> (src1 * 16))") +binop("extract_iword", tint, "", "(int16_t)(src0 >> (src1 * 16))") + + def triop(name, ty, const_expr): opcode(name, 0, ty, [0, 0, 0], [ty, ty, ty], "", const_expr) def triop_horiz(name, output_size, src1_size, src2_size, src3_size, const_expr): diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py index 7745b76f7ce..b761b54cd70 100644 --- a/src/glsl/nir/nir_opt_algebraic.py +++ b/src/glsl/nir/nir_opt_algebraic.py @@ -242,6 +242,22 @@ optimizations = [ ('bcsel', ('ult', 31, 'bits'), 'value', ('ubfe', 'value', 'offset', 'bits')), 'options->lower_bitfield_extract'), + + (('extract_ibyte', a, b), + ('ishr', ('ishl', a, ('imul', ('isub', 3, b), 8)), 8), + 'options->lower_extract_byte'), + + (('extract_ubyte', a, b), + ('iand', ('ushr', a, ('imul', b, 8)), 0xff), + 'options->lower_extract_byte'), + + (('extract_iword', a, b), + ('ishr', ('ishl', a, ('imul', ('isub', 1, b), 16)), 16), + 'options->lower_extract_word'), + + (('extract_uword', a, b), + ('iand', ('ushr', a, ('imul', b, 16)), 0xffff), + 'options->lower_extract_word'), ] # Add optimizations to handle the case where the result of a ternary is |