Java:VM 如何在 32 位处理器上处理 64 位 `long` [英] Java: How does the VM handle a 64bit `long` on a 32bit processor

查看:35
本文介绍了Java:VM 如何在 32 位处理器上处理 64 位 `long`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在多核 32 位机器上可以并行使用多核吗?
32 位机器上的 64 位操作慢多少?


Can it utilise mulitple cores in parallel when on a Multi-Core 32bit machine?
How much slower are 64bit operations on a 32bit machine?

推荐答案

它可能使用多个内核来运行不同的线程,但它不会并行使用它们进行 64 位计算.一个 64 位长基本上存储为两个 32 位整数.为了将它们相加,需要进行两次相加,以跟踪进位位.乘法有点像两个两位数的乘法,只是每个数字都以 2^32 为基数,而不是以 10 为基数.其他算术运算依此类推.

It may use multiple cores to run different threads, but it does not use them in parallel for 64 bit calculations. A 64 bit long is basically stored as two 32 bit ints. In order to add them, two additions are needed, keeping track of the carry bit. Multiplication is kind of like multiplying two two-digit numbers, except each digit is in base 2^32 instead of base 10. So on for other arithmetic operations.

关于速度的我只能猜测速度差异.加法需要两个加法而不是一个,乘法(我认为)需要四个乘法而不是一个.但是,我怀疑如果一切都可以保存在寄存器中,那么计算的实际时间将与两次进入内存进行读取和两次写入所需的时间相形见绌,所以我的猜测是大多数情况下的两倍操作.我想这将取决于处理器、特定的 JVM 实现、月相等.除非您进行大量的数字运算,否则我不会担心.大多数程序大部分时间都在等待磁盘或网络的 IO.

Edit about speed: I can only guess about the speed difference. An addition requires two adds instead of one, and a multiplication would (I think) require four multiplies instead of one. However, I suspect that if everything can be kept in registers then the actual time for the computation would be dwarfed by the time required to go to memory twice for the read and twice for the write, so my guess is about twice as long for most operations. I imagine that it would depend on the processor, the particular JVM implementation, the phase of the moon, etc. Unless you are doing heavy number crunching, I wouldn't worry about it. Most programs spend most of their time waiting for IO to/from the disk or network.

这篇关于Java:VM 如何在 32 位处理器上处理 64 位 `long`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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