C++用户定义类型的矢量化
假设我正在编写一个模块化算术类型,在每个算术操作都应用了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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您仍将依靠模板实例化,然后进行编译。
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 operationsinline
so the compiler can combine multiple calls.