【发布时间】:2014-04-05 04:12:36
【问题描述】:
我正在将我使用内联汇编编写的一些代码移植到 NEON。
我需要做的一件事是将范围 [0..128] 的字节值转换为表格中的其他字节值,该值取整个范围 [0..255]
表格很短,但其背后的数学运算并不容易,所以我认为每次“即时”计算它都不值得。所以我想试试查找表。
我在 32 字节的情况下使用了 VTBL,并且按预期工作
对于整个范围,一个想法是首先比较源所在的范围并进行不同的查找(即有 4 个 32 位查找表)。
我的问题是:有没有更有效的方法?
编辑
经过一些试验,我已经完成了四次查找,并且(仍未安排)我对结果感到满意。我在这里留下一段内联汇编中的代码行,以防有人发现它有用或认为它可以改进。
// 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
【问题讨论】:
-
我认为你在正确的轨道上 - 如果你想要并行查找,4 x VTBL 可能是要走的路。
-
谢谢。在调度和优化之前看起来不错。刚刚用一个例子编辑了帖子
-
如果函数是单调的,可以省略vadds,重复使用
vtbx d0, { dXXXX }, d0; vsub d0, d0, d1;。必须调整表格以考虑偏移 n*d1,确保已处理的值永远不会减去范围 0..31。 -
从来没有想过这个!在这种情况下,它不是单调的,但可以在某些情况下使用。
标签: optimization assembly arm neon