<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 8, 2017 at 4:09 PM, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> writes:<br>
<br>
> The NIR story on conversion opcodes is a mess.  We've had way too many<br>
> of them, naming is inconsistent, and which ones have explicit sizes was<br>
> sort-of random.  This commit re-organizes things and makes them all<br>
> consistent:<br>
><br>
>  - All non-bool conversion opcodes now have the explicit size in the<br>
>    destination and are named <src_type>2<dst_type><size>.<br>
><br>
>  - Integer <-> integer conversion opcodes now only come in i2i and u2u<br>
>    forms (i2u and u2i have been removed) since the only difference<br>
>    between the different integer conversions is whether or not they<br>
>    sign-extend when up-converting.<br>
><br>
>  - Boolean conversion opcodes all have the explicit size on the bool and<br>
>    are named <src_type>2<dst_type>.<br>
><br>
> Making things consistent also allows nir_type_conversion_op to be moved<br>
> to nir_opcodes.c and auto-generated using mako.  This will make adding<br>
> int8, int16, and float16 versions much easier when the time comes.<br>
> ---<br>
<br>
</span><div><div class="h5">> diff --git a/src/compiler/nir/nir_<wbr>opcodes.py b/src/compiler/nir/nir_<wbr>opcodes.py<br>
> index b116fcf..f7d7d3b 100644<br>
> --- a/src/compiler/nir/nir_<wbr>opcodes.py<br>
> +++ b/src/compiler/nir/nir_<wbr>opcodes.py<br>
> @@ -166,42 +166,26 @@ unop("frsq", tfloat, "bit_size == 64 ? 1.0 / sqrt(src0) : 1.0f / sqrtf(src0)")<br>
>  unop("fsqrt", tfloat, "bit_size == 64 ? sqrt(src0) : sqrtf(src0)")<br>
>  unop("fexp2", tfloat, "exp2f(src0)")<br>
>  unop("flog2", tfloat, "log2f(src0)")<br>
> -unop_convert("f2i", tint32, tfloat32, "src0") # Float-to-integer conversion.<br>
> -unop_convert("f2u", tuint32, tfloat32, "src0") # Float-to-unsigned conversion<br>
> -unop_convert("d2i", tint32, tfloat64, "src0") # Double-to-integer conversion.<br>
> -unop_convert("d2u", tuint32, tfloat64, "src0") # Double-to-unsigned conversion.<br>
> -unop_convert("i2f", tfloat32, tint32, "src0") # Integer-to-float conversion.<br>
> -unop_convert("i2d", tfloat64, tint32, "src0") # Integer-to-double conversion.<br>
> -unop_convert("i2i32", tint32, tint, "src0")    # General int (int8_t, int64_t, etc.) to int32_t conversion<br>
> -unop_convert("u2i32", tint32, tuint, "src0")   # General uint (uint8_t, uint64_t, etc.) to int32_t conversion<br>
> -unop_convert("i2u32", tuint32, tint, "src0")   # General int (int8_t, int64_t, etc.) to uint32_t conversion<br>
> -unop_convert("u2u32", tuint32, tuint, "src0")  # General uint (uint8_t, uint64_t, etc.) to uint32_t conversion<br>
> -unop_convert("i2i64", tint64, tint, "src0")    # General int (int8_t, int32_t, etc.) to int64_t conversion<br>
> -unop_convert("u2i64", tint64, tuint, "src0")   # General uint (uint8_t, uint64_t, etc.) to int64_t conversion<br>
> -unop_convert("f2i64", tint64, tfloat, "src0")  # General float (float or double) to int64_t conversion<br>
> -unop_convert("i2u64", tuint64, tint,  "src0")  # General int (int8_t, int64_t, etc.) to uint64_t conversion<br>
> -unop_convert("u2u64", tuint64, tuint, "src0")  # General uint (uint8_t, uint32_t, etc.) to uint64_t conversion<br>
> -unop_convert("f2u64", tuint64, tfloat, "src0") # General float (float or double) to uint64_t conversion<br>
> -unop_convert("i642f", tfloat32, tint64, "src0")  # int64_t-to-float conversion.<br>
> -unop_convert("i642b", tbool, tint64, "src0")  # int64_t-to-bool conversion.<br>
> -unop_convert("i642d", tfloat64, tint64, "src0")  # int64_t-to-double conversion.<br>
> -unop_convert("u642f", tfloat32, tuint64, "src0") # uint64_t-to-float conversion.<br>
> -unop_convert("u642d", tfloat64, tuint64, "src0") # uint64_t-to-double conversion.<br>
> -<br>
> -# Float-to-boolean conversion<br>
> -unop_convert("f2b", tbool, tfloat32, "src0 != 0.0f")<br>
> -unop_convert("d2b", tbool, tfloat64, "src0 != 0.0")<br>
> -# Boolean-to-float conversion<br>
> -unop_convert("b2f", tfloat32, tbool, "src0 ? 1.0f : 0.0f")<br>
> -# Int-to-boolean conversion<br>
> +<br>
> +# Generate all of the numeric conversion opcodes<br>
> +for src_t in [tint, tuint, tfloat, tbool]:<br>
> +   if src_t in (tint, tuint):<br>
> +      dst_types = [tfloat, src_t]<br>
> +   elif src_t == tfloat:<br>
> +      dst_types = [tint, tuint, tfloat]<br>
> +<br>
> +   for dst_t in dst_types:<br>
> +      for bit_size in [32, 64]:<br>
> +         unop_convert("{}2{}{}".format(<wbr>src_t[0], dst_t[0], bit_size),<br>
> +                      dst_t + str(bit_size), src_t, "src0")<br>
> +<br>
> +# We'll hand-code the to/from bool conversion opcodes.  Because bool doesn't<br>
> +# have multiple bit-sizes, we can always infer the size from the other type.<br>
> +unop_convert("f2b", tbool, tfloat, "src0 != 0.0")<br>
>  unop_convert("i2b", tbool, tint, "src0 != 0")<br>
> -unop_convert("b2i", tint32, tbool, "src0 ? 1 : 0") # Boolean-to-int conversion<br>
> -unop_convert("b2i64", tint64, tbool, "src0 ? 1 : 0")  # Boolean-to-int64_t conversion.<br>
> -unop_convert("u2f", tfloat32, tuint32, "src0") # Unsigned-to-float conversion.<br>
> -unop_convert("u2d", tfloat64, tuint32, "src0") # Unsigned-to-double conversion.<br>
> -# double-to-float conversion<br>
> -unop_convert("d2f", tfloat32, tfloat64, "src0") # Double to single precision<br>
> -unop_convert("f2d", tfloat64, tfloat32, "src0") # Single to double precision<br>
> +unop_convert("b2f", tfloat, tbool, "src0 ? 1.0 : 0.0")<br>
> +unop_convert("b2i", tint, tbool, "src0 ? 1 : 0")<br>
<br>
</div></div>I'm confused.  The loop includes "tbool" in src_t iteration, so that<br>
makes me think it would be generating a unop_convert() for, say, b2i64<br>
(despite the commit message saying bool conversions don't get sizes),<br>
but then there are these hand-written unop_converts for bools here and I<br>
don't see b2i64 in any of the code.<br></blockquote><div><br></div><div>Oops...  You're right, we are creating bogus opcodes.  I must have failed at refactoring at some point.  Fixed locally.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Other than this question, patches 1-3 and 6 are:<br>
<br>
Reviewed-by: Eric Anholt <<a href="mailto:eric@anholt.net">eric@anholt.net</a>><br>
</blockquote></div><br></div></div>