From f90e4c329975a59968f43201c05cb85018921e43 Mon Sep 17 00:00:00 2001 From: David Grellscheid <david.grellscheid@uib.no> Date: Mon, 2 Sep 2024 07:21:40 +0200 Subject: [PATCH] More striking vector example --- exercises/week02.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/week02.md b/exercises/week02.md index 77b3163..13735fe 100644 --- a/exercises/week02.md +++ b/exercises/week02.md @@ -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; } } ``` -- GitLab