C++ Adding 2 arrays together quickly

前端 未结 6 1693
一整个雨季
一整个雨季 2021-02-04 16:57

Given the arrays:

int canvas[10][10];
int addon[10][10];

Where all the values range from 0 - 100, what is the fastest way in C++ to add

6条回答
  •  长情又很酷
    2021-02-04 17:28

    Two parts: first, consider your two-dimensional array [10][10] as a single array [100]. The layout rules of C++ should allow this. Second, check your compiler for intrinsic functions implementing some form of SIMD instructions, such as Intel's SSE. For example Microsoft supplies a set. I believe SSE has some instructions for checking against a maximum value, and even clamping to the maximum if you want.

提交回复
热议问题