class modifier {
private:
float origin = 0.0, range = 1.0;
public:
int map(float input) {
return static_cast<int>((input - origin) / range);
}
};
modifier mod;
mod.origin = std::rand();
mod.range = std::rand(); // example only
for(std::ptrdiff_t y = 0; y < h; ++y)
for(std::ptrdiff_t x = 0; x < w; ++x)
out[x][y] = mod.map( in[x][y] );
Are C++ compilers (GCC, Clang) able to optimize code like this so that the non-static data members origin
and range
remain stored in registers during the iterations, instead of being looked up again each time?