As
>>4-san already mentioned, you want to use SSE, Altivec, NEON, or whatever SIMD instruction set you have at your disposal. It will be faster than trying to hack it using regular SISD arithmetic instructions and union casts by a factor of 4 or more. Most SIMD pipelines also support integer instructions, including bitwise operators, shifts, and basic integer arithmetic. Generally, you have 128-bit types to work with, but newer SIMD architectures are moving to 256-bit, 512-bit, and even 1024-bit SIMD types.
// Compile with $ gcc/clang -msse2 on x86/x86-64. Following code also works in MSVC++ and Intel C++.
#include <immintrin.h>
int main() {
__m128i test = _mm_set_epi32(0, 0, 0, 1); // 128-bits, fuck my anus
test = _mm_slli_si128(test, 1); // shift-left logical 1 bit
return 0;
}
You can't rely on long double being 128-bits. On x86/x86-64 it's actually only 80-bits, but gets padded/aligned to 128-bits. The top 48-bits are unused and most likely get zero'd by the compiler and you wouldn't be able to use it to reliably store data. Furthermore, both Intel C++ and MSVC++ just make long double be an alias for double anyway, so it's 64-bits with those compilers, as the x87 FPU has been deprecated anyway in favor of SSE/AVX. This is fully standard compliant too, the C and C++ language standards make no guarantees as to the size or precise binary format of long double. On other platforms without double-precision, like some game consoles with custom MIPS RISC or Power processors, both double and long-double are in fact aliases for 32-bit floats.