Is there hardware support for 128-bit integers in modern processors?

Do we still need to emulate 128-bit integers in the software, or is there hardware support in your average desktop processor these days?

+5
source share
2 answers

The x86-64 instruction set can execute 64-bit * 64-bit up to 128 bits using one command ( mul for unsigned imul for each of them with one operand), so I would say that to some extent this x86 instruction set includes some support for 128-bit integers.

If your instruction set does not have instructions for 64-bit * from 64-bit to 128-bit, you need a few instructions to emulate this .

This is why 128-bit * 128-bit for lower 128-bit operations can be performed with small instructions from x86-64. For example, using GCC

 __int128 mul(__int128 a, __int128 b) { return a*b; } 

creates this assembly

 imulq %rdx, %rsi movq %rdi, %rax imulq %rdi, %rcx mulq %rdx addq %rsi, %rcx addq %rcx, %rdx 

which uses one 64-bit * 64-bit and 128-bit instructions, two 64-bit * 64-bit and lower 64-bit instructions, and two 64-bit add-ons.

+4
source

Short answer: NO!

To clarify, SSE registers are 128 bits wide, but there are no instructions for processing them in the form of 128-bit integers. In the best case, these registers are considered as two 64-bit (un) signed integers. Operations such as adding / ... can be created by adding these two 64-bit values ​​in parallel and manually processing the overflow, but not with a single instruction. Implementing this can become quite complex and ugly, look here:

How to add two SSE registers

This must be done for each main operation with probable advantages compared to the implementation with 64-bit general-purpose registers ("emulation" in software). On the other hand, the advantage of this SSE approach would be that after its implementation it would also work for 256-bit integers (AVX2) and 512-bit integers (AVX-512) with minor changes.

+2
source

Source: https://habr.com/ru/post/1237958/


All Articles