senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 8 | #include "SkBitmapProcState_opts_SSE2.h" |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 9 | #include "SkBitmapProcState_opts_SSSE3.h" |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 10 | #include "SkBitmapFilter_opts_SSE2.h" |
reed@google.com | 58af9a6 | 2011-10-12 13:43:52 +0000 | [diff] [blame] | 11 | #include "SkBlitMask.h" |
tomhudson@google.com | 8dd90a9 | 2012-03-19 13:49:50 +0000 | [diff] [blame] | 12 | #include "SkBlitRow.h" |
| 13 | #include "SkBlitRect_opts_SSE2.h" |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 14 | #include "SkBlitRow_opts_SSE2.h" |
| 15 | #include "SkUtils_opts_SSE2.h" |
| 16 | #include "SkUtils.h" |
| 17 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 18 | #include "SkRTConf.h" |
| 19 | |
tomhudson@google.com | ea85494 | 2012-05-17 15:09:17 +0000 | [diff] [blame] | 20 | #if defined(_MSC_VER) && defined(_WIN64) |
| 21 | #include <intrin.h> |
| 22 | #endif |
| 23 | |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 24 | /* This file must *not* be compiled with -msse or -msse2, otherwise |
| 25 | gcc may generate sse2 even for scalar ops (and thus give an invalid |
| 26 | instruction on Pentium3 on the code below). Only files named *_SSE2.cpp |
| 27 | in this directory should be compiled with -msse2. */ |
| 28 | |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 29 | |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 30 | #ifdef _MSC_VER |
| 31 | static inline void getcpuid(int info_type, int info[4]) { |
tomhudson@google.com | ea85494 | 2012-05-17 15:09:17 +0000 | [diff] [blame] | 32 | #if defined(_WIN64) |
| 33 | __cpuid(info, info_type); |
| 34 | #else |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 35 | __asm { |
| 36 | mov eax, [info_type] |
| 37 | cpuid |
| 38 | mov edi, [info] |
| 39 | mov [edi], eax |
| 40 | mov [edi+4], ebx |
| 41 | mov [edi+8], ecx |
| 42 | mov [edi+12], edx |
| 43 | } |
tomhudson@google.com | ea85494 | 2012-05-17 15:09:17 +0000 | [diff] [blame] | 44 | #endif |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 45 | } |
| 46 | #else |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 47 | #if defined(__x86_64__) |
| 48 | static inline void getcpuid(int info_type, int info[4]) { |
| 49 | asm volatile ( |
| 50 | "cpuid \n\t" |
| 51 | : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3]) |
| 52 | : "a"(info_type) |
| 53 | ); |
| 54 | } |
| 55 | #else |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 56 | static inline void getcpuid(int info_type, int info[4]) { |
| 57 | // We save and restore ebx, so this code can be compatible with -fPIC |
| 58 | asm volatile ( |
| 59 | "pushl %%ebx \n\t" |
| 60 | "cpuid \n\t" |
| 61 | "movl %%ebx, %1 \n\t" |
| 62 | "popl %%ebx \n\t" |
| 63 | : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3]) |
| 64 | : "a"(info_type) |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 65 | ); |
| 66 | } |
| 67 | #endif |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 68 | #endif |
| 69 | |
reed@google.com | 70d1be5 | 2012-07-16 16:07:42 +0000 | [diff] [blame] | 70 | #if defined(__x86_64__) || defined(_WIN64) || SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 71 | /* All x86_64 machines have SSE2, or we know it's supported at compile time, so don't even bother checking. */ |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 72 | static inline bool hasSSE2() { |
| 73 | return true; |
| 74 | } |
| 75 | #else |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 76 | |
| 77 | static inline bool hasSSE2() { |
| 78 | int cpu_info[4] = { 0 }; |
| 79 | getcpuid(1, cpu_info); |
| 80 | return (cpu_info[3] & (1<<26)) != 0; |
| 81 | } |
| 82 | #endif |
| 83 | |
reed@google.com | 70d1be5 | 2012-07-16 16:07:42 +0000 | [diff] [blame] | 84 | #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 |
| 85 | /* If we know SSSE3 is supported at compile time, don't even bother checking. */ |
| 86 | static inline bool hasSSSE3() { |
| 87 | return true; |
| 88 | } |
| 89 | #else |
| 90 | |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 91 | static inline bool hasSSSE3() { |
| 92 | int cpu_info[4] = { 0 }; |
| 93 | getcpuid(1, cpu_info); |
| 94 | return (cpu_info[2] & 0x200) != 0; |
| 95 | } |
reed@google.com | 70d1be5 | 2012-07-16 16:07:42 +0000 | [diff] [blame] | 96 | #endif |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 97 | |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 98 | static bool cachedHasSSE2() { |
| 99 | static bool gHasSSE2 = hasSSE2(); |
| 100 | return gHasSSE2; |
| 101 | } |
| 102 | |
tomhudson@google.com | 95ad155 | 2012-02-14 18:28:54 +0000 | [diff] [blame] | 103 | static bool cachedHasSSSE3() { |
| 104 | static bool gHasSSSE3 = hasSSSE3(); |
| 105 | return gHasSSSE3; |
| 106 | } |
| 107 | |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 108 | SK_CONF_DECLARE( bool, c_hqfilter_sse, "bitmap.filter.highQualitySSE", false, "Use SSE optimized version of high quality image filters"); |
| 109 | |
reed@google.com | fed04b3 | 2013-09-05 20:31:17 +0000 | [diff] [blame] | 110 | void SkBitmapProcState::platformConvolutionProcs(SkConvolutionProcs* procs) { |
humper@google.com | 138ebc3 | 2013-07-19 20:20:04 +0000 | [diff] [blame] | 111 | if (cachedHasSSE2()) { |
reed@google.com | fed04b3 | 2013-09-05 20:31:17 +0000 | [diff] [blame] | 112 | procs->fExtraHorizontalReads = 3; |
| 113 | procs->fConvolveVertically = &convolveVertically_SSE2; |
| 114 | procs->fConvolve4RowsHorizontally = &convolve4RowsHorizontally_SSE2; |
| 115 | procs->fConvolveHorizontally = &convolveHorizontally_SSE2; |
| 116 | procs->fApplySIMDPadding = &applySIMDPadding_SSE2; |
humper@google.com | 138ebc3 | 2013-07-19 20:20:04 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 120 | void SkBitmapProcState::platformProcs() { |
tomhudson@google.com | 06a7313 | 2012-02-22 18:30:43 +0000 | [diff] [blame] | 121 | if (cachedHasSSSE3()) { |
| 122 | if (fSampleProc32 == S32_opaque_D32_filter_DX) { |
| 123 | fSampleProc32 = S32_opaque_D32_filter_DX_SSSE3; |
| 124 | } else if (fSampleProc32 == S32_alpha_D32_filter_DX) { |
| 125 | fSampleProc32 = S32_alpha_D32_filter_DX_SSSE3; |
| 126 | } |
tomhudson@google.com | ae29b88 | 2012-03-06 14:59:04 +0000 | [diff] [blame] | 127 | |
| 128 | if (fSampleProc32 == S32_opaque_D32_filter_DXDY) { |
| 129 | fSampleProc32 = S32_opaque_D32_filter_DXDY_SSSE3; |
| 130 | } else if (fSampleProc32 == S32_alpha_D32_filter_DXDY) { |
| 131 | fSampleProc32 = S32_alpha_D32_filter_DXDY_SSSE3; |
| 132 | } |
tomhudson@google.com | 06a7313 | 2012-02-22 18:30:43 +0000 | [diff] [blame] | 133 | } else if (cachedHasSSE2()) { |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 134 | if (fSampleProc32 == S32_opaque_D32_filter_DX) { |
| 135 | fSampleProc32 = S32_opaque_D32_filter_DX_SSE2; |
senorblanco@chromium.org | f3f0bd7 | 2009-12-10 22:46:31 +0000 | [diff] [blame] | 136 | } else if (fSampleProc32 == S32_alpha_D32_filter_DX) { |
| 137 | fSampleProc32 = S32_alpha_D32_filter_DX_SSE2; |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 138 | } |
reed@google.com | 7866228 | 2012-07-24 13:53:23 +0000 | [diff] [blame] | 139 | |
| 140 | if (fSampleProc16 == S32_D16_filter_DX) { |
| 141 | fSampleProc16 = S32_D16_filter_DX_SSE2; |
| 142 | } |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 143 | } |
tomhudson@google.com | 06a7313 | 2012-02-22 18:30:43 +0000 | [diff] [blame] | 144 | |
| 145 | if (cachedHasSSSE3() || cachedHasSSE2()) { |
| 146 | if (fMatrixProc == ClampX_ClampY_filter_scale) { |
| 147 | fMatrixProc = ClampX_ClampY_filter_scale_SSE2; |
| 148 | } else if (fMatrixProc == ClampX_ClampY_nofilter_scale) { |
| 149 | fMatrixProc = ClampX_ClampY_nofilter_scale_SSE2; |
| 150 | } |
tomhudson@google.com | 5efaf26 | 2012-02-28 15:41:49 +0000 | [diff] [blame] | 151 | |
| 152 | if (fMatrixProc == ClampX_ClampY_filter_affine) { |
| 153 | fMatrixProc = ClampX_ClampY_filter_affine_SSE2; |
| 154 | } else if (fMatrixProc == ClampX_ClampY_nofilter_affine) { |
| 155 | fMatrixProc = ClampX_ClampY_nofilter_affine_SSE2; |
| 156 | } |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 157 | if (c_hqfilter_sse) { |
mtklein@google.com | 0dc546c | 2013-08-26 16:21:35 +0000 | [diff] [blame] | 158 | if (fShaderProc32 == highQualityFilter32) { |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 159 | fShaderProc32 = highQualityFilter_SSE2; |
| 160 | } |
humper@google.com | b088947 | 2013-07-09 21:37:14 +0000 | [diff] [blame] | 161 | } |
tomhudson@google.com | 06a7313 | 2012-02-22 18:30:43 +0000 | [diff] [blame] | 162 | } |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 163 | } |
| 164 | |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 165 | static SkBlitRow::Proc32 platform_32_procs[] = { |
| 166 | NULL, // S32_Opaque, |
| 167 | S32_Blend_BlitRow32_SSE2, // S32_Blend, |
| 168 | S32A_Opaque_BlitRow32_SSE2, // S32A_Opaque |
| 169 | S32A_Blend_BlitRow32_SSE2, // S32A_Blend, |
| 170 | }; |
| 171 | |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 172 | SkBlitRow::Proc SkBlitRow::PlatformProcs565(unsigned flags) { |
reed@google.com | 7329dc9 | 2012-07-27 13:29:59 +0000 | [diff] [blame] | 173 | return NULL; |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 174 | } |
| 175 | |
senorblanco@chromium.org | c385638 | 2010-12-13 15:27:20 +0000 | [diff] [blame] | 176 | SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() { |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 177 | if (cachedHasSSE2()) { |
senorblanco@chromium.org | c385638 | 2010-12-13 15:27:20 +0000 | [diff] [blame] | 178 | return Color32_SSE2; |
| 179 | } else { |
| 180 | return NULL; |
| 181 | } |
| 182 | } |
| 183 | |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 184 | SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) { |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 185 | if (cachedHasSSE2()) { |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 186 | return platform_32_procs[flags]; |
| 187 | } else { |
| 188 | return NULL; |
| 189 | } |
| 190 | } |
| 191 | |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 192 | |
reed@google.com | e901b4c | 2011-11-14 21:56:45 +0000 | [diff] [blame] | 193 | SkBlitMask::ColorProc SkBlitMask::PlatformColorProcs(SkBitmap::Config dstConfig, |
| 194 | SkMask::Format maskFormat, |
| 195 | SkColor color) { |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 196 | if (SkMask::kA8_Format != maskFormat) { |
| 197 | return NULL; |
| 198 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 199 | |
reed@google.com | e901b4c | 2011-11-14 21:56:45 +0000 | [diff] [blame] | 200 | ColorProc proc = NULL; |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 201 | if (cachedHasSSE2()) { |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 202 | switch (dstConfig) { |
| 203 | case SkBitmap::kARGB_8888_Config: |
reed@google.com | e6ea606 | 2011-07-07 19:12:50 +0000 | [diff] [blame] | 204 | // The SSE2 version is not (yet) faster for black, so we check |
| 205 | // for that. |
| 206 | if (SK_ColorBLACK != color) { |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 207 | proc = SkARGB32_A8_BlitMask_SSE2; |
reed@google.com | e6ea606 | 2011-07-07 19:12:50 +0000 | [diff] [blame] | 208 | } |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 209 | break; |
| 210 | default: |
reed@google.com | e901b4c | 2011-11-14 21:56:45 +0000 | [diff] [blame] | 211 | break; |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | return proc; |
| 215 | } |
| 216 | |
tomhudson@google.com | d6770e6 | 2012-02-14 16:01:15 +0000 | [diff] [blame] | 217 | SkBlitMask::BlitLCD16RowProc SkBlitMask::PlatformBlitRowProcs16(bool isOpaque) { |
| 218 | if (cachedHasSSE2()) { |
| 219 | if (isOpaque) { |
| 220 | return SkBlitLCD16OpaqueRow_SSE2; |
| 221 | } else { |
| 222 | return SkBlitLCD16Row_SSE2; |
| 223 | } |
| 224 | } else { |
| 225 | return NULL; |
| 226 | } |
| 227 | |
| 228 | } |
reed@google.com | e901b4c | 2011-11-14 21:56:45 +0000 | [diff] [blame] | 229 | SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkBitmap::Config dstConfig, |
reed@google.com | 1750bf1 | 2011-11-15 19:51:02 +0000 | [diff] [blame] | 230 | SkMask::Format maskFormat, |
| 231 | RowFlags flags) { |
reed@google.com | e901b4c | 2011-11-14 21:56:45 +0000 | [diff] [blame] | 232 | return NULL; |
| 233 | } |
| 234 | |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 235 | SkMemset16Proc SkMemset16GetPlatformProc() { |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 236 | if (cachedHasSSE2()) { |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 237 | return sk_memset16_SSE2; |
| 238 | } else { |
| 239 | return NULL; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | SkMemset32Proc SkMemset32GetPlatformProc() { |
reed@google.com | edb606c | 2011-10-18 13:56:50 +0000 | [diff] [blame] | 244 | if (cachedHasSSE2()) { |
senorblanco@chromium.org | 4e75355 | 2009-11-16 21:09:00 +0000 | [diff] [blame] | 245 | return sk_memset32_SSE2; |
| 246 | } else { |
| 247 | return NULL; |
| 248 | } |
| 249 | } |
tomhudson@google.com | 8dd90a9 | 2012-03-19 13:49:50 +0000 | [diff] [blame] | 250 | |
caryclark@google.com | 83ecdc3 | 2012-06-06 12:10:26 +0000 | [diff] [blame] | 251 | SkBlitRow::ColorRectProc PlatformColorRectProcFactory(); // suppress warning |
| 252 | |
tomhudson@google.com | 8dd90a9 | 2012-03-19 13:49:50 +0000 | [diff] [blame] | 253 | SkBlitRow::ColorRectProc PlatformColorRectProcFactory() { |
| 254 | if (cachedHasSSE2()) { |
| 255 | return ColorRect32_SSE2; |
| 256 | } else { |
| 257 | return NULL; |
| 258 | } |
| 259 | } |