How to get VSX value of zero?

We rearrange the vector in several places, and we need a dedicated value of 0 for use with the built-in vec_perm . We were unable to find vec_zero() or the like, so we would like to know how we should deal with things.

Currently, the code uses two strategies. The first strategy is the vector load:

 __attribute__((aligned(16))) static const uint8_t z[16] = { 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 }; const uint8x16_p8 zero = vec_ld(0, z); 

The second strategy is xor using a mask, which we intend to use:

 __attribute__((aligned(16))) static const uint8_t m[16] = { 15,14,13,12, 11,10,9,8, 7,6,5,4, 3,2,1,0 }; const uint8x16_p8 mask = vec_ld(0, m); const uint8x16_p8 zero = vec_xor(mask, mask); 

We have not started the tests (yet), so we do not know if one of them is better. The first strategy uses a load of VMX, and it can be expensive. The second strategy avoids loading, but introduces a data dependency.

How do we get a VSX value of zero?

+5
source share
1 answer

I would suggest that the compiler handle this for you. Just initialize zero:

 const uint8x16_p8 zero = {0}; 

- which is likely to compile with xor .

For example, a simple test:

 vector char foo(void) { const vector char zero = {0}; return zero; } 

On my machine, this compiles to:

 0000000000000000 <foo>: 0: d7 14 42 f0 xxlxor vs34,vs34,vs34 4: 20 00 80 4e blr ... 
+1
source

Source: https://habr.com/ru/post/1271656/


All Articles