<div dir="ltr">This needs some changes since the code may not work on all platforms.<br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 17, 2014 at 10:06 AM, Neil Roberts <span dir="ltr"><<a href="mailto:neil@linux.intel.com" target="_blank">neil@linux.intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Actually I think this might be a slightly cleaner way to do the shift<br>
because it doesn't depend on any particular size of unsigned int and<br>
there are fewer ~s.<br>
<br>
- Neil<br>
<br>
------- >8 --------------- (use git am --scissors to automatically chop here)<br>
<br>
The un_to_float function was trying to get the maximum value given a<br>
number of bits by shifting ~0ul by the number of bits. For the<br>
GL_UNSIGNED_INT type this function was also being used to get a<br>
maximum value for a 32-bit quantity. However on a 32-bit build this<br>
would mean that it is shifting a 32-bit integer (unsigned long is<br>
32-bit) by 32 bits. The C spec leaves it undefined what happens if you<br>
do a shift that is greater than the number of bits in the type. GCC<br>
takes advantage of that to make the shift a no-op so the maximum was<br>
ending up as zero and the test fails.<br>
<br>
This patch makes it shift ~0u in the other direction so that it<br>
doesn't matter what size unsigned int is and it won't try to shift by<br>
32.<br>
<br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=83695" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=83695</a><br>
---<br>
 tests/texturing/teximage-colors.c | 2 +-<br>
 1 file changed, 1 insertion(+), 1 deletion(-)<br>
<br>
diff --git a/tests/texturing/teximage-colors.c b/tests/texturing/teximage-colors.c<br>
index 815ef4d..0afb4b1 100644<br>
--- a/tests/texturing/teximage-colors.c<br>
+++ b/tests/texturing/teximage-colors.c<br>
@@ -189,7 +189,7 @@ valid_combination(GLenum format, GLenum type)<br>
 static float<br>
 un_to_float(unsigned char bits, unsigned int color)<br>
 {<br>
-       unsigned int max = ~(~0ul << bits);<br>
+       unsigned int max = ~0u >> (sizeof max * 8 - bits);<br></blockquote><div>why not use, sizeof(unsigned int)? the call "sizeof max" may not always work depending on compiler<br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
        return (float)color / (float)max;<br>
 }<br>
<span class=""><font color="#888888"><br>
--<br>
1.9.3<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div></div>