그냥 평균함수는
void Average2(uint8_t *dst, int dstPitch, const uint8_t *src0, int srcPitch0, const uint8_t *src1, int srcPitch1, int width, int height)
{
for(int y = 0 ; y < height; y++)
{
for(int x = 0 ; x < width; x++)
{
dst[x] = (src0[x] + src1[x] + 1) >> 1;
}
dst += dstPitch;
src0 += srcPitch0;
src1 += srcPitch1;
}
}
요렇게 짜면 된다. 근데 사이즈 커지면 은근히 시간 잡아먹음.
그래서
void Average2_AVX2(uint8_t *dst, int dstPitch, const uint8_t *src0, int srcPitch0, const uint8_t *src1, int srcPitch1, int width, int height)
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x += 32)
{
auto s0 = Simd::Load256iAligned(src0 + x);
auto s1 = Simd::Load256iAligned(src1 + x);
Simd::StoreAligned(dst + x, _mm256_avg_epu8(s0, s1));
}
dst += dstPitch;
src0 += srcPitch0;
src1 += srcPitch1;
}
}
요렇게만 바꿔줘도 성능 체감 5배 이상은 빠름 ㅇㅅㅇ
return std::accumulate(list.begin(), list.end(), 0.0) / list.size();
이건 list의 평균이고 내가한건 두개의 list의 각각 원소의 평균이지
오호 ㅇㅅㅇ
이런 건 라이브러리로...! 남이 짜줬으면
조건이 x86 cpu, 각각 pointer의 위치가 32의 배수, pitch가 32의 배수같은게 붙어서 라이브러리로 짜긴 좀 그럼..