diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 6b5414dca49..31bc0f68518 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -3847,6 +3847,9 @@ typedef struct nir_shader_compiler_options { * type casts (e.g. f2f16). */ bool preserve_mediump; + + /** lowers fquantize2f16 to alu ops. */ + bool lower_fquantize2f16; } nir_shader_compiler_options; typedef struct nir_shader { diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index 374ddb68126..a430aa1bca1 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -2729,6 +2729,21 @@ optimizations.extend([ (('fisnormal', 'a@64'), ('ult', 0x3fffffffffffff, ('iadd', ('ishl', a, 1), 0x20000000000000)), 'options->lower_fisnormal') ]) + +""" + if (fabs(val) < SMALLEST_NORMALIZED_FLOAT16) + return (val & SIGN_BIT) /* +0.0 or -0.0 as appropriate */; + else + return f2f32(f2f16(val)); +""" +optimizations.extend([ + (('fquantize2f16', 'a@32'), + ('bcsel', ('!flt', ('!fabs', a), math.ldexp(1.0, -14)), + ('iand', a, 1 << 31), + ('!f2f32', ('!f2f16_rtne', a))), + 'options->lower_fquantize2f16') + ]) + for s in range(0, 31): mask = 0xffffffff << s