SPRUI04F july 2015 – april 2023
In addition to vector operations, printf() support is provided for outputting vector data. See Section 6.12.13 of The OpenCL Specification version 1.2 for details about formatting vector data types using printf(). Note that the Texas Instruments C6000 implementation differs in the following ways from the OpenCL specification:
That is, the
ll
length modifier specifies that a following d, i, o, u, x, or X conversion specifier applies to a longlongn or ulonglongn argument. Use the
l
length modifier for 64-bit doublen arguments as described in the OpenCL specification.
The following example declares, initializes, and prints a vector of four 32-bit floating values, a vector of four 8-bit unsigned char values, and a vector of two 64-bit long long values.
float4 f4 = (float4)(1.0f, 2.0f, 3.0f, 4.0f);
uchar4 uc = (uchar4)(0xFA, 0xFB, 0xFC, 0xFD);
longlong2 bigNums = (longlong2)(600000000000, -600000000000);
printf("f4 = %2.2v4hlf\n", f);
printf("uc = %#v4hhx\n", uc);
printf("bigNums = %+v2lld\n", bigNums);
The example prints the vector containing float values using the
%2.2v4hlf
format string to output values at least 2 digits wide with a precision of 2 (
2.2
) a vector of length 4 (
v4
) with a floatn length modifier (
hl
) using the float type specifier (
f
).
The example prints the vector containing uchar values using the
%#v4hhx
format string to output a 0x prefix (
#
) followed by a vector of length 4 (
v4
) with a charn or ucharn length modifier (
hh
) using lowercase hexadecimal notation (
x
).
The example prints the vector containing long long values using the
%+v2lld
format string to output values with a + or - sign prefix (
+
) followed by a vector of length 2 (
v2
) with a longlongn or ulonglongn length modifier (
ll
) using decimal notation (
d
).
/* Output */
f4 = 1.00,2.00,3.00,4.00
uc = 0xfa,0xfb,0xfc,0xfd
bigNums = +600000000000,-600000000000