float ptr[32] = {1, 2, 3, ..., 32}; // ptr is a pointer to a contiguous memory block of 32 floats// Variable Sized Registerscv::v_float32 reg1(ptr); // reg1 stores first x values according to the maximum register size available.cv::v_float32 reg2(ptr + x); // reg stores the next x values// Constant Sized Registerscv::v_float32x4 reg1(ptr); // reg1 stores the first 4 floats (1, 2, 3, 4)cv::v_float32x4 reg2(ptr + 4); // reg2 stores the next 4 floats (5, 6, 7, 8)// Or we can explicitly write down the values.
cv::v_float32x4(1, 2, 3, 4);
// let us consider the following code is run in a 128-bit register
cv::v_uint8 a; // a = {0, 1, 2, ..., 15}
cv::v_uint8 b; // b = {15, 14, 13, ..., 0}
cv::v_uint8 c = a < b;
/*
let us look at the first 4 values in binary
a = |00000000|00000001|00000010|00000011|
b = |00001111|00001110|00001101|00001100|
c = |11111111|11111111|11111111|11111111|
If we store the values of c and print them as integers, we will get 255 for true values and 0 for false values.
*/// In a computer supporting 256-bit registers
cv::v_int32 a; // a = {1, 2, 3, 4, 5, 6, 7, 8}
cv::v_int32 b; // b = {8, 7, 6, 5, 4, 3, 2, 1}
cv::v_int32 c = (a < b); // c = {-1, -1, -1, -1, 0, 0, 0, 0}/*
The true values are 0xffffffff, which in signed 32-bit integer representation is equal to -1.
*/
cv::v_int32 a; // a = {a1, ..., a4}int mn = cv::v_reduce_min(a); // mn = min(a1, ..., an)int sum = cv::v_reduce_sum(a); // sum = a1 + ... + an
掩码操作
掩码操作允许我们在宽寄存器中复制条件。这些包括:
返回一个布尔值,如果寄存器中的所有值都小于零,则为 true。
返回布尔值,如果寄存器中的任何值小于零,则为 true。
返回一个寄存器,该寄存器基于掩码混合两个寄存器。
cv::v_uint8 a; // {a1, .., an}
cv::v_uint8 b; // {b1, ..., bn}
cv::v_int32x4 mask; // {0xff, 0, 0, 0xff, ..., 0xff, 0}
cv::v_uint8 Res = cv::v_select(mask, a, b); // {a1, b2, b3, a4, ..., an-1, bn}/*
"Res" will contain the value from "a" if mask is true (all bits set to 1),
and value from "b" if mask is false (all bits set to 0)
We can use comparison operators to generate mask and v_select to obtain results based on conditionals.
It is common to set all values of b to 0. Thus, v_select will give values of "a" or 0 based on the mask.
*/