我正在使用内联汇编将我编写的一些代码移植到 NEON。
我需要的一件事是将范围 [0..128] 的字节值转换为表中采用完整范围 [0..255] 的其他字节值
该表很短,但其背后的数学并不容易,因此我认为不值得每次“即时”计算它。所以我想尝试查找表。
我已将 VTBL 用于 32 字节的情况,并且按预期工作
对于完整范围,一个想法是首先比较源所在的范围并进行不同的查找(即拥有 4 个 32 位查找表)。
我的问题是:有没有更有效的方法来做到这一点?
EDIT
经过一些试验,我已经完成了四次查找(尚未安排),我对结果感到满意。我在内联汇编中留下了一段代码行,以防万一有人发现它有用或认为它可以改进。
// Have the original data in d0
// d1 holds #32 value
// d6,d7,d8,d9 has the images for the values [0..31]
//First we look for the 0..31 images. The values out of range will be 0
"vtbl.u8 d2,{d6,d7,d8,d9},d0 \n\t"
// Now we sub #32 to d1 and find the images for [32...63], which have been previously loaded in d10,d11,d12,d13
"vsub.u8 d0,d0,d1\n\t"
"vtbl.u8 d3,{d10,d11,d12,d13},d1 \n\t"
// Do the same and calculating images for [64..95]
"vsub.u8 d0,d0,d1\n\t"
"vtbl.u8 d4,{d14,d15,d16,d17},d0 \n\t"
// Last step: images for [96..127]
"vsub.u8 d0,d0,d1\n\t"
"vtbl.u8 d5,{d18,d19,d20,d21},d0 \n\t"
// Now we add all. No need to saturate, since only one will be different than zero each time
"vadd.u8 d2,d2,d3\n\t"
"vadd.u8 d4,d4,d5\n\t"
"vadd.u8 d2,d2,d4\n\t" // Leave the result in d2