如何在 Visual Studio 中使用处理器寄存器?

发布于 2024-08-22 04:06:13 字数 239 浏览 1 评论 0原文

我正在尝试编写一个程序来解决 rsa 挑战(是的,我有有趣的目标),目前我没有 64 位 Linux 机器,而且我真的不想花时间编写一个没有 64 位 Linux 机器的程序。一个完成的机会。 因此,虽然我可以进行一些汇编程序编程,但我更喜欢使用 C++。但是,我也对如何使用内联汇编来做同样的事情感兴趣。 这里的计划是使用 16 个 64 位通用寄存器和 128 位 sse 寄存器来进行(非常非常长)整数数学运算。因此,任何有关如何做到这一点的帮助将不胜感激。

i'm trying to write a program that solves the rsa challenge (yes i have interesting goals) and currently i don't have a 64 bit linux box and i don't really wanna spend my time writing a program that doesn't have a chance to ever finish.
so while i can do some assembler programming, i would prefer using C++. however, i would also be interested in how to use inline assembly to do the same thing.
the plan here is to use the 16 64 bit general purpose registers and the 128 bit sse registers to do (really really long) integer math. so any help on how to do that would be greatly appreciated.

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

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

发布评论

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

评论(3

夏天碎花小短裙 2024-08-29 04:06:13

根据您对 BarsMonsters anser 的评论,您不需要靠近 CPU,您需要一个大型整数库。

一种选择是 gmp,它包括任意整数算术。它对于大整数相乘之类的事情有很好的算法,一个好的编译器会比大多数人做得更好。

可能促使您寻找替代方案的主要问题是它支持可变精度算术,如果您确定数字最多有 512 个二进制数字,这可能是您宁愿避免的开销。即便如此,您可能更想了解算法而不是低级技巧(在这种规模下,长乘法可能已经是一个糟糕的选择),而且我非常有信心让编译器进行优化会更好。

我的建议是——把时间花在需要人类智能的事情上,而不是机器可以更一致、更快地完成的事情上。

如果您确实可以比编译器更好地优化机器代码,请下载 LLVM 并将该逻辑实现为优化过程,这样我们都可以受益;-)

Based on your comment to BarsMonsters anser, you don't need to get closer to the CPU, you need a large integer library.

One option is gmp, which includes arbitrary integer arithmetic. It has good algorithms for things like multiplying large integers, and a good compiler will do a better job of optimising this than most people.

The main issue that might make you look for an alternative is that it supports variable precision arithmetic, which may be an overhead you'd rather avoid if you know for sure that your numbers have at most 512 binary digits. Even so, you probably want to look at algorithms more than low-level tricks (long multiplication may already be a bad choice at that size), and I'm pretty confident you'll be better off letting the compiler do your optimisation.

My advice - spend your time doing the things that require human intelligence, not the things that a machine can do far more consistently and a billion times faster.

And if you really can optimise machine code better than a compiler can, download LLVM and implement that logic as an optimisation pass so we can all get the benefit ;-)

绝不放开 2024-08-29 04:06:13

所有现代编译器都非常擅长重用所有可用寄存器来生成尽可能快的代码。

特别是 Intel C++ 和 GCC3 - 它们经常手动创建无与伦比的代码。

顺便说一句,看看这个:为什么MSVC 不支持 AMD64 和 Itanium 目标的内联汇编?

All modern compillers are very good at reusing all available registers to produce the fastest possible code.

Especially Intel C++ and GCC3 - they often create code unbeatable manually.

BTW, check out this: Why does MSVC not support inline assembly for AMD64 and Itanium targets?

梦里的微风 2024-08-29 04:06:13

如果你只想做一些精确的数学,你最好尝试英特尔 C++ 编译器并使用它的数学库,它非常强大并且过度优化。 Boost 数学库也是如此。这可能会使您的工作量减少 90% :-) 它们确实支持任意精度数字。

If you want to just do some precission math, you would better try Intel C++ compiler and use it's math lib, it very powerfull and overoptimized. Same for Boost math library. This might cut your work by 90% :-) They do support arbitrary precission numbers.

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