A modern way to use SIMD instructions in C ++ using g ++

I am building a ray tracer, and in many cases I need to make additions and multiplications on three floats.

In such cases, I did it naively:

class Color{ float mR, mG, mB; ... Color operator+(const Color &color) const { return Color(mR + color.mR, mG + color.mG, mB + color.mB); } Color operator*(const Color &color) const { return Color(mR * color.mR / COLOR_MAX, mG * color.mG / COLOR_MAX, mB * color.mB / COLOR_MAX); } } 

This will also happen in equivalent classes such as Point or Vect3 .

Then I heard about SIMD instructions and they look like they are suitable for what I am doing. So, of course, I searched for it and found this piece of code:

 typedef int v4sf __attribute__((mode(V4SF))); // Vector of three single floats union f4vector { v4sf v; float f[4]; }; 

What primarily uses the extra four, I do not need right now. But then gcc warns me that:

specifying vector types with __attribute__ ((mode)) is deprecated

I would like to know how to do this in C ++ 14 (if that even matters at all), and I cannot find another way to do this.

+6
source share

Source: https://habr.com/ru/post/1012843/


All Articles