使用SSE指令 [英] Using SSE instructions
问题描述
我已经写在其中一个大整数数组中的每个元素执行C ++的循环。在循环中,我掩盖了整数的某些位,然后找到最小值和最大值。我听说,如果我使用SSE指令执行这些操作将运行得更快相比,使用按位写一个正常的循环,以及如果其他条件。我的问题是我应该去这些SSE指令?另外,如果我的code在不同的处理器上运行时会发生什么?它仍然可以工作或这些指令是特定的处理器?
- SSE指令是特定处理器。你可以看一下哪些处理器支持维基百科上上交所版本。
- 如果SSE code会更快与否取决于很多因素:第一是当然的问题是否是内存限制或CPU绑定。如果内存总线是瓶颈SSE不会有太大的帮助。尽量简化您的整数计算,如果这使得code更快,它可能是CPU绑定的,你必须加速它的一个很好的机会。
- 请注意,写SIMD- code是比写C ++了很多困难 - code和所产生的code是更难改变。始终保持C ++ code是最新的,你会想它作为一个评论,并检查你的汇编code是正确的。
- 考虑使用像IPP库,实现对各种处理器进行优化公共的低级别SIMD操作。
I have a loop written in C++ which is executed for each element of a big integer array. Inside the loop, I mask some bits of the integer and then find the min and max values. I heard that if I use SSE instructions for these operations it will run much faster compared to a normal loop written using bitwise AND , and if-else conditions. My question is should I go for these SSE instructions? Also, what happens if my code runs on a different processor? Will it still work or these instructions are processor specific?
- SSE instructions are processor specific. You can look up which processor supports which SSE version on wikipedia.
- If SSE code will be faster or not depends on many factors: The first is of course whether the problem is memory-bound or CPU-bound. If the memory bus is the bottleneck SSE will not help much. Try simplifying your integer calculations, if that makes the code faster, it's probably CPU-bound, and you have a good chance of speeding it up.
- Be aware that writing SIMD-code is a lot harder than writing C++-code, and that the resulting code is much harder to change. Always keep the C++ code up to date, you'll want it as a comment and to check the correctness of your assembler code.
- Think about using a library like the IPP, that implements common low-level SIMD operations optimized for various processors.
这篇关于使用SSE指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!