SPRUI04F july 2015 – april 2023
The as_<destination type>(<source type object>) functions are provided to re-interpret the original type of an object as another vector type. The source type and destination type must be the same size in number of bits. An error is returned if the sizes are different.
While arithmetic conversion is performed by the conversion functions described in the previous section, no arithmetic conversion is performed by the re-interpretation functions. For example, suppose a float value of 1.0 is re-interpreted as an int value. Since the float value of 1.0 is represented in hex as 0x3f800000, the value in the resulting int is 1,065,353,216.
The following example reinterprets a non-vector variable of the longlong type (64 bits) to a float2 vector (2 elements of 32 bits each). The least significant 32-bits of mylonglong are placed in fltvec2.s0 and the most significant 32-bits of mylonglong are placed in fltvec2.s1. No arithmetic conversion is performed.
extern longlong mylonglong;
float2 fltvec2 = as_float2(mylonglong);
If the sizes of the source and destination types are different, an error occurs.
If vector data types are enabled, you can also use the as_<type>() functions for scalar (non-vector) types. The types must have the same number of bits. The following example re-interprets a float value as an int value. Since the float value of 1.0 is represented in hex as 0x3f800000, the value in the resulting int is 1,065,353,216.
float myfloat = 1.0f;
myint = as_int(myfloat);
The as_<destination type>() functions are not available for use with complex vector types.