GNU C++ 的 SSE SSE2 和 SSE3;

发布于 2024-07-15 11:41:08 字数 1815 浏览 5 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

云柯 2024-07-22 11:41:08

抱歉不知道有教程。

您最好的选择(恕我直言)是通过英特尔提供的“内在”函数来使用 SSE 来包装(通常)单个 SSE 指令。
这些可以通过一组名为 *mmintrin.h 的包含文件来获得,例如 xmmintrin.h 是原始的 SSE 指令集。

开始熟悉英特尔优化的内容 参考手册 是个好主意(有关内在函数的示例,请参阅第 4.3.1.2 节),SIMD 部分是必读内容。 指令集参考手册也非常有用,因为每个指令的文档都包含它对应的“内在”函数。

花一些时间检查编译器从内部函数生成的汇编程序(您将学到很多东西)以及分析/性能测量(您将避免浪费时间 SSE 代码而获得很少的回报)努力)。

2011-05-31 更新:Agner Fog 的 中对内在函数和矢量化有一些非常好的介绍优化PDFs谢谢)尽管它有点分散(例如部分第一个的第 12 节和 第二个)。 这些并不完全是教程材料(事实上,有一个“这些手册不适合初学者”的警告),但它们确实正确地将 SIMD(无论是通过 asm、内在函数还是编译器向量化使用)视为更大的优化工具箱的一部分。

2012-10-04 更新: A 关于 gcc 向量内在函数的 Linux 期刊小文章值得在这里提及。 比 SSE 更通用(也涵盖 PPC 和 ARM 扩展)。 上有很多参考资料最后一页,这引起了我对英特尔的 “内在指南”

Sorry don't know of a tutorial.

Your best bet (IMHO) is to use SSE via the "intrinsic" functions Intel provides to wrap (generally) single SSE instructions.
These are made available via a set of include files named *mmintrin.h e.g xmmintrin.h is the original SSE instruction set.

Begin familiar with the contents of Intel's Optimization Reference Manual is a good idea (see section 4.3.1.2 for an example of intrinsics) and the SIMD sections are essential reading. The instruction set reference manuals are pretty helpful too, in that each instruction's documentation includes the "intrinsic" function it corresponds to.

Do spend some time inspecting the assembler produced by the compiler from intrinsics (you'll learn a lot) and on profiling/performance measurement (you'll avoid wasting time SSE-ing code for little return on the effort).

Update 2011-05-31: There is some very nice coverage of intrinsics and vectorization in Agner Fog's optimization PDFs (thanks) although it's a bit spread about (e.g section 12 of the first one and section 5 of the second one). These aren't exactly tutorial material (in fact there's a "these manuals are not for beginners" warning) but they do rightly treat SIMD (whether used via asm, intrinsics or compiler vectorization) as just one part of the larger optimization toolbox.

Update 2012-10-04: A nice little Linux Journal article on gcc vector intrinsics deserves a mention here. More general than just SSE (covers PPC and ARM extensions too). There's a good collection of references on the last page, which drew my attention to Intel's "intrinsics guide".

浮生未歇 2024-07-22 11:41:08

最简单的优化是允许 gcc 发出 SSE 代码。

标志:-msse-msse2-msse3-march=-mfpmath=sse

有关 386 个选项的更简洁列表,请参阅 http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-选项,针对您的特定编译器版本的更准确文档位于:http://gcc.gnu。 org/onlinedocs/.

对于优化,请务必查看 Agner Fog 的:http://agner.org/optimize/。 我认为他没有关于内在函数的 SSE 教程,但他有一些非常简洁的 std-c++ 技巧,并且还提供了大量有关编码 SSE 程序集的信息(通常可以转录为内在函数)。

The most simple optimization to use is to allow gcc to emit SSE code.

Flags: -msse, -msse2, -msse3, -march=, -mfpmath=sse

For a more concise list about 386 options, see http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/i386-and-x86_002d64-Options.html#i386-and-x86_002d64-Options, more exact documentation for your specific compiler version is there: http://gcc.gnu.org/onlinedocs/.

For optimization, always check out Agner Fog's: http://agner.org/optimize/. I think he doesn't have SSE tutorials for intrinsics, but he has some really neat std-c++ tricks and also provides lots of information about coding SSE assembly (which can often be transcribed to intrinsics).

染火枫林 2024-07-22 11:41:08

当然,请查看 -mtune-march 选项、-msse*-mfpmath。 所有这些都使 GCC 能够进行特定于 SSE 的优化。

恐怕除此之外的一切都是汇编器的领域。

GCC 在线手册 - i386 和 x86_64 选项

Check out the -mtune and -march options, -msse*, and -mfpmath of course. All of those enable GCC to do SSE-specific optimizations.

Anything beyond that is the realm of Assembler, I am afraid.

GCC Online Manual - i386 and x86_64 Options

静若繁花 2024-07-22 11:41:08

MSDN 对 SSE 编译器内置程序有很好的描述(这些内置程序是事实上的标准,它们甚至可以在 clang/XCode 中工作)。

该参考的好处是它显示了等效的伪代码,因此例如您可以了解到 ADDPD指令是:

r0 := a0 + b0
r1 := a1 + b1

这是一个神秘的随机播放指令的很好的描述: http://www.songho .ca/misc/sse/sse.html

MSDN has pretty good description of SSE compiler built-ins (and those built-ins are de-facto standard, they even work in clang/XCode).

The nice thing about that reference is that it shows equivalent pseudocode, so e.g. you can learn that ADDPD instruction is:

r0 := a0 + b0
r1 := a1 + b1

And here's good description of a cryptic shuffle instruction: http://www.songho.ca/misc/sse/sse.html

沦落红尘 2024-07-22 11:41:08

一个简单的教程? 从来没听说过。

但是任何有关使用 MMX 或任何版本的 SSE 的信息都将对学习有用,无论是对于 GCC、ICC 还是 VC。

要了解 GCC 的向量扩展,请输入“info gcc”并转到节点:向量扩展。

A simple tutorial? Not that I know of.

But any information about using MMX or any version of SSE will be useful for learning, whether for GCC or for ICC or VC.

To learn about GCC's vector extensions, type "info gcc" and go to Node: Vector Extensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文