Master the fundamental concepts of simd & vectorization through this focused micro-challenge.
RGBA images store four 8-bit channels per pixel (16 million colors times alpha). Inverting colors is 255 - channel, a perfect SIMD byte operation across 16 pixels per __m128i chunk.
cLoading…
Image kernels often hit DRAM bandwidth before compute limits. Align rows, process full vectors in the hot loop, and handle width remainder scalarly.
For example, a 1920x1080 frame has 2,073,600 pixels; vectorized inversion touches the same bytes as scalar code but issues fewer instructions.
For this exercise, you will invert a buffer with SSE2 byte intrinsics and compare ms/frame to scalar loops. This task asks you to treat alpha separately if premultiplication matters for your test image format.
Keep the relevant datasheet, ISA manual, or architecture textbook chapter open while you implement. When your output disagrees with the reference trace on the same program, the bug is usually a mis-decoded opcode, a stale register read, or a flag bit left unchanged after arithmetic.
For this exercise, you will use those habits while implementing the requirement in the starter code. Microarchitectural product names change across CPU generations, but the control ideas (fetch, bypass, cache lines, vector lanes) stay stable enough to debug from first principles.
Implement RGBA image color inversion using SIMD.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github