Последовательный и векторизованный код
Parallel STL const int SIZE = 8; int vec[] = {1, 2, 3, 4, 5, 6, 7, 8}; int res[SIZE] = {0,}; int main(){ for(int i = 0; i < SIZE; ++i){ res[i] = vec[i] + 5; } } Sequential Vectorised movslq -8(%rbp), %rax movl vec(,%rax,4), %ecx addl $5, %ecx movslq -8(%rbp), %rax movl %ecx, res(,%rax,4) movdqa .LCPI0_3(%rip), %xmm0 # xmm0 = [5,5,5,5] movdqa vec(%rip), %xmm1 paddd %xmm0, %xmm1 movdqa %xmm1, res(%rip) movdqa vec+16(%rip), %xmm0 paddd %xmm0, %xmm1 movdqa %xmm1, res+16(%rip)
На слайде показано, как одну и ту же операцию над массивом можно выполнить последовательно или векторизованно. Вверху обычный цикл C++, а внизу — соответствующий ассемблер: последовательная версия обрабатывает элементы по одному, Vectorised использует SIMD-регистры. Шутка в контрасте между красивым названием Parallel STL и довольно низкоуровневым ассемблером, который приходится разбирать, когда язык не делает всё за программиста. EN: The slide shows how the same operation on an array can be performed sequentially or in vectorised form. At the top is a regular C++ loop, and below are the corresponding assembly snippets: the sequential version processes elements one by one, while the vectorised version uses SIMD registers. The joke is the contrast between the elegant name “Parallel STL” and the low-level assembly programmers may still have to study when the language does not do everything for them.
- @ithueti / 856 2019-04-20
- Type
- image
- Size
- 800×601 · 30.9 KiB
- Mood
- ироничный
- Language
- en
- Added