本文的直接思路来源是:https://www.codeproject.com/Articles/874396/Crunching-Numbers-with-AVX-and-AVX
For example, suppose a vector contains signed bytes, so the maximum value for each element is 127 (0x7F). If an operation adds 98 to 85, the mathematical sum is 183 (0xB7).
If the values are added with _mm256_add_epi8, the saturation will be ignored and the stored result will be -73 (0xB7).
这里说的是98+85后的值(带符号8位),我当时认为是之间加起来就是了,带符号的话就是-53。和文章中的数值不一样。我想起了计算后应该是补码的形式还原后才行。(原来是反码(不操作符号)加一就是补码,现在还原就是逆过程。如图一所示。
图一:

本文深入探讨了在使用AVX指令集进行向量运算时,带符号字节的饱和运算特性。通过具体实例解释了_mm256_add_epi8函数在处理98与85相加时的饱和行为,揭示了最终结果为-73而非-53的原因,强调了理解补码和反码转换的重要性。
2万+

被折叠的 条评论
为什么被折叠?



