From ce2c5055cee5d5d3c9fc84c1b3eeed4b4d84a827 Mon Sep 17 00:00:00 2001 From: mtklein Date: Mon, 27 Jul 2015 10:52:33 -0700 Subject: [PATCH] Lay groundwork for SkOpts. This doesn't really do anything yet. It's just the CPU detection code, skeleton new .cpp files, and a few little .gyp tweaks. BUG=skia:4117 Review URL: https://codereview.chromium.org/1255193002 --- gyp/core.gypi | 1 + gyp/opts.gyp | 1 + gyp/opts.gypi | 5 ++++ src/core/SkGraphics.cpp | 2 ++ src/core/SkOpts.cpp | 48 +++++++++++++++++++++++++++++++++++++++ src/core/SkOpts.h | 22 ++++++++++++++++++ src/opts/SkOpts_neon.cpp | 14 ++++++++++++ src/opts/SkOpts_sse2.cpp | 14 ++++++++++++ src/opts/SkOpts_sse41.cpp | 14 ++++++++++++ src/opts/SkOpts_ssse3.cpp | 14 ++++++++++++ 10 files changed, 135 insertions(+) create mode 100644 src/core/SkOpts.cpp create mode 100644 src/core/SkOpts.h create mode 100644 src/opts/SkOpts_neon.cpp create mode 100644 src/opts/SkOpts_sse2.cpp create mode 100644 src/opts/SkOpts_sse41.cpp create mode 100644 src/opts/SkOpts_ssse3.cpp diff --git a/gyp/core.gypi b/gyp/core.gypi index 389fca6d61..8618324d87 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -134,6 +134,7 @@ '<(skia_src_path)/core/SkMiniRecorder.cpp', '<(skia_src_path)/core/SkMultiPictureDraw.cpp', '<(skia_src_path)/core/SkNinePatchIter.cpp', + '<(skia_src_path)/core/SkOpts.cpp', '<(skia_src_path)/core/SkPackBits.cpp', '<(skia_src_path)/core/SkPaint.cpp', '<(skia_src_path)/core/SkPaintPriv.cpp', diff --git a/gyp/opts.gyp b/gyp/opts.gyp index b4fb609881..1c767af99b 100644 --- a/gyp/opts.gyp +++ b/gyp/opts.gyp @@ -105,6 +105,7 @@ 'type': 'static_library', 'standalone_static_library': 1, 'dependencies': [ 'core.gyp:*' ], + 'include_dirs': [ '../src/core' ], 'sources': [ '<@(sse41_sources)' ], 'conditions': [ [ 'skia_os == "win"', { diff --git a/gyp/opts.gypi b/gyp/opts.gypi index 6d7a796ad9..44e57d524c 100644 --- a/gyp/opts.gypi +++ b/gyp/opts.gypi @@ -34,6 +34,7 @@ '<(skia_src_path)/opts/SkTextureCompression_opts_neon.cpp', '<(skia_src_path)/opts/SkUtils_opts_arm_neon.cpp', '<(skia_src_path)/opts/SkXfermode_opts_arm_neon.cpp', + '<(skia_src_path)/opts/SkOpts_neon.cpp', ], 'arm64_sources': [ '<(skia_src_path)/opts/SkBitmapProcState_arm_neon.cpp', @@ -51,6 +52,7 @@ '<(skia_src_path)/opts/SkUtils_opts_none.cpp', '<(skia_src_path)/opts/SkXfermode_opts_arm.cpp', '<(skia_src_path)/opts/SkXfermode_opts_arm_neon.cpp', + '<(skia_src_path)/opts/SkOpts_neon.cpp', ], 'mips_dsp_sources': [ @@ -74,12 +76,15 @@ '<(skia_src_path)/opts/SkUtils_opts_SSE2.cpp', '<(skia_src_path)/opts/SkXfermode_opts_none.cpp', '<(skia_src_path)/opts/opts_check_x86.cpp', + '<(skia_src_path)/opts/SkOpts_sse2.cpp', ], 'ssse3_sources': [ '<(skia_src_path)/opts/SkBitmapProcState_opts_SSSE3.cpp', + '<(skia_src_path)/opts/SkOpts_ssse3.cpp', ], 'sse41_sources': [ '<(skia_src_path)/opts/SkBlurImage_opts_SSE4.cpp', '<(skia_src_path)/opts/SkBlitRow_opts_SSE4.cpp', + '<(skia_src_path)/opts/SkOpts_sse41.cpp', ], } diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp index 7acee85c4d..4b94b07e06 100644 --- a/src/core/SkGraphics.cpp +++ b/src/core/SkGraphics.cpp @@ -14,6 +14,7 @@ #include "SkGeometry.h" #include "SkMath.h" #include "SkMatrix.h" +#include "SkOpts.h" #include "SkPath.h" #include "SkPathEffect.h" #include "SkPixelRef.h" @@ -50,6 +51,7 @@ void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) { #endif void SkGraphics::Init() { + SkOpts::Init(); #ifdef SK_DEVELOPER skRTConfRegistry().possiblyDumpFile(); skRTConfRegistry().validate(); diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp new file mode 100644 index 0000000000..c90adf85ca --- /dev/null +++ b/src/core/SkOpts.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkOpts.h" + +#if defined(SK_CPU_X86) + #if defined(SK_BUILD_FOR_WIN32) + #include + static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); } + #else + #include + static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abcd+2, abcd+3); } + #endif +#elif defined(SK_BUILD_FOR_ANDROID) + #include +#endif + +namespace SkOpts { + // (Define default function pointer values here...) + + // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. + void Init_sse2(); + void Init_ssse3(); + void Init_sse41(); + void Init_neon(); + //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ? + + void Init() { + #if defined(SK_CPU_X86) + uint32_t abcd[] = {0,0,0,0}; + cpuid(abcd); + if (abcd[3] & (1<<26)) { Init_sse2(); } + if (abcd[2] & (1<< 9)) { Init_ssse3(); } + if (abcd[2] & (1<<19)) { Init_sse41(); } + + #elif defined(SK_ARM_HAS_NEON) + Init_neon(); + + #elif defined(SK_BUILD_FOR_ANDROID) + if (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) { Init_neon(); } + + #endif + } +} diff --git a/src/core/SkOpts.h b/src/core/SkOpts.h new file mode 100644 index 0000000000..c6eab8df88 --- /dev/null +++ b/src/core/SkOpts.h @@ -0,0 +1,22 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkOpts_DEFINED +#define SkOpts_DEFINED + +#include "SkTypes.h" + +namespace SkOpts { + // Called by SkGraphics::Init(). + // It's not thread safe, but it's fine to call more than once. + // If Init() were somehow not called, that'd also be fine: you'll get portable fallbacks. + void Init(); + + // (Function pointers go here). +} + +#endif//SkOpts_DEFINED diff --git a/src/opts/SkOpts_neon.cpp b/src/opts/SkOpts_neon.cpp new file mode 100644 index 0000000000..3508b35318 --- /dev/null +++ b/src/opts/SkOpts_neon.cpp @@ -0,0 +1,14 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkOpts.h" + +namespace SkOpts { + void Init_neon() { + + } +} diff --git a/src/opts/SkOpts_sse2.cpp b/src/opts/SkOpts_sse2.cpp new file mode 100644 index 0000000000..31afa8cae7 --- /dev/null +++ b/src/opts/SkOpts_sse2.cpp @@ -0,0 +1,14 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkOpts.h" + +namespace SkOpts { + void Init_sse2() { + + } +} diff --git a/src/opts/SkOpts_sse41.cpp b/src/opts/SkOpts_sse41.cpp new file mode 100644 index 0000000000..72e5682463 --- /dev/null +++ b/src/opts/SkOpts_sse41.cpp @@ -0,0 +1,14 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkOpts.h" + +namespace SkOpts { + void Init_sse41() { + + } +} diff --git a/src/opts/SkOpts_ssse3.cpp b/src/opts/SkOpts_ssse3.cpp new file mode 100644 index 0000000000..de3296654f --- /dev/null +++ b/src/opts/SkOpts_ssse3.cpp @@ -0,0 +1,14 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkOpts.h" + +namespace SkOpts { + void Init_ssse3() { + + } +}