I really can't get what "keyword" like __m128d
is in C++.
I'm using MSVC, and it says: The __m128d data type, for use with the Streaming SIMD Extensions 2 instructions intrinsics, is defined in <emmintrin.h>
.
So, is it a Data Type? typedef
? If I do:
#include <emmintrin.h>
int main() {
__m128d x;
}
I can't see the defination on <emmintrin.h>
. It seems a keyword
of compiler? Does it automatically convert that keyword to somethings like "move register xmm0" etc? Or which kind of operation does?
It doesn't seems a data type at all.
Can someone shine me?
Is it a typedef?
Yes!
__m128d
is a data type that the compiler will hopefully store in a XMM 128 bit register when optimizing (if not optimizing it away as @PeterCordes commented). It's not inherently different from an int
or long
, which the compiler will hopefully store in integer registers when optimizing.
The actual definition is compiler-specific; code that intends to be portable between MSVC and the other major compilers that implement Intel's intrinsics should avoid depending on the details of the definition.
MSVC defines vector types as a union of arrays of different element sizes.
In compilers that implement GNU C extensions (gcc and clang), it is typedef'ed as a 16-byte GNU C native vector of double
s:
// From gcc 7.3's emmintrin.h (SSE2 extensions). SSE1 stuff in xmmintrin.h
/* The Intel API is flexible enough that we must allow aliasing with other
vector types, and their scalar components. */
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
typedef double __m128d __attribute__ ((__vector_size__ (16), __may_alias__));
in <emmintrin.h>
, as @Default commented.
The may_alias
attribute tells the compiler that __m128d*
can alias other types the same way that char*
can, for the purposes of optimization based on C++ strict-aliasing rules.
Example of usage: (initialization is portable between MSVC and other compilers)
__m128d a2 = { -1.388539L, 0.0L };
For __m128
, check the Intel forum and <xmmintrin.h>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With