__m128i类型的解析

          对于SSE2指令集来说用到频率最高的的参数或返回类型,在这篇文章里看一下它定义的原型,并对他进行分析:

          __m128i类型定义在emmintrin.h中,先来看一下它定义的原型:

         typedef union __declspec(intrin_type) _CRT_ALIGN(16) __m128i {
                                                                                                                                   __int8                          m128i_i8[16];
                                                                                                                                   __int16                        m128i_i16[8];
                                                                                                                                   __int32                        m128i_i32[4];   
                                                                                                                                   __int64                        m128i_i64[2];
                                                                                                                                   unsigned __int8        m128i_u8[16];
                                                                                                                                   unsigned __int16      m128i_u16[8];
                                                                                                                                   unsigned __int32      m128i_u32[4];
                                                                                                                                   unsigned __int64      m128i_u64[2];
                                                                                                                                   } __m128i;

          其中_CRT_ALIGN的定义如下:

                  #if !defined(_CRT_ALIGN)
                  #if defined(__midl)
                  #define _CRT_ALIGN(x)
                  
#else
                  #define _CRT_ALIGN(x) __declspec(align(x))
                 
#endif
                  #endif

        另外:__int8 数据类型与类型 char是同义词的, __int16 与类型short是同义词的,__int32 与类型 int是同义词的,__int64 与类型long long是同义词的

        首先:__m128i 为一个共用体(或又称,“联合”,union) 类型,union的特点为:共用体表示几个变量共用一个内存位置,在不同的时间保存不同的数据类型和不同长度的变量。在union中,所有的共用体成员共用一个空间,并且同一时间只能储存其中一个成员变量的值。当一个共用体被声明时, 编译程序自动地产生一个变量, 其长度为联合中最大的变量长度的整数倍。所以__m128i的大小为128字节;

           其次:__declspec(align(16))是设定内存对齐方式,来保证__m128i的大小为128字节;

你可能感兴趣的:(SSE2指令)