2021. 10. 8. 16:06 자기개발/SIMD
SIMD - Intrinsics 개요
명명법
_mm_<intrin_op>_<suffix>
_mm_:SIMD의 intrinsics 함수를 의미한다.
<intrin_op> : 함수가 실제로 동작할 연산자를 의미한다.
<suffix> : 사용하게 될 인자의 데이터 타입과 사이즈, packed 혹은 scalar와 같은 정보가 들어가게 된다. 두개의 문자가 포함되게 되는데, 첫 번쨰는 packed(p), extended packed(ep), scalar(s)가 들어간다. 두 번째 들어갈 문자는 데이터 형의 크기로, 들어가는 문자는 다음과 같다.

128bit 정수형 데이터 타입
명명법
__m128
접두사 __m은 Intrinsics 데이터 타입을 나타낸다. 128과 i는 각각 데이터형의 사이즈가 128bit임과 정수형을 의미한다.



데이터 읽고 쓰기
- 메모리에서 데이터 읽기
byte, short, interger, __int64로 이루어진 정수형 메모리 배열에서 __m128i 데이터형으로 값을 가져온다.
정렬된 메모리에서 데이터 읽어오기
__m128ir = _mm_load_si128(__m128iconst*p)
정렬되지 않은 메모리에서 데이터 읽어오기
__m128ir = _mm_loadu_si128(__m128iconst*p)
- 메모리에서 데이터 쓰기
__m128i 데이터형에 있는 데이터를 byte, short, interger, __int64로 이루어진 정수형 메모리 배열에 쓴다.
정렬된 메모리에서 데이터 쓰기
void_mm_store_si128(__m128i*p,__m128i b)
정렬되지 않은 메모리에서 데이터 쓰기
void_mm_storeu_si128(__m128i*p,__m128i b)
정렬된 메모리 사용 예
#include <iostream>
#include <afx.h>
using namespace std;
#include <emmintrin.h>
int main(int argc, char* argv[])
{
__declspec(align(16)) short Source[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
__declspec(align(16)) short Dest[8] = { 0 };
__m128i xmmA = _mm_load_si128((__m128i*)Source);
__m128i xmmB = xmmA;
_mm_store_si128((__m128i*)Dest, xmmB);
cout << "Dest : " << Dest[7] << ", " << Dest[6] << ", " << Dest[5] << ", " << Dest[4] << ", " << Dest[3] << ", " << Dest[2] << ", " << Dest[1] << ", " << Dest[0] << endl;
return 0;
}
정렬되지 않은 메모리 사용 예
int main(int argc, char* argv[])
{
__declspec(align(16)) short Source[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
__declspec(align(16)) short Dest[8] = { 0 };
__m128i xmmA = _mm_load_si128((__m128i*)Source);
_mm_storeu_si128((__m128i*)Dest, xmmA);
cout << "Dest : " << Dest[7] << ", " << Dest[6] << ", " << Dest[5] << ", " << Dest[4] << ", " << Dest[3] << ", " << Dest[2] << ", " << Dest[1] << ", " << Dest[0] << endl;
return 0;
}
결과

'자기개발 > SIMD' 카테고리의 다른 글
| SIMD - Intrinsics 세트 함수(값 입력 함수) (0) | 2021.10.08 |
|---|---|
| SIMD - Intrinsics 정수의 산술 연산 (0) | 2021.10.08 |
| SIMD - memcpy구현 (0) | 2021.10.08 |
| SIMD - 최대값 구하기( C랑 비교) (0) | 2021.10.08 |
| SIMD - 정수 연산 SIMD 프로그래밍(XMM 값 대입, 논리 연산) (0) | 2021.10.07 |