> For the complete documentation index, see [llms.txt](https://eric-lo.gitbook.io/lab-1-simd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eric-lo.gitbook.io/lab-1-simd/simd-in-c-c++/intrinsics.md).

# Intrinsics

In our vector addition example:

{% code title="add\_simd.c" %}

```c
void add_simd(float a[4], float b[4], float result[4])
{
	__m128 v1 = _mm_load_ps(a);
	__m128 v2 = _mm_load_ps(b);
	__m128 v3 = _mm_add_ps(v1, v2);
	_mm_store_ps(result, v3);
}
```

{% endcode %}

The 5th line does the actual work of performing the addition operation. [Intel Intrinsic Guide](https://software.intel.com/sites/landingpage/IntrinsicsGuide/) describes the functionality of this intrinsic clearly in pseudo-code:

![](https://2267274569-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LoF4fSjDhFLH6o9i9dX%2F-LoGT_IXLwdBSWMAjaTP%2F-LoHAsaLUl0HouN7-yua%2Fimage.png?alt=media\&token=4b6e0af3-171d-407d-89ac-ff7ab30cf768)

Basically, the pseudo-code tells us \_mm\_add\_ps does exactly as illustrated in the following:

![](https://2267274569-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LoF4fSjDhFLH6o9i9dX%2F-LoIWYGjnRLy_p8u0LHa%2F-LoIa-USZmOv2LvVsim_%2Fimage.png?alt=media\&token=014b8918-09cd-4d53-a2da-88401216c5f8)

Note that the pseudo-code is only a logical description of what the intrinsic does but not how it actually works. For simplicity, the pseudo-code is written as a serial program, but actually the iterations of for-loop run in parallel.

For now, we only introduce `_mm_add_ps`, but there are plenty of intrinsics that provide various arithmetic operations on different types of data. In practice, you need to find the one that best fits your needs. To do so, play with [Intel Intrinsic Guide](https://software.intel.com/sites/landingpage/IntrinsicsGuide/), it is super useful and convenient for SIMD programming! :laughing:&#x20;
