MSIL有ROL和ROR指令吗?
我写了一个 Int128 类型,效果很好。我认为我可以通过一个简单的想法来提高它的性能:改进有点笨拙的移位操作。
由于它们大量用于乘法和除法,因此改进会产生连锁反应。于是我开始创建一个动态方法(低移和高电平旋转),却发现没有 OpCodes.Rol 或 OpCodes.Ror 指令。
这在伊利诺伊州可能吗?
I wrote an Int128 type and it works great. I thought I could improve on its performance with a simple idea: Improve the shift operations which are a bit clumsy.
Because they are heavily used in multiplication and division, an improvement would have a ripple effect. So I began creating a dynamic method (to shift low and rotate high), only to discover that there are no OpCodes.Rol or OpCodes.Ror instructions.
Is this possible in IL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,
你需要通过位移来实现它
No.
You need to implement it with bit shifts
7年后部分回答这个问题,以防万一有人需要它。
您可以在.Net 中使用 ROR/ROL。
MSIL 不直接包含 ROR 或 ROL 操作,但有一些模式可以使 JIT 编译器生成 ROR 和 ROL。 RuyJIT(.Net 和 .Net core)支持这一点。
此处讨论了改进 .Net Core 以使用此模式的详细信息,一个月后.Net Core 代码已更新为使用它。
查看SHA512 的实现我们找到了 ROR 的示例:
并通过相同的模式扩展到 ROL:
要在 128 位整数上执行此操作,您可以将其处理为两个 64 位,然后使用 AND 来提取“进位”,使用 AND 来清除目标,然后使用 OR 来应用。这必须在两个方向上镜像(低->高和高->低)。我不会费心举例,因为这个问题有点老了。
To partially answer this question 7 years later, in case someone should need it.
You can use ROR/ROL in .Net.
MSIL doesn't directly contain ROR or ROL operations, but there are patterns that will make the JIT compiler generate ROR and ROL. RuyJIT (.Net and .Net core) supports this.
The details of improving .Net Core to use this pattern was discussed here and a month later .Net Core code was updated to use it.
Looking at the implementation of SHA512 we find examples of ROR:
And extending by same pattern to ROL:
To do this on 128-bit integer you can process as two 64-bit, then AND to extract "carry", AND to clear destination and OR to apply. This has to be mirrored in both directions (low->high and high->low). I'm not goin to bother with an example since this question is a bit old.