質問

I implemented an algorithm using Neon on Android JNI. When I wanted to add vectors together I noticed there are two types of methods and I can't spot the difference.

// pairwise addition
int8x8_t vpadd_s8(int8x8_t a, int8x8_t b); // VPADD.I8 d0,d0,d0

// addition
int8x8_t vadd_s8(int8x8_t a, int8x8_t b);  // VADD.I8 d0,d0,d0 

The second does what you'd expect. It takes the ith int8 in a and adds it to the ith int8 in b. Why the two methods?

役に立ちましたか?

解決

There is good information to be found at ARM's Information Center. The reference is for the assembly instructions, but the names are very similar to the intrinsics. Although if you are going to use NEON, you'll get better performance by just skipping straight to assembly. It's even easier to write than using intrinsics.

To summarize, pairwise addition adds pairs of elements in the same vector, then concatenates the results into a single vector. An illustration (I use 4-element vectors for ease of drawing):

vector 'a'   vector 'b'
+-+-+-+-+    +-+-+-+-+
|0|1|2|3|    |4|5|6|7|
+-+-+-+-+    +-+-+-+-+
 \+/ \+/      \+/ \+/
  1   5        9   13
   \   \      /   /
      +-+-+-+--+
      |1|5|9|13|  result
      +-+-+-+--+

This differs from the regular addition instruction, which adds corresponding elements of the two vectors, giving the result

+-+-+-+--+
|4|6|8|10|
+-+-+-+--+

for a and b in the above illustration.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top