Skip to content
Snippets Groups Projects
Commit f90e4c32 authored by David Grellscheid's avatar David Grellscheid
Browse files

More striking vector example

parent 4ddf549f
No related branches found
No related tags found
No related merge requests found
......@@ -60,12 +60,12 @@ int special_add(int a, int b){
}
```
10. **(optional)** Have you heard about vectorization before? Declare the function provided below and set the flags to **-O2** and observe how the asembly code differs to having set the flags to to **-O2** **-mavx**
10. **(optional)** Have you heard about vectorization before? Declare the function provided below and set the flags to **-O1**, **-O2** and observe how the asembly code differs to having set the flags to to **-O2** **-mavx**. Now change the size of the loop, try 4, 8, 16. How many add-operations are run in the assembly?
```c
void add_arrays(float *a, float *b, float *result, int n) {
for (int i = 0; i < n; i++) {
result[i] = a[i] + b[i];
void add_arrays(float *a, float b) {
for (int i = 0; i < 8; i++) {
a[i] += b;
}
}
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment