diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-18 21:28:11 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-18 21:28:11 +0000 |
commit | f15336e83697b42709d3a0582229897ad6558739 (patch) | |
tree | 5f5352161db1ac61b12f10c4f98d2d5beea6f4c6 | |
parent | 593a1179aec175804bde287144e9d7d2606bde34 (diff) | |
download | chromium_src-f15336e83697b42709d3a0582229897ad6558739.zip chromium_src-f15336e83697b42709d3a0582229897ad6558739.tar.gz chromium_src-f15336e83697b42709d3a0582229897ad6558739.tar.bz2 |
Revert "Mac YUV assembly"
This reverts commit r26614.
Review URL: http://codereview.chromium.org/213034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26621 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/base/yuv_row.h | 5 | ||||
-rw-r--r-- | media/base/yuv_row_mac.cc | 331 |
2 files changed, 273 insertions, 63 deletions
diff --git a/media/base/yuv_row.h b/media/base/yuv_row.h index 37bd935..104b9c7 100644 --- a/media/base/yuv_row.h +++ b/media/base/yuv_row.h @@ -63,8 +63,9 @@ void ScaleYUVToRGB32Row(const uint8* y_buf, } // extern "C" #if !defined(USE_MMX) -// Windows, Mac and Linux x86 use MMX; x64 and other CPUs do not. -#if defined(OS_WIN) || defined(ARCH_CPU_X86) +#if defined(_MSC_VER) +#define USE_MMX 1 +#elif defined(OS_LINUX) && defined(ARCH_CPU_X86) #define USE_MMX 1 #else #define USE_MMX 0 diff --git a/media/base/yuv_row_mac.cc b/media/base/yuv_row_mac.cc index 1f33317..c80b213 100644 --- a/media/base/yuv_row_mac.cc +++ b/media/base/yuv_row_mac.cc @@ -4,9 +4,17 @@ #include "media/base/yuv_row.h" +#ifdef _DEBUG +#include "base/logging.h" +#else +#define DCHECK(a) +#endif + +// TODO(fbarchard): Make MMX work in DLLs. Currently only works in unittests. // TODO(fbarchard): Do 64 bit version. extern "C" { +#if USE_MMX #define RGBY(i) { \ static_cast<int16>(1.164 * 64 * (i - 16) + 0.5), \ @@ -29,8 +37,7 @@ extern "C" { 0 \ } -#define MMX_ALIGNED(var) \ - var __attribute__ ((section ("__TEXT,__text"))) __attribute__ ((aligned(16))) +#define MMX_ALIGNED(var) var __attribute__((aligned(16))) MMX_ALIGNED(int16 kCoefficientsRgbY[256][4]) = { RGBY(0x00), RGBY(0x01), RGBY(0x02), RGBY(0x03), @@ -238,36 +245,75 @@ MMX_ALIGNED(int16 kCoefficientsRgbV[256][4]) = { #undef RGBV #undef MMX_ALIGNED -extern void MacConvertYUVToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - int width, - int16 *kCoefficientsRgbY); +// TODO(fbarchard): Use the following function instead of +// pure assembly to help make code more portable to 64 bit +// and Mac, which has different labels. +// no-gcse eliminates the frame pointer, freeing up ebp. + +#if defined(FUTURE_64BIT_VERSION) +void __attribute__((optimize("O2", "no-gcse"))) + NewFastConvertYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + asm( + "shr %4\n" +"1:\n" + "movzb (%1),%%eax\n" + "add $0x1,%1\n" + "movzb (%2),%%ebx\n" + "add $0x1,%2\n" + "movq kCoefficientsRgbU(,%%eax,8),%%mm0\n" + "movzb (%0),%%eax\n" + "paddsw kCoefficientsRgbV(,%%ebx,8),%%mm0\n" + "movzb 0x1(%0),%%ebx\n" + "movq kCoefficientsRgbY(,%%eax,8),%%mm1\n" + "add $0x2,%0\n" + "movq kCoefficientsRgbY(,%%ebx,8),%%mm2\n" + "paddsw %%mm0,%%mm1\n" + "paddsw %%mm0,%%mm2\n" + "psraw $0x6,%%mm1\n" + "psraw $0x6,%%mm2\n" + "packuswb %%mm2,%%mm1\n" + "movntq %%mm1,0x0(%3)\n" + "add $0x8,%3\n" + "sub $0x1,%4\n" + "jne 1b\n" + : : "r"(y_buf),"r"(u_buf),"r"(v_buf),"r"(rgb_buf),"r"(width) + : "eax","ebx"); +} +#endif + +extern void FastConvertYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width); + __asm__( -" .globl _MacConvertYUVToRGB32Row\n" -"_MacConvertYUVToRGB32Row:\n" +" .globl _FastConvertYUVToRGB32Row\n" +"_FastConvertYUVToRGB32Row:\n" "pusha\n" "mov 0x24(%esp),%edx\n" "mov 0x28(%esp),%edi\n" "mov 0x2c(%esp),%esi\n" "mov 0x30(%esp),%ebp\n" - "mov 0x38(%esp),%ecx\n" - - "jmp Lconvertend\n" + "mov 0x34(%esp),%ecx\n" + "jmp convertend\n" -"Lconvertloop:" +"convertloop:" "movzbl (%edi),%eax\n" "add $0x1,%edi\n" "movzbl (%esi),%ebx\n" "add $0x1,%esi\n" - "movq 2048(%ecx,%eax,8),%mm0\n" + "movq _kCoefficientsRgbU(,%eax,8),%mm0\n" "movzbl (%edx),%eax\n" - "paddsw 4096(%ecx,%ebx,8),%mm0\n" + "paddsw _kCoefficientsRgbV(,%ebx,8),%mm0\n" "movzbl 0x1(%edx),%ebx\n" - "movq 0(%ecx,%eax,8),%mm1\n" + "movq _kCoefficientsRgbY(,%eax,8),%mm1\n" "add $0x2,%edx\n" - "movq 0(%ecx,%ebx,8),%mm2\n" + "movq _kCoefficientsRgbY(,%ebx,8),%mm2\n" "paddsw %mm0,%mm1\n" "paddsw %mm0,%mm2\n" "psraw $0x6,%mm1\n" @@ -275,76 +321,67 @@ extern void MacConvertYUVToRGB32Row(const uint8* y_buf, "packuswb %mm2,%mm1\n" "movntq %mm1,0x0(%ebp)\n" "add $0x8,%ebp\n" -"Lconvertend:" - "sub $0x2,0x34(%esp)\n" - "jns Lconvertloop\n" +"convertend:" + "sub $0x2,%ecx\n" + "jns convertloop\n" - "and $0x1,0x34(%esp)\n" - "je Lconvertdone\n" + "and $0x1,%ecx\n" + "je convertdone\n" "movzbl (%edi),%eax\n" - "movq 2048(%ecx,%eax,8),%mm0\n" + "movq _kCoefficientsRgbU(,%eax,8),%mm0\n" "movzbl (%esi),%eax\n" - "paddsw 4096(%ecx,%eax,8),%mm0\n" + "paddsw _kCoefficientsRgbV(,%eax,8),%mm0\n" "movzbl (%edx),%eax\n" - "movq 0(%ecx,%eax,8),%mm1\n" + "movq _kCoefficientsRgbY(,%eax,8),%mm1\n" "paddsw %mm0,%mm1\n" "psraw $0x6,%mm1\n" "packuswb %mm1,%mm1\n" "movd %mm1,0x0(%ebp)\n" -"Lconvertdone:\n" +"convertdone:" "popa\n" "ret\n" ); -void FastConvertYUVToRGB32Row(const uint8* y_buf, - const uint8* u_buf, - const uint8* v_buf, - uint8* rgb_buf, - int width) { - MacConvertYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, width, - &kCoefficientsRgbY[0][0]); -} -extern void MacScaleYUVToRGB32Row(const uint8* y_buf, +extern void ScaleYUVToRGB32Row(const uint8* y_buf, const uint8* u_buf, const uint8* v_buf, uint8* rgb_buf, int width, - int scaled_dx, - int16 *kCoefficientsRgbY); + int scaled_dx); __asm__( -" .globl _MacScaleYUVToRGB32Row\n" -"_MacScaleYUVToRGB32Row:\n" +" .globl _ScaleYUVToRGB32Row\n" +"_ScaleYUVToRGB32Row:\n" "pusha\n" "mov 0x24(%esp),%edx\n" "mov 0x28(%esp),%edi\n" "mov 0x2c(%esp),%esi\n" "mov 0x30(%esp),%ebp\n" - "mov 0x3c(%esp),%ecx\n" + "mov 0x34(%esp),%ecx\n" "xor %ebx,%ebx\n" - "jmp Lscaleend\n" + "jmp scaleend\n" -"Lscaleloop:" +"scaleloop:" "mov %ebx,%eax\n" "sar $0x5,%eax\n" "movzbl (%edi,%eax,1),%eax\n" - "movq 2048(%ecx,%eax,8),%mm0\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" "mov %ebx,%eax\n" "sar $0x5,%eax\n" "movzbl (%esi,%eax,1),%eax\n" - "paddsw 4096(%ecx,%eax,8),%mm0\n" + "paddsw kCoefficientsRgbV(,%eax,8),%mm0\n" "mov %ebx,%eax\n" "add 0x38(%esp),%ebx\n" "sar $0x4,%eax\n" "movzbl (%edx,%eax,1),%eax\n" - "movq 0(%ecx,%eax,8),%mm1\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" "mov %ebx,%eax\n" "add 0x38(%esp),%ebx\n" "sar $0x4,%eax\n" "movzbl (%edx,%eax,1),%eax\n" - "movq 0(%ecx,%eax,8),%mm2\n" + "movq kCoefficientsRgbY(,%eax,8),%mm2\n" "paddsw %mm0,%mm1\n" "paddsw %mm0,%mm2\n" "psraw $0x6,%mm1\n" @@ -352,29 +389,29 @@ extern void MacScaleYUVToRGB32Row(const uint8* y_buf, "packuswb %mm2,%mm1\n" "movntq %mm1,0x0(%ebp)\n" "add $0x8,%ebp\n" -"Lscaleend:" - "sub $0x2,0x34(%esp)\n" - "jns Lscaleloop\n" +"scaleend:" + "sub $0x2,%ecx\n" + "jns scaleloop\n" - "and $0x1,0x34(%esp)\n" - "je Lscaledone\n" + "and $0x1,%ecx\n" + "je scaledone\n" "mov %ebx,%eax\n" "sar $0x5,%eax\n" "movzbl (%edi,%eax,1),%eax\n" - "movq 2048(%ecx,%eax,8),%mm0\n" + "movq kCoefficientsRgbU(,%eax,8),%mm0\n" "mov %ebx,%eax\n" "sar $0x5,%eax\n" "movzbl (%esi,%eax,1),%eax\n" - "paddsw 4096(%ecx,%eax,8),%mm0\n" + "paddsw kCoefficientsRgbV(,%eax,8),%mm0\n" "mov %ebx,%eax\n" "sar $0x4,%eax\n" "movzbl (%edx,%eax,1),%eax\n" - "movq 0(%ecx,%eax,8),%mm1\n" + "movq kCoefficientsRgbY(,%eax,8),%mm1\n" "mov %ebx,%eax\n" "sar $0x4,%eax\n" "movzbl (%edx,%eax,1),%eax\n" - "movq 0(%ecx,%eax,8),%mm2\n" + "movq kCoefficientsRgbY(,%eax,8),%mm2\n" "paddsw %mm0,%mm1\n" "paddsw %mm0,%mm2\n" "psraw $0x6,%mm1\n" @@ -382,22 +419,194 @@ extern void MacScaleYUVToRGB32Row(const uint8* y_buf, "packuswb %mm2,%mm1\n" "movd %mm1,0x0(%ebp)\n" -"Lscaledone:" +"scaledone:" "popa\n" "ret\n" ); +#else // USE_MMX + +// Reference version of YUV converter. +static const int kClipTableSize = 256; +static const int kClipOverflow = 288; // Cb max is 535. + +static uint8 kRgbClipTable[kClipOverflow + + kClipTableSize + + kClipOverflow] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 288 underflow values + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // clipped to 0. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Unclipped values. + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0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F, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +}; + +// Clip an rgb channel value to 0..255 range. +// Source is signed fixed point 8.8. +// Table allows for values to underflow or overflow by 128. +// Therefore source range is -128 to 384. +// Output clips to unsigned 0 to 255. +static inline uint32 clip(int32 value) { + DCHECK(((value >> 8) + kClipOverflow) >= 0); + DCHECK(((value >> 8) + kClipOverflow) < + (kClipOverflow + kClipTableSize + kClipOverflow)); + return static_cast<uint32>(kRgbClipTable[((value) >> 8) + kClipOverflow]); +} + +static inline void YuvPixel(uint8 y, + uint8 u, + uint8 v, + uint8* rgb_buf) { + int32 d = static_cast<int32>(u) - 128; + int32 e = static_cast<int32>(v) - 128; + + int32 cb = (516 * d + 128); + int32 cg = (- 100 * d - 208 * e + 128); + int32 cr = (409 * e + 128); + int32 C298a = ((static_cast<int32>(y) - 16) * 298 + 128); + *reinterpret_cast<uint32*>(rgb_buf) = (clip(C298a + cb)) | + (clip(C298a + cg) << 8) | + (clip(C298a + cr) << 16) | + (0xff000000); +} + +void FastConvertYUVToRGB32Row(const uint8* y_buf, + const uint8* u_buf, + const uint8* v_buf, + uint8* rgb_buf, + int width) { + for (int x = 0; x < width; x += 2) { + uint8 u = u_buf[x >> 1]; + uint8 v = v_buf[x >> 1]; + uint8 y0 = y_buf[x]; + YuvPixel(y0, u, v, rgb_buf); + if ((x + 1) < width) { + uint8 y1 = y_buf[x + 1]; + YuvPixel(y1, u, v, rgb_buf + 4); + } + rgb_buf += 8; // Advance 2 pixels. + } +} + +// 28.4 fixed point is used. A shift by 4 isolates the integer. +// A shift by 5 is used to further subsample the chrominence channels. +// & 15 isolates the fixed point fraction. >> 2 to get the upper 2 bits, +// for 1/4 pixel accurate interpolation. void ScaleYUVToRGB32Row(const uint8* y_buf, const uint8* u_buf, const uint8* v_buf, uint8* rgb_buf, int width, int scaled_dx) { - - MacScaleYUVToRGB32Row(y_buf, u_buf, v_buf, rgb_buf, width, scaled_dx, - &kCoefficientsRgbY[0][0]); + int scaled_x = 0; + for (int x = 0; x < width; ++x) { + uint8 u = u_buf[scaled_x >> 5]; + uint8 v = v_buf[scaled_x >> 5]; + uint8 y0 = y_buf[scaled_x >> 4]; + YuvPixel(y0, u, v, rgb_buf); + rgb_buf += 4; + scaled_x += scaled_dx; + } } - +#endif // USE_MMX } // extern "C" |