<div dir="ltr"><div>The R600 ISA documentation only says that the DX10 variants of MIN and MAX use DX10 handling of NaNs. It does not say anything about the non-DX10 variants.<br><br></div>Marek<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sun, Apr 14, 2013 at 8:16 PM, Roland Scheidegger <span dir="ltr"><<a href="mailto:sroland@vmware.com" target="_blank">sroland@vmware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Am 14.04.2013 18:39, schrieb Marek Olšák:<br>
<div class="im">> On Sun, Apr 14, 2013 at 5:24 PM, Roland Scheidegger <<a href="mailto:sroland@vmware.com">sroland@vmware.com</a><br>
</div><div class="im">> <mailto:<a href="mailto:sroland@vmware.com">sroland@vmware.com</a>>> wrote:<br>
><br>
> Am 14.04.2013 10:12, schrieb <a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a><br>
</div>> <mailto:<a href="mailto:jfonseca@vmware.com">jfonseca@vmware.com</a>>:> - TBD<br>
<div class="im">> > + Start an IF ... ELSE .. ENDIF block. Condition evaluates to<br>
> true if<br>
> > +<br>
> > + src0.x != 0.0<br>
> > +<br>
> > + where src0.x is interpreted as a floating point register.<br>
> Maybe should say something wrt evaluation of NaNs? I know we haven't<br>
> really established rules for comparisons etc. wrt NaNs but those<br>
> bools-as-float make me cry. I guess it is no different though than other<br>
> float opcodes, if we now really have a definition saying IF takes _any_<br>
> float not just a bool-as-float which was loosely implied before.<br>
><br>
><br>
> I don't know where the term "bool-as-float" came from, but I'd rather<br>
> not use it unless it's properly defined somewhere, and TGSI doesn't have<br>
> bools anyway, so why bother? The GLSL compiler or glsl-to-tgsi is<br>
> responsible for converting bools to either floats or ints and TGSI<br>
> shouldn't need to care. Both r300g and r600g use (src0.x != 0.0) for IF<br>
> and (src0.x != 0) for UIF (r600-only), so there is always the<br>
> "not-equal-to" operator, which is also well defined for NaNs.<br>
</div>That depends on your definition of "well defined". llvm for instance has<br>
both "ordered not equal" and "unordered not equal" operators for<br>
precisely this reason. But yes I guess ieee-754 has some defined<br>
behavior there.<br>
That "bool-as-float" essentially comes from state trackers, because the<br>
language they are translating from require bools as "if" inputs - hence<br>
the input value always should have been the result of some comparison<br>
(or similar) operation (which in turn return these fake bools).<br>
But I agree this was never really documented, so just clearly stating<br>
you can pass in any float is just fine (it means that state trackers now<br>
are explicitly allowed to omit the comparison for simple cases like this<br>
one, "if(a != 0)...", well if they can detect it, it was not really<br>
obvious without documentation before if that would be ok). So in that<br>
sense nothing more needs to be said about NaNs, since they just adhere<br>
to the same rules as in other places (meaning pretty much undefined for<br>
most things, currently).<br>
<div class="im"><br>
><br>
> Also if you care about NaNs, we should start by defining how<br>
> instructions should handle them, e.g. how relational operators handle<br>
> NaNs, whether the multiplication operator follows the rule 0*anything =<br>
> 0 (MUL, MAD, DP4, ...), etc.<br>
><br>
> R600 have separate opcodes depending on what behavior you want, for example:<br>
> - The MUL opcode follows the rule 0*anything = 0. (DX9)<br>
> - The MUL_IEEE opcode follows the IEEE behavior.<br>
><br>
> The other opcodes with both the DX9 and IEEE behavior are: MAD, DP4,<br>
> EX2, LG2, RCP, RSQ. There are also separate MIN and MAX opcodes for DX9<br>
> and DX10. We should choose our opcodes carefully depending on whether we<br>
> are implementing a DX9, DX10, OpenGL, or OpenCL state tracker.<br>
<br>
</div>Yes indeed. d3d10 has quite strict rules which are mostly ieee754 (or<br>
ieee754r) but with some deviations. Other specs tend to be more lenient,<br>
and requiring strict rules could add quite some overhead, so we might<br>
want to introduce additional opcodes. How does MIN/MAX work for dx9 btw?<br>
DX10 will require you to give back the non-NaN value if only one<br>
argument is NaN (which seems to be ieee754r behavior), which for<br>
instance unfortunately doesn't translate well to sse2 code (as sse2 will<br>
just give you the second source if there's a NaN in either src which<br>
means you had to use cmp/select instead and be careful about what<br>
comparison you use there since the cpu doesn't support the full set of<br>
"ordered" and "unordered" comparisons unless you've got avx though<br>
presumably llvm would take care of that if you use the right comparison<br>
ops there).<br>
<span class="HOEnZb"><font color="#888888"><br>
Roland<br>
</font></span></blockquote></div><br></div>