Program The rantings of a lunatic Scientist

SIMD examples for OS revision

C/C++ University

For anyone taking the OS exam this wednesday, here are some naive vs. SIMD (AVX) function examples which we wrote during a revision session.

You can get the gist directly here.

EDIT: I’ve gone back and modified the minValAVX function. Previously it would overwrite the source list as it went, something I didn’t pick up because the test was being run last.

Also, the function used to solve the minimum of each group of eight using SIMD then using a naive approach to collate the sub-results. This has now been changed so that results for each group are copied into a float8 buffer as they are computed. The function then loops back on itself to reduce these values in turn until there is only one value remaining.

This style of solution is effectively a map-reduce function, which allowed me to create a second function sumValAVX simply by copying minValAVX and changing the three occurrences of min8() to add8(). Currently the speed-up of the two map-reduce functions by comparison to their naive alternatives is a 38-40% speed up over the course of ~ 4 million elements.

The only issue with the summing function is that for large length arrays so much copying and combining of the data occurs that floating-point precision errors become apparent sooner than with the naive O(n) function.