Я пишу фильтр для изображений, который вычисляет среднее значение 2x2 пикселей. Я выполняю часть вычислений, накапливая сумму двух пикселей в один пиксель.
Код: Выделить всё
template
inline void accumulate_2x2_x_pass(
T* channel, U* accum,
const size_t sx, const size_t sy,
const size_t osx, const size_t osy,
const size_t yoff, const size_t oyoff
) {
const bool odd_x = (sx & 0x01);
size_t i_idx, o_idx;
// Should be vectorizable somehow...
for (size_t x = 0, ox = 0; x < sx - (size_t)odd_x; x += 2, ox++) {
i_idx = x + yoff;
o_idx = ox + oyoff;
accum[o_idx] += channel[i_idx];
accum[o_idx] += channel[i_idx + 1];
}
if (odd_x) {
//
Подробнее здесь: [url]https://stackoverflow.com/questions/55057933/simd-accumulate-adjacent-pairs[/url]
Мобильная версия