summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authordalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-12 08:29:32 +0000
committerdalecurtis@chromium.org <dalecurtis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-12 08:29:32 +0000
commit55508c4b3b949c1ead26e59e5685d94d16131da0 (patch)
tree4b59d54c592ee34e7d8ae141c8875b7be79b3847 /media
parent993402c92ba6629ebe4bec234e1bbf2a100b9867 (diff)
downloadchromium_src-55508c4b3b949c1ead26e59e5685d94d16131da0.zip
chromium_src-55508c4b3b949c1ead26e59e5685d94d16131da0.tar.gz
chromium_src-55508c4b3b949c1ead26e59e5685d94d16131da0.tar.bz2
Remove duplicate CPU detection code; use base::CPU instead.
BUG=none TEST=media_unittests. Review URL: https://chromiumcodereview.appspot.com/10537082 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/cpu_features.h27
-rw-r--r--media/base/cpu_features_arm.cc17
-rw-r--r--media/base/cpu_features_x86.cc92
-rw-r--r--media/base/simd/convert_rgb_to_yuv_ssse3.cc3
-rw-r--r--media/base/simd/convert_rgb_to_yuv_unittest.cc7
-rw-r--r--media/base/simd/convert_yuv_to_rgb_x86.cc3
-rw-r--r--media/base/yuv_convert.cc36
-rw-r--r--media/base/yuv_convert_unittest.cc35
-rw-r--r--media/media.gyp25
9 files changed, 51 insertions, 194 deletions
diff --git a/media/base/cpu_features.h b/media/base/cpu_features.h
deleted file mode 100644
index 0878385..0000000
--- a/media/base/cpu_features.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// This file provide utility functions to check CPU features such as SSE2,
-// NEON.
-
-#ifndef MEDIA_BASE_CPU_FEATURES_H_
-#define MEDIA_BASE_CPU_FEATURES_H_
-
-namespace media {
-
-// Returns true if CPU has MMX support.
-bool hasMMX();
-
-// Returns true if CPU has SSE support.
-bool hasSSE();
-
-// Returns true if CPU has SSE2 support.
-bool hasSSE2();
-
-// Returns true if CPU supports SSE2, SSE3, and SSSE3.
-bool hasSSSE3();
-
-} // namespace media
-
-#endif // MEDIA_BASE_CPU_FEATURES_H_
diff --git a/media/base/cpu_features_arm.cc b/media/base/cpu_features_arm.cc
deleted file mode 100644
index a0d5c68..0000000
--- a/media/base/cpu_features_arm.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "media/base/cpu_features.h"
-
-namespace media {
-
-bool hasSSE2() {
- return false;
-}
-
-bool hasSSSE3() {
- return false;
-}
-
-} // namespace media
diff --git a/media/base/cpu_features_x86.cc b/media/base/cpu_features_x86.cc
deleted file mode 100644
index d1c70c5..0000000
--- a/media/base/cpu_features_x86.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Code in this file is taked from
-// third_party/skia/src/opts/opts_check_SSE2.cpp.
-
-// Note that this file cannot be compiled with -msse2 in gcc.
-
-#include "build/build_config.h"
-#include "media/base/cpu_features.h"
-
-namespace media {
-
-#ifdef _MSC_VER
-static inline void getcpuid(int info_type, int info[4]) {
- __asm {
- mov eax, [info_type]
- cpuid
- mov edi, [info]
- mov [edi], eax
- mov [edi+4], ebx
- mov [edi+8], ecx
- mov [edi+12], edx
- }
-}
-#else
-static inline void getcpuid(int info_type, int info[4]) {
- // We save and restore ebx, so this code can be compatible with -fPIC
-#if defined(__i386__)
- asm volatile (
- "pushl %%ebx \n\t"
- "cpuid \n\t"
- "movl %%ebx, %1 \n\t"
- "popl %%ebx \n\t"
- : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
- : "a"(info_type)
- );
-#else
- // We can use cpuid instruction without pushing ebx on gcc x86-64 because it
- // does not use ebx (or rbx) as a GOT register.
- asm volatile (
- "cpuid \n\t"
- : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
- : "a"(info_type)
- : "%rbx"
- );
-#endif
-}
-#endif
-
-bool hasMMX() {
-#if defined(ARCH_CPU_X86_64)
- // Every X86_64 processor has MMX.
- return true;
-#else
- int cpu_info[4] = { 0 };
- getcpuid(1, cpu_info);
- return (cpu_info[3] & (1<<23)) != 0;
-#endif
-}
-
-bool hasSSE() {
-#if defined(ARCH_CPU_X86_64)
- // Every X86_64 processor has SSE.
- return true;
-#else
- int cpu_info[4] = { 0 };
- getcpuid(1, cpu_info);
- return (cpu_info[3] & (1<<25)) != 0;
-#endif
-}
-
-bool hasSSE2() {
-#if defined(ARCH_CPU_X86_64)
- // All X86_64 machines have SSE2, so don't even bother checking.
- return true;
-#else
- int cpu_info[4] = { 0 };
- getcpuid(1, cpu_info);
- return (cpu_info[3] & (1<<26)) != 0;
-#endif
-}
-
-bool hasSSSE3() {
- int cpu_info[4] = { 0 };
- getcpuid(1, cpu_info);
- return (cpu_info[3] & 0x04000000) != 0 && (cpu_info[2] & 0x00000001) != 0 &&
- (cpu_info[2] & 0x00000200) != 0;
-}
-
-} // namespace media
diff --git a/media/base/simd/convert_rgb_to_yuv_ssse3.cc b/media/base/simd/convert_rgb_to_yuv_ssse3.cc
index 2bd6930..10eff35 100644
--- a/media/base/simd/convert_rgb_to_yuv_ssse3.cc
+++ b/media/base/simd/convert_rgb_to_yuv_ssse3.cc
@@ -1,11 +1,10 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/base/simd/convert_rgb_to_yuv.h"
#include "build/build_config.h"
-#include "media/base/cpu_features.h"
#include "media/base/simd/convert_rgb_to_yuv_ssse3.h"
namespace media {
diff --git a/media/base/simd/convert_rgb_to_yuv_unittest.cc b/media/base/simd/convert_rgb_to_yuv_unittest.cc
index a1eab03..020fb25 100644
--- a/media/base/simd/convert_rgb_to_yuv_unittest.cc
+++ b/media/base/simd/convert_rgb_to_yuv_unittest.cc
@@ -1,9 +1,9 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/cpu.h"
#include "base/memory/scoped_ptr.h"
-#include "media/base/cpu_features.h"
#include "media/base/simd/convert_rgb_to_yuv.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -52,7 +52,8 @@ int ConvertRGBToV(const uint8* rgb, int size, bool subsampling) {
TEST(YUVConvertTest, SideBySideRGB) {
// We skip this test on PCs which does not support SSE3 because this test
// needs it.
- if (!media::hasSSSE3())
+ base::CPU cpu;
+ if (!cpu.has_ssse3())
return;
// This test checks a subset of all RGB values so this test does not take so
diff --git a/media/base/simd/convert_yuv_to_rgb_x86.cc b/media/base/simd/convert_yuv_to_rgb_x86.cc
index 3e03ef9..3825bdb 100644
--- a/media/base/simd/convert_yuv_to_rgb_x86.cc
+++ b/media/base/simd/convert_yuv_to_rgb_x86.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,7 +8,6 @@
#include <mmintrin.h>
#endif
-#include "media/base/cpu_features.h"
#include "media/base/simd/convert_yuv_to_rgb.h"
#include "media/base/yuv_convert.h"
diff --git a/media/base/yuv_convert.cc b/media/base/yuv_convert.cc
index f9a6076..094fe794 100644
--- a/media/base/yuv_convert.cc
+++ b/media/base/yuv_convert.cc
@@ -17,10 +17,10 @@
#include "media/base/yuv_convert.h"
+#include "base/cpu.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
-#include "media/base/cpu_features.h"
#include "media/base/simd/convert_rgb_to_yuv.h"
#include "media/base/simd/convert_yuv_to_rgb.h"
#include "media/base/simd/filter_yuv.h"
@@ -37,9 +37,10 @@ namespace media {
static FilterYUVRowsProc ChooseFilterYUVRowsProc() {
#if defined(ARCH_CPU_X86_FAMILY)
- if (hasSSE2())
+ base::CPU cpu;
+ if (cpu.has_sse2())
return &FilterYUVRows_SSE2;
- if (hasMMX())
+ if (cpu.has_mmx())
return &FilterYUVRows_MMX;
#endif
return &FilterYUVRows_C;
@@ -47,9 +48,10 @@ static FilterYUVRowsProc ChooseFilterYUVRowsProc() {
static ConvertYUVToRGB32RowProc ChooseConvertYUVToRGB32RowProc() {
#if defined(ARCH_CPU_X86_FAMILY)
- if (hasSSE())
+ base::CPU cpu;
+ if (cpu.has_sse())
return &ConvertYUVToRGB32Row_SSE;
- if (hasMMX())
+ if (cpu.has_mmx())
return &ConvertYUVToRGB32Row_MMX;
#endif
return &ConvertYUVToRGB32Row_C;
@@ -60,10 +62,11 @@ static ScaleYUVToRGB32RowProc ChooseScaleYUVToRGB32RowProc() {
// Use 64-bits version if possible.
return &ScaleYUVToRGB32Row_SSE2_X64;
#elif defined(ARCH_CPU_X86_FAMILY)
+ base::CPU cpu;
// Choose the best one on 32-bits system.
- if (hasSSE())
+ if (cpu.has_sse())
return &ScaleYUVToRGB32Row_SSE;
- if (hasMMX())
+ if (cpu.has_mmx())
return &ScaleYUVToRGB32Row_MMX;
#endif // defined(ARCH_CPU_X86_64)
return &ScaleYUVToRGB32Row_C;
@@ -74,10 +77,11 @@ static ScaleYUVToRGB32RowProc ChooseLinearScaleYUVToRGB32RowProc() {
// Use 64-bits version if possible.
return &LinearScaleYUVToRGB32Row_MMX_X64;
#elif defined(ARCH_CPU_X86_FAMILY)
+ base::CPU cpu;
// 32-bits system.
- if (hasSSE())
+ if (cpu.has_sse())
return &LinearScaleYUVToRGB32Row_SSE;
- if (hasMMX())
+ if (cpu.has_mmx())
return &LinearScaleYUVToRGB32Row_MMX;
#endif // defined(ARCH_CPU_X86_64)
return &LinearScaleYUVToRGB32Row_C;
@@ -89,7 +93,8 @@ void EmptyRegisterState() {
static bool checked = false;
static bool has_mmx = false;
if (!checked) {
- has_mmx = hasMMX();
+ base::CPU cpu;
+ has_mmx = cpu.has_mmx();
checked = true;
}
if (has_mmx)
@@ -445,7 +450,8 @@ void ConvertRGB32ToYUV(const uint8* rgbframe,
#else
// TODO(hclam): Switch to SSSE3 version when the cyan problem is solved.
// See: crbug.com/100462
- if (hasSSE2())
+ base::CPU cpu;
+ if (cpu.has_sse2())
convert_proc = &ConvertRGB32ToYUV_SSE2;
else
convert_proc = &ConvertRGB32ToYUV_C;
@@ -472,7 +478,8 @@ void ConvertRGB24ToYUV(const uint8* rgbframe,
static void (*convert_proc)(const uint8*, uint8*, uint8*, uint8*,
int, int, int, int, int) = NULL;
if (!convert_proc) {
- if (hasSSSE3())
+ base::CPU cpu;
+ if (cpu.has_ssse3())
convert_proc = &ConvertRGB24ToYUV_SSSE3;
else
convert_proc = &ConvertRGB24ToYUV_C;
@@ -541,9 +548,10 @@ void ConvertYUVToRGB32(const uint8* yplane,
#else
static ConvertYUVToRGB32Proc convert_proc = NULL;
if (!convert_proc) {
- if (hasSSE())
+ base::CPU cpu;
+ if (cpu.has_sse())
convert_proc = &ConvertYUVToRGB32_SSE;
- else if (hasMMX())
+ else if (cpu.has_mmx())
convert_proc = &ConvertYUVToRGB32_MMX;
else
convert_proc = &ConvertYUVToRGB32_C;
diff --git a/media/base/yuv_convert_unittest.cc b/media/base/yuv_convert_unittest.cc
index 7d059c7..153cad8 100644
--- a/media/base/yuv_convert_unittest.cc
+++ b/media/base/yuv_convert_unittest.cc
@@ -3,10 +3,10 @@
// found in the LICENSE file.
#include "base/base_paths.h"
+#include "base/cpu.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
-#include "media/base/cpu_features.h"
#include "media/base/djb2.h"
#include "media/base/simd/convert_rgb_to_yuv.h"
#include "media/base/simd/convert_yuv_to_rgb.h"
@@ -457,7 +457,8 @@ TEST(YUVConvertTest, DownScaleYUVToRGB32WithRect) {
#if !defined(ARCH_CPU_ARM_FAMILY)
TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) {
- if (!media::hasSSE2()) {
+ base::CPU cpu;
+ if (!cpu.has_sse2()) {
LOG(WARNING) << "System doesn't support SSE2, test not executed.";
return;
}
@@ -543,7 +544,8 @@ TEST(YUVConvertTest, RGB32ToYUV_SSE2_MatchReference) {
}
TEST(YUVConvertTest, ConvertYUVToRGB32Row_MMX) {
- if (!media::hasMMX()) {
+ base::CPU cpu;
+ if (!cpu.has_mmx()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -571,7 +573,8 @@ TEST(YUVConvertTest, ConvertYUVToRGB32Row_MMX) {
}
TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) {
- if (!media::hasSSE()) {
+ base::CPU cpu;
+ if (!cpu.has_sse()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -599,7 +602,8 @@ TEST(YUVConvertTest, ConvertYUVToRGB32Row_SSE) {
}
TEST(YUVConvertTest, ScaleYUVToRGB32Row_MMX) {
- if (!media::hasMMX()) {
+ base::CPU cpu;
+ if (!cpu.has_mmx()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -630,7 +634,8 @@ TEST(YUVConvertTest, ScaleYUVToRGB32Row_MMX) {
}
TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) {
- if (!media::hasSSE()) {
+ base::CPU cpu;
+ if (!cpu.has_sse()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -661,7 +666,8 @@ TEST(YUVConvertTest, ScaleYUVToRGB32Row_SSE) {
}
TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX) {
- if (!media::hasMMX()) {
+ base::CPU cpu;
+ if (!cpu.has_mmx()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -692,7 +698,8 @@ TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_MMX) {
}
TEST(YUVConvertTest, LinearScaleYUVToRGB32Row_SSE) {
- if (!media::hasSSE()) {
+ base::CPU cpu;
+ if (!cpu.has_sse()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -738,7 +745,8 @@ TEST(YUVConvertTest, FilterYUVRows_C_OutOfBounds) {
}
TEST(YUVConvertTest, FilterYUVRows_MMX_OutOfBounds) {
- if (!media::hasMMX()) {
+ base::CPU cpu;
+ if (!cpu.has_mmx()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -759,7 +767,8 @@ TEST(YUVConvertTest, FilterYUVRows_MMX_OutOfBounds) {
}
TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) {
- if (!media::hasSSE2()) {
+ base::CPU cpu;
+ if (!cpu.has_sse2()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -779,7 +788,8 @@ TEST(YUVConvertTest, FilterYUVRows_SSE2_OutOfBounds) {
}
TEST(YUVConvertTest, FilterYUVRows_MMX_UnalignedDestination) {
- if (!media::hasMMX()) {
+ base::CPU cpu;
+ if (!cpu.has_mmx()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
@@ -808,7 +818,8 @@ TEST(YUVConvertTest, FilterYUVRows_MMX_UnalignedDestination) {
}
TEST(YUVConvertTest, FilterYUVRows_SSE2_UnalignedDestination) {
- if (!media::hasSSE2()) {
+ base::CPU cpu;
+ if (!cpu.has_sse2()) {
LOG(WARNING) << "System not supported. Test skipped.";
return;
}
diff --git a/media/media.gyp b/media/media.gyp
index 2a8c6c6..056407f 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -445,36 +445,11 @@
],
},
{
- 'target_name': 'cpu_features',
- 'type': 'static_library',
- 'include_dirs': [
- '..',
- ],
- 'conditions': [
- [ 'target_arch == "ia32" or target_arch == "x64"', {
- 'sources': [
- 'base/cpu_features_x86.cc',
- ],
- }],
- [ 'target_arch == "arm"', {
- 'sources': [
- 'base/cpu_features_arm.cc',
- ],
- }],
- ],
- 'sources': [
- 'base/cpu_features.h',
- ],
- },
- {
'target_name': 'yuv_convert',
'type': 'static_library',
'include_dirs': [
'..',
],
- 'dependencies': [
- 'cpu_features',
- ],
'conditions': [
['order_profiling != 0', {
'target_conditions' : [