Does the "dot" intrinsic take into cosideration the .w component of a float4 register?

For example,

const float4 a = (float4)(1.0f,2.0f,3.0f,4.0f);

const float4 b = (float4)(1.0f,1.0f,1.0f,1.0f);

what's the result of dot(a,b)? 10 or 6?

And what's more efficient?

1. const float k = dot(a,b)

or

2. const float k = a.x*b.x + a.y*b.y + a.z*b.z

thx

Hi bubu,

It will be 10.

Thus a and b are both const, k is computed at compile-time. There is no difference in efficiency.

If one of a and b are not const, second one has less add operation, and it also be written as

float k = dot(a.xyz, b.xyz);

or consider using float3. (OpenCL 1.1 feature.)