Bit-wise Operations - 2022.2 English

AI Engine Kernel and Graph Programming Guide (UG1079)

Document ID
Release Date
2022.2 English

The following AI Engine APIs allow bit-wise AND, OR, XOR, and NOT operations on a scalar value and all the elements of the input vector with same type, or on the elements of the two input vectors with same type and size.

  • aie::bit_and
  • aie::bit_or
  • aie::bit_xor

The following AI Engine API allows bit-wise NOT operations on the elements of the input vector.

  • aie::bit_not
Note: The aie::bit_* operations are emulated on a scalar processor in AI Engine.
aie::vector<int16,8> iv=window_readincr_v<8>(data0);
aie::vector<int16,8> iv2;
aie::vector<int16,8> iv_bit_and=aie::bit_and((int16)0xf,iv);//0xf bit AND with each element of iv
aie::vector<int16,8> iv_bit_or=aie::bit_or((int16)0xf,iv);
aie::vector<int16,8> iv_bit_xor=aie::bit_xor((int16)0xf,iv);
aie::vector<int16,8> iv_bit_and2=aie::bit_and(iv,iv2);//bit AND on each element of iv and iv2
aie::vector<int16,8> iv_bit_or2=aie::bit_or(iv,iv2);
aie::vector<int16,8> iv_bit_xor2=aie::bit_xor(iv,iv2);
aie::vector<int16,8> iv_not=aie::bit_not(iv);

The following AI Engine APIs provide to shift all values of a vector right or left by specified number of bits.

  • aie::downshift
  • aie::upshift
aie::vector<int16,8> iv_down=aie::downshift(iv,2); //shift each element right 2 bits
aie::vector<int16,8> iv_up=aie::upshift(iv,2); //shift each element left 2 bits