<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 9, 2014 at 10:53 PM, Michel Dänzer <span dir="ltr"><<a href="mailto:michel@daenzer.net" target="_blank">michel@daenzer.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="">On 09.12.2014 21:06, Iago Toral Quiroga wrote:<br>
> From: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
><br>
> This patch fixes the return of a wrong value when x is lower than<br>
> -MAX_INT(src_bits) as the result would not be between [-1.0 1.0].<br>
><br>
> v2 by Samuel Iglesias <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>>:<br>
> - Modify unorm_to_float() to avoid doing the division when<br>
> x == -MAX_INT(src_bits)<br>
><br>
> Reviewed-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
> ---<br>
> src/mesa/main/format_utils.c | 2 +-<br>
> 1 file changed, 1 insertion(+), 1 deletion(-)<br>
><br>
> diff --git a/src/mesa/main/format_utils.c b/src/mesa/main/format_utils.c<br>
> index 93a0cea..5dd0848 100644<br>
> --- a/src/mesa/main/format_utils.c<br>
> +++ b/src/mesa/main/format_utils.c<br>
> @@ -152,7 +152,7 @@ unorm_to_float(unsigned x, unsigned src_bits)<br>
> static inline float<br>
> snorm_to_float(int x, unsigned src_bits)<br>
> {<br>
> - if (x == -MAX_INT(src_bits))<br>
> + if (x <= -MAX_INT(src_bits))<br>
> return -1.0f;<br>
> else<br>
> return x * (1.0f / (float)MAX_INT(src_bits));<br>
><br>
<br>
</span>The commit log talks about unorm_to_float, but the code modifies<br>
snorm_to_float. Also, I think something like<br>
<br>
mesa: Fix clamping to -1.0 in snorm_to_float<br>
<br>
would be a more useful shortlog.<br>
<br>
<br>
BTW, don't this function and unorm_to_float also need corresponding<br>
clamping to 1.0 for values >= MAX_INT(src_bits)?<br></blockquote><div><br></div><div>Yes and no. Every place that we use [us]norm_to_*, we assume that the value passed in is represented by the given number of bits. Therefore, clamping above should always be useless. The one edge case is the signed value MIN_INT(src_bits) (or, if you prefer, -MAX_INT(src_bits) - 1) in which is representable in the given number of bits but is actually less than -1 according to the formula. Technically, using an equality there was Ok, it's just that I had it equal to the wrong thing. Adding the check *probably* won't hurt as GCC *should* optimize it away, but I'd double-check the generated code before being too sure about it.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Earthling Michel Dänzer | <a href="http://www.amd.com" target="_blank">http://www.amd.com</a><br>
Libre software enthusiast | Mesa and X developer<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div></div>