<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 22, 2015 at 12:02 AM, Jan Vesely <span dir="ltr"><<a href="mailto:jan.vesely@rutgers.edu" target="_blank">jan.vesely@rutgers.edu</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"><div class=""><div class="h5">On Mon, 2015-09-21 at 23:07 -0500, Aaron Watry wrote:<br>
> On Thu, Sep 17, 2015 at 7:06 PM, Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a>><br>
> wrote:<br>
><br>
> > On Thu, 2015-09-17 at 10:34 -0500, Aaron Watry wrote:<br>
> > > On Wed, Sep 16, 2015 at 7:33 PM, Jan Vesely <<br>
> > > <a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a>><br>
> > > wrote:<br>
> > ><br>
> > > > On Wed, 2015-09-16 at 17:18 -0500, Aaron Watry wrote:<br>
> > > > > On Tue, Sep 15, 2015 at 9:42 AM, Jan Vesely <<br>
> > > > > <a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a>><br>
> > > > > wrote:<br>
> > > > ><br>
> > > > > ><br>
> > > > > ><br>
> > > > > > On Tue, Sep 15, 2015 at 7:28 AM, Jan Vesely <<br>
> > > > > > <a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a><br>
> > > > > > ><br>
> > > > > > wrote:<br>
> > > > > ><br>
> > > > > > > On Thu, 2015-09-10 at 10:12 -0500, Aaron Watry wrote:<br>
> > > > > > > > The char/short return buffers were declared as ints.<br>
> > > > > > > ><br>
> > > > > > > > Signed-off-by: Aaron Watry <<a href="mailto:awatry@gmail.com">awatry@gmail.com</a>><br>
> > > > > > ><br>
> > > > > > > Reviewed-by: Jan Vesely <<a href="mailto:jan.vesely@rutgers.edu">jan.vesely@rutgers.edu</a>><br>
> > > > > > > For both patches.<br>
> > > > > > ><br>
> > > > > > > though, I agree with Serge that a spec reference would be<br>
> > > > > > > nice.<br>
> > > > > > ><br>
> > > > > ><br>
> > > > > > PS: don't we need to test this for *_MAX too? I'd expect at<br>
> > > > > > least<br>
> > > > > > char and<br>
> > > > > > short to have the same problem.<br>
> > > > > ><br>
> > > > ><br>
> > > > ><br>
> > > > > Yes, it seems that the _MAX values are also broken because<br>
> > > > > the<br>
> > > > > values<br>
> > > > > are<br>
> > > > > upgraded to ints by llvm.<br>
> > > ><br>
> > > > I checked the c99 specs, section 6.4.4.1 says that the type<br>
> > > > decimal<br>
> > > > constants without suffix is the first of int, long int, long<br>
> > > > long<br>
> > > > int,<br>
> > > > in which the value can be represented.<br>
> > > > So I guess llvm is doing the right thing here.<br>
> > > ><br>
> > > ><br>
> > > Yeah, I believe it...  It's just sad that the CL spec doesn't<br>
> > > take<br>
> > > into<br>
> > > account that the main usage of [CHAR|SHORT]_[MIN|MAX] will be for<br>
> > > comparisons that possibly include values of those types (or<br>
> > > something<br>
> > > smaller than an int).<br>
> > ><br>
> > > I'm updating the patches to send the _MAX values for each type<br>
> > > through a<br>
> > > vector/scalar round trip.<br>
> > ><br>
> > > While I'm at it, do we have any consensus on how the CHAR_BIT<br>
> > > macro<br>
> > > should<br>
> > > be defined?  The value of CHAR_BIT is the number of bits in a<br>
> > > byte,<br>
> > > but I'm<br>
> > > not really sure if it makes sense to cast it to char as well<br>
> > > (probably<br>
> > > doesn't hurt anything), or if we should leave it as an int.<br>
> ><br>
> > I did a bit more digging, and it turns out that both c99 and OpenCL<br>
> > require that "The values shall all be constant expressions suitable<br>
> > for<br>
> > use in #if preprocessing directives." (section 5.2.4.2.1 and<br>
> > 6.12.3).<br>
> > type casts don't work with preprocessor, so I think adding them is<br>
> > against the specs.<br>
> ><br>
> ><br>
> Yeah, I read that part of the CL spec as well... But I'm not sure why<br>
> you're saying that casts don't work with the pre-processor.  It most<br>
> definitely does work to cast those values to the desired type without<br>
> altering the underlying numeric value (if they're needed as ints,<br>
> they can<br>
> be sign/zero-extended without a change in the value), but given the<br>
> wording<br>
> surrounding that section, maybe we do want to leave the<br>
> CHAR/SHORT_MIN/MAX<br>
> values without an explicit cast (therefore as scalar ints).<br>
<br>
</div></div>sorry, should have been more exact. Type casts don't work in<br>
preprocessor expressions. Types (and casts) are not part of the<br>
preprocessor language and only work in direct substitution. trying to<br>
_use_ them in preprocessor fails. ex:<br>
<br>
#define CHAR_MIN ((char)-127)<br>
<br>
char c = CHAR_MIN; // Works OK<br>
<br>
However,<br>
<br>
#if CHAR_MIN < 0<br>
#warning char is unsigned<br>
#endif<br>
<br>
fails.<br>
Both in C and OCLC. I believe this is the situation the specs is<br>
referring to in "use in #if preprocessing directives".<br>
<span class=""><font color="#888888"><br></font></span></blockquote><div><br></div><div>Ahh, I get it now.<br><br></div><div>If that's the case, then we don't have any real choice here.  I'll remove the explicit casts, and see what else I think we need to do.<br><br></div><div>Since we can't do explicit casts, the *_MAX values should probably all be left alone (e.g. 127, 32767, etc), and that's that.<br><br></div><div>For piglit, we take my first patch in this series, and remove the explicit vectorization of the 8/16-bit types for testing purposes (because they're actually ints), and we leave the vectorization of INT_MIN, and maybe add a check for INT_MAX just to make sure it's actually stored as in integer and not a long.  <br><br></div><div>I believe that we can drop the second patch in this series, since it doesn't really add much in this case (we already have other tests to make sure that char/short data types actually work). I don't really care either way.<br></div><div><br></div><div>Then for CLC, we just do the following to generic/include/clc/integer/definitions.h:<br>-#define INT_MIN ((int)(-2147483647 - 1))<br>+#define INT_MIN (-2147483647 - 1)<br>-#define SCHAR_MIN ((char)(-127 - 1))<br>+#define SCHAR_MIN (-127 - 1)<br>-#define SHRT_MIN ((short)(-32767 - 1))<br>+#define SHRT_MIN (-32767 - 1)<br><br></div><div>And leave the rest alone.<br><br></div><div>Sound good?<br></div><div><br></div><div>--Aaron<br></div><div><br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><font color="#888888">
Jan<br>
</font></span><div class=""><div class="h5"><br>
<br>
<br>
<br>
><br>
> I tested with the nvidia CL implementation and any char/short tests<br>
> that<br>
> assume that [U][CHAR|SHORT]_[MIN|MAX] are of those respective types<br>
> fail<br>
> because at least Nvidia treates them as ints.  I haven't tried out<br>
> the AMD<br>
> implementation yet (it'd take a bit of setup work to do).<br>
><br>
> So where does that leave us?  Do we partially revert the libclc<br>
> changes<br>
> (remove the explicit casts) to the [S]CHAR_MIN/SHORT_MIN values and<br>
> leave<br>
> those values as ints, and then just modify the unit tests for<br>
> INT_MIN/INT_MAX to make sure they aren't upgraded to longs while<br>
> leaving<br>
> the char/short tests alone?<br>
><br>
> I guess that's probably the way to go, but at this point, I'd like<br>
> some<br>
> sort of consensus before I waste any more time going down the wrong<br>
> route... free time is in way too short a supply these days.<br>
><br>
> --Aaron<br>
><br>
><br>
><br>
> ><br>
> > Jan<br>
> ><br>
> ><br>
> ><br>
> > ><br>
> > ><br>
> > > > Jan<br>
> > > ><br>
> > > > ><br>
> > > > ><br>
> > > > > ><br>
> > > > > > > Jan<br>
> > > > > > ><br>
> > > > > > > > ---<br>
> > > > > > > >  tests/cl/program/execute/<a href="http://int-definitions.cl" rel="noreferrer" target="_blank">int-definitions.cl</a> | 8 ++++--<br>
> > > > > > > > --<br>
> > > > > > > >  1 file changed, 4 insertions(+), 4 deletions(-)<br>
> > > > > > > ><br>
> > > > > > > > diff --git a/tests/cl/program/execute/int<br>
> > > > > > > > -<a href="http://definitions.cl" rel="noreferrer" target="_blank">definitions.cl</a><br>
> > > > > > > > b/tests/cl/program/execute/<a href="http://int-definitions.cl" rel="noreferrer" target="_blank">int-definitions.cl</a><br>
> > > > > > > > index 3d8ee63..a438fe4 100644<br>
> > > > > > > > --- a/tests/cl/program/execute/<a href="http://int-definitions.cl" rel="noreferrer" target="_blank">int-definitions.cl</a><br>
> > > > > > > > +++ b/tests/cl/program/execute/<a href="http://int-definitions.cl" rel="noreferrer" target="_blank">int-definitions.cl</a><br>
> > > > > > > > @@ -12,12 +12,12 @@ global_size: 1 0 0<br>
> > > > > > > >  [test]<br>
> > > > > > > >  name: Char Definitions<br>
> > > > > > > >  kernel_name: test_char<br>
> > > > > > > > -arg_out: 0 buffer int[6] 8 127 -128 127 -128 255<br>
> > > > > > > > +arg_out: 0 buffer char[6] 8 127 -128 127 -128 255<br>
> > > > > > > ><br>
> > > > > > > >  [test]<br>
> > > > > > > >  name: Short Definitions<br>
> > > > > > > >  kernel_name: test_short<br>
> > > > > > > > -arg_out: 0 buffer int[3] 32767 -32768 65535<br>
> > > > > > > > +arg_out: 0 buffer short[3] 32767 -32768 65535<br>
> > > > > > > ><br>
> > > > > > > >  [test]<br>
> > > > > > > >  name: Int Definitions<br>
> > > > > > > > @@ -32,7 +32,7 @@ arg_out: 0 buffer long[3]<br>
> > > > > > > > 9223372036854775807<br>
> > > > > > > > \<br>
> > > > > > > >                            18446744073709551615<br>
> > > > > > > >  !*/<br>
> > > > > > > ><br>
> > > > > > > > -kernel void test_char(global int* out) {<br>
> > > > > > > > +kernel void test_char(global char* out) {<br>
> > > > > > > >    int i = 0;<br>
> > > > > > > >    out[i++] = CHAR_BIT;<br>
> > > > > > > >    out[i++] = CHAR_MAX;<br>
> > > > > > > > @@ -42,7 +42,7 @@ kernel void test_char(global int*<br>
> > > > > > > > out) {<br>
> > > > > > > >    out[i++] = UCHAR_MAX;<br>
> > > > > > > >  }<br>
> > > > > > > ><br>
> > > > > > > > -kernel void test_short(global int* out) {<br>
> > > > > > > > +kernel void test_short(global short* out) {<br>
> > > > > > > >    int i = 0;<br>
> > > > > > > >    out[i++] = SHRT_MAX;<br>
> > > > > > > >    out[i++] = (SHRT_MIN - (short2)(0)).s0;<br>
> > > > > > ><br>
> > > > > ><br>
> > > > > ><br>
> > > ><br>
> ><br>
</div></div></blockquote></div><br></div></div>