「B8G8R8フォーマットで24bitずつ詰めて羅列された画像データを、B8G8R8A8フォーマット(A8は255とする)で32bitずつ詰めて羅列された画像データに変換するのに効率の良いコードは何か?」という話題がありました。
これについて多数の手法でソースコード「BGRtoBGRA.cpp」を作成し、ベンチマークをとってみました。
アセンブラの熟練度はそう高くありませんので、この中にあるコードの一番速いものが、ベストであるとは限りません。よりよいものが出来たら優しくお教え下さればと思います。
B8G8R8 to B8G8R8A8 convsersion-code benchmark VER.2000-11-20d by (C)2000 XELF. width=1024 height=1024 (BGR source=3145728 [bytes], BGRA destination=4194304 [bytes]) MMX +Prefetch +nt: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 16.96 [ms] MMX +nt: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 20.34 [ms] Asm 1px byte,byte,word copy: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 30.81 [ms] Asm 3dword-set byte or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 38.97 [ms] Asm 3dword-set dword or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 28.02 [ms] MMX: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 28.02 [ms] Asm 3dword-set dword or +Prefetch: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 24.19 [ms] MMX +Prefetch: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 23.72 [ms] C++ byte: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 31.18 [ms] C++ byte,byte,word: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 32.88 [ms] C++ byte,byte,word ver.2: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 31.68 [ms] C++ 3dword-set: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 31.00 [ms] Asm 1px byte or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 49.32 [ms] Asm 1px dword or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 51.05 [ms] completed.
B8G8R8 to B8G8R8A8 convsersion-code benchmark VER.2000-11-20d by (C)2000 XELF. width=1024 height=1024 (BGR source=3145728 [bytes], BGRA destination=4194304 [bytes]) Asm 1px byte,byte,word copy: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 171.12 [ms] Asm 3dword-set byte or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 72.34 [ms] Asm 3dword-set dword or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 72.75 [ms] MMX: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 76.56 [ms] C++ byte: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 218.52 [ms] C++ byte,byte,word: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 169.46 [ms] C++ byte,byte,word ver.2: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 168.88 [ms] C++ 3dword-set: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 72.84 [ms] Asm 1px byte or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 73.16 [ms] Asm 1px dword or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 73.67 [ms] completed.
B8G8R8 to B8G8R8A8 convsersion-code benchmark VER.2000-11-20 by (C)2000 XELF. width=1024 height=1024 (BGR source=3145728 [bytes], BGRA destination=4194304 [bytes]) C++ byte: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 31.07 [ms] C++ byte,byte,word: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 32.68 [ms] C++ byte,byte,word ver.2: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 31.53 [ms] C++ 3dword-set: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 30.55 [ms] Asm 1px byte or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 48.78 [ms] Asm 1px dword or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 50.69 [ms] Asm 3dword-set byte or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 38.32 [ms] Asm 3dword-set dword or: FF 01 02 03 FF 04 05 06 FF 07 08 09 FF 0A 0B 0C 27.54 [ms] completed.