Gamaru / opencl-book-samples

Automatically exported from code.google.com/p/opencl-book-samples
0 stars 0 forks source link

Errata: Incorrect comment in sample code (ch.4 pg.117) #11

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The sample explicit cast at the top of the page contains an incorrect comment 
about the result of the cast:

uchar4 vtrue =(uchar4)true; // vtrue is a uchar4 vector with
                            // elements(0xFF, 0xFF, 0xFF, 0xFF)

The correct result would be elements(0x01, 0x01, 0x01, 0x01), as the value true 
should be extended to the integer value 1, as correctly mentioned in table 4.1 
at the begining of the chapter (pg. 100).

Original issue reported on code.google.com by wel...@gmail.com on 6 Aug 2011 at 6:53

GoogleCodeExporter commented 8 years ago
Good catch. Affie, please confirm.

Original comment by dginsb...@upsamplesoftware.com on 6 Aug 2011 at 9:36

GoogleCodeExporter commented 8 years ago
The source of the confusion here stems from some irregularities in the 
standard. Later on in the same chapter there's an example for reinerpreting 
bits as different types. On page 122 the example states:

// Perform the operation f = f < g ? f : 0 for components of a
// vector
float4 f, g;
int4 is_less = f < g;
// Each component of the is_less vector will be 0 if result of <
// operation is false and will be -1 (i.e., all bits set) if
// the result of < operation is true.

This comment is correct, but the use of the word 'true' might imply that the 
conversion was of the extended integer value for the boolean value true. This 
is not the case. The < operator for vector types returns an intn type, not a 
booln type (well, there's no booln type). I'm guessing C99 compatability for 
this operator is the reason that -1 represets the condition to be true.

Maybe in OpenCL 1.2, the extended integer value for true should be -1, and not 
1.

Original comment by wel...@gmail.com on 6 Aug 2011 at 9:59

GoogleCodeExporter commented 8 years ago
Reading back my last comment, and the specs for the behavior of the < operator, 
I guess that what I call irregularities are actually intentional, since for 
scalar types the returned value in case the condition was true is 1, whereas 
for vector types it is defined as -1.

Aaftab, can you please explain why these choices were made?

Original comment by wel...@gmail.com on 6 Aug 2011 at 11:14