C++用户定义类型的矢量化

发布于 2025-01-29 07:21:42 字数 230 浏览 2 评论 0原文

假设我正在编写一个模块化算术类型,在每个算术操作都应用了mod p操作(%p)之后。

我希望新类型可用于STL的算法以及执行策略。

看来PAR策略应该起作用,但是unseq向量化呢?是否可以将标准库的矢量化功能与自定义数字类型相结合?

如何将数字性状添加到自定义类型中?

顺便说一句,我知道有模块化算术库。这是现代C ++的练习。

Say I am writing a modular arithmetic type, after each arithmetic operation a mod P operation (% P) is applied.

I would like the new type to be usable with STL's algorithms, as well as execution policies.

It seems that the par policy should work, but what about unseq vectorization? Is it possible to integrate vectorization capabilities of the standard library with a custom numeric type?

How would I add the numeric traits to the custom type?

BTW, I know that there are modular arithmetic libraries. This is an exercise with modern C++.

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

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

发布评论

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

评论(1

陪你搞怪i 2025-02-05 07:21:43

您仍将依靠模板实例化,然后进行编译。 unseq矢量化应来自编译器,注意到没有混蛋,允许它选择SIMD指令。这意味着您不是手动编写SIMD指令。

但是,您应该给编译器一个合理的机会,可以一起查看所有操作。如果您的操作员+仅由链接器看到,则将其编译为标量操作。这意味着您需要进行所有操作inline,以便编译器可以结合多个调用。

You're still going to rely on template instantiation followed by compilation. unseq vectorization should come from the compiler noticing that there can't be aliasing, allowing it to choose SIMD instructions. That means you're not writing the SIMD instructions manually.

However, you should give the compiler a fair chance to see all the operations together. If your operator+ is only seen by the linker, it would be compiled as a scalar operation . That means you'll need to make all the operations inline so the compiler can combine multiple calls.

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