128位运算的x64 C语言 [英] 128 bit arithmetic on x64 in C

查看:975
本文介绍了128位运算的x64 C语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当执行在x86大数,显然对数字大小的最有效的选择是32位。但是,您需要算术到数字大小的两倍(即32 + 32 = 33,32 * 32 = 64,三十二分之六十四= 32)。幸运的是,不仅提供了86本,但它也从移植的C(uint64_t中)进行访问。

When implementing bignums on x86, obviously the most efficient choice for digit size is 32 bits. However, you need arithmetic up to twice the digit size (i.e. 32+32=33, 32*32=64, 64/32=32). Fortunately, not only does x86 provide this, but it's also accessible from portable C (uint64_t).

同样,在x64这将是理想的是使用64位数字。这将需要128位运算(即64 + 64 = 65,64 * 64 = 128,六十四分之一百二十八= 64)。幸运的是,64位提供了这一点。不幸的是,它不是从移植的C访问,但显然人们可以动用组装。

Similarly, on x64 it would be desirable to use 64-bit digits. This would require 128 bit arithmetic (i.e. 64+64=65, 64*64=128, 128/64=64). Fortunately, x64 provides this. Unfortunately, it's not accessible from portable C, though obviously one could dip into assembly.

所以我的问题是,它是否是可从不可移植C.是否有任何C语言编译器在x64提供上网本,如果是这样,有什么语法?

So my question is whether it's accessible from nonportable C. Do any C compilers on x64 provide access to this, and if so, what's the syntax?

(请注意,我说的不是被严格地视为32或64位字的集合,它们之间没有进位传播约128位向量,但对实际的128位整数运算。)

(Note that I'm not talking about 128 bit vectors that are strictly treated as collections of 32 or 64 bit words with no carry propagation between them, but about actual 128 bit integer operations.)

推荐答案

GCC有 __ uint128_t __ int128_t 作为扩展

这篇关于128位运算的x64 C语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆