From cdd80e04c9a2a63ff321e7cf26bc75ef01c4dc38 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Mon, 9 Mar 2015 21:56:48 +0000 Subject: [PATCH] Port I444ToARGB to AVX2. BUG=403 TESTED=I444ToARGB unittests R=tpsiaki@google.com Review URL: https://webrtc-codereview.appspot.com/45589004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@1314 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/row.h | 12 +++++++++- include/libyuv/version.h | 2 +- source/convert_argb.cc | 8 +++++++ source/row_any.cc | 3 +++ source/row_win.cc | 48 ++++++++++++++++++++++++++++++++++++++++ unit_test/color_test.cc | 8 +------ 7 files changed, 73 insertions(+), 10 deletions(-) diff --git a/README.chromium b/README.chromium index 99ef43862..ad80c4d5c 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1313 +Version: 1314 License: BSD License File: LICENSE diff --git a/include/libyuv/row.h b/include/libyuv/row.h index dbe882dba..cbd0200ef 100644 --- a/include/libyuv/row.h +++ b/include/libyuv/row.h @@ -198,7 +198,7 @@ extern "C" { #define HAS_I422TORGB565ROW_AVX2 #define HAS_I422TOARGB1555ROW_AVX2 #define HAS_I422TOARGB4444ROW_AVX2 - +#define HAS_I444TOARGBROW_AVX2 // TODO(fbarchard): Port to Neon #define HAS_ARGBTORGB565DITHERROW_SSE2 #define HAS_ARGBTORGB565DITHERROW_AVX2 @@ -1046,6 +1046,11 @@ void I444ToARGBRow_SSSE3(const uint8* src_y, const uint8* src_v, uint8* dst_argb, int width); +void I444ToARGBRow_AVX2(const uint8* src_y, + const uint8* src_u, + const uint8* src_v, + uint8* dst_argb, + int width); void I422ToARGBRow_SSSE3(const uint8* src_y, const uint8* src_u, const uint8* src_v, @@ -1185,6 +1190,11 @@ void I444ToARGBRow_Any_SSSE3(const uint8* src_y, const uint8* src_v, uint8* dst_argb, int width); +void I444ToARGBRow_Any_AVX2(const uint8* src_y, + const uint8* src_u, + const uint8* src_v, + uint8* dst_argb, + int width); void I422ToARGBRow_Any_SSSE3(const uint8* src_y, const uint8* src_u, const uint8* src_v, diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 0ea38d522..98ada7313 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1313 +#define LIBYUV_VERSION 1314 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/source/convert_argb.cc b/source/convert_argb.cc index 66f766079..beb6543ca 100644 --- a/source/convert_argb.cc +++ b/source/convert_argb.cc @@ -85,6 +85,14 @@ int I444ToARGB(const uint8* src_y, int src_stride_y, } } #endif +#if defined(HAS_I444TOARGBROW_AVX2) + if (TestCpuFlag(kCpuHasAVX2)) { + I444ToARGBRow = I444ToARGBRow_Any_AVX2; + if (IS_ALIGNED(width, 16)) { + I444ToARGBRow = I444ToARGBRow_AVX2; + } + } +#endif #if defined(HAS_I444TOARGBROW_NEON) if (TestCpuFlag(kCpuHasNEON)) { I444ToARGBRow = I444ToARGBRow_Any_NEON; diff --git a/source/row_any.cc b/source/row_any.cc index c44d0b7a1..84d8d0632 100644 --- a/source/row_any.cc +++ b/source/row_any.cc @@ -73,6 +73,9 @@ YANY(I422ToRGBARow_Any_AVX2, I422ToRGBARow_AVX2, I422ToRGBARow_C, 1, 4, 15) #ifdef HAS_I422TOABGRROW_AVX2 YANY(I422ToABGRRow_Any_AVX2, I422ToABGRRow_AVX2, I422ToABGRRow_C, 1, 4, 15) #endif +#ifdef HAS_I444TOARGBROW_AVX2 +YANY(I444ToARGBRow_Any_AVX2, I444ToARGBRow_AVX2, I444ToARGBRow_C, 0, 4, 15) +#endif #ifdef HAS_I422TOARGB4444ROW_AVX2 YANY(I422ToARGB4444Row_Any_AVX2, I422ToARGB4444Row_AVX2, I422ToARGB4444Row_C, 1, 2, 7) diff --git a/source/row_win.cc b/source/row_win.cc index 08941f2a9..93ee58240 100644 --- a/source/row_win.cc +++ b/source/row_win.cc @@ -1678,6 +1678,16 @@ void RGBAToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb, } #endif // HAS_ARGBTOYROW_SSSE3 +// Read 16 UV from 444 +#define READYUV444_AVX2 __asm { \ + __asm vmovdqu xmm0, [esi] /* U */ /* NOLINT */ \ + __asm vmovdqu xmm1, [esi + edi] /* V */ /* NOLINT */ \ + __asm lea esi, [esi + 16] \ + __asm vpermq ymm0, ymm0, 0xd8 \ + __asm vpermq ymm1, ymm1, 0xd8 \ + __asm vpunpcklbw ymm0, ymm0, ymm1 /* UV */ \ + } + // Read 8 UV from 422, upsample to 16 UV. #define READYUV422_AVX2 __asm { \ __asm vmovq xmm0, qword ptr [esi] /* U */ /* NOLINT */ \ @@ -1775,6 +1785,44 @@ void I422ToARGBRow_AVX2(const uint8* y_buf, } #endif // HAS_I422TOARGBROW_AVX2 +#ifdef HAS_I444TOARGBROW_AVX2 +// 16 pixels +// 16 UV values with 16 Y producing 16 ARGB (64 bytes). +__declspec(naked) __declspec(align(16)) +void I444ToARGBRow_AVX2(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* dst_argb, + int width) { + __asm { + push esi + push edi + mov eax, [esp + 8 + 4] // Y + mov esi, [esp + 8 + 8] // U + mov edi, [esp + 8 + 12] // V + mov edx, [esp + 8 + 16] // argb + mov ecx, [esp + 8 + 20] // width + sub edi, esi + vpcmpeqb ymm5, ymm5, ymm5 // generate 0xffffffffffffffff for alpha + + convertloop: + READYUV444_AVX2 + YUVTORGB_AVX2(kYuvConstants) + STOREARGB_AVX2 + + sub ecx, 16 + jg convertloop + + pop edi + pop esi + vzeroupper + ret + } +} +#endif // HAS_I444TOARGBROW_AVX2 + + + #ifdef HAS_NV12TOARGBROW_AVX2 // 16 pixels. // 8 UV values upsampled to 16 UV, mixed with 16 Y producing 16 ARGB (64 bytes). diff --git a/unit_test/color_test.cc b/unit_test/color_test.cc index 6de5dc694..0adff146b 100644 --- a/unit_test/color_test.cc +++ b/unit_test/color_test.cc @@ -185,13 +185,7 @@ static void YToRGB(int y, int* r, int* g, int* b) { static int RoundToByte(double f) { int i = static_cast(f + 0.5); - if (i < 0) { - i = 0; - } - if (i > 255) { - i = 255; - } - return i; + return (i & ~0xff) ? (int)(((int32)(-i) >> 31) & 0xff) : i; } static void YUVToRGBReference(int y, int u, int v, int* r, int* g, int* b) {