1 /* 2 * Copyright 2015 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkCpu.h" 9 #include "SkHalf.h" 10 #include "SkOnce.h" 11 #include "SkOpts.h" 12 13 #if defined(SK_ARM_HAS_NEON) 14 #if defined(SK_ARM_HAS_CRC32) 15 #define SK_OPTS_NS neon_and_crc32 16 #else 17 #define SK_OPTS_NS neon 18 #endif 19 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 20 #define SK_OPTS_NS avx2 21 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX 22 #define SK_OPTS_NS avx 23 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42 24 #define SK_OPTS_NS sse42 25 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41 26 #define SK_OPTS_NS sse41 27 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 28 #define SK_OPTS_NS ssse3 29 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE3 30 #define SK_OPTS_NS sse3 31 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 32 #define SK_OPTS_NS sse2 33 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1 34 #define SK_OPTS_NS sse 35 #else 36 #define SK_OPTS_NS portable 37 #endif 38 39 #include "SkBlitMask_opts.h" 40 #include "SkBlitRow_opts.h" 41 #include "SkChecksum_opts.h" 42 #include "SkMorphologyImageFilter_opts.h" 43 #include "SkSwizzler_opts.h" 44 #include "SkUtils_opts.h" 45 #include "SkXfermode_opts.h" 46 47 namespace SkOpts { 48 // Define default function pointer values here... 49 // If our global compile options are set high enough, these defaults might even be 50 // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defaults. 51 // They'll still get a chance to be replaced with even better ones, e.g. using SSE4.1. 52 #define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name 53 DEFINE_DEFAULT(create_xfermode); 54 55 DEFINE_DEFAULT(dilate_x); 56 DEFINE_DEFAULT(dilate_y); 57 DEFINE_DEFAULT( erode_x); 58 DEFINE_DEFAULT( erode_y); 59 60 DEFINE_DEFAULT(blit_mask_d32_a8); 61 62 DEFINE_DEFAULT(blit_row_color32); 63 DEFINE_DEFAULT(blit_row_s32a_opaque); 64 65 DEFINE_DEFAULT(RGBA_to_BGRA); 66 DEFINE_DEFAULT(RGBA_to_rgbA); 67 DEFINE_DEFAULT(RGBA_to_bgrA); 68 DEFINE_DEFAULT(RGB_to_RGB1); 69 DEFINE_DEFAULT(RGB_to_BGR1); 70 DEFINE_DEFAULT(gray_to_RGB1); 71 DEFINE_DEFAULT(grayA_to_RGBA); 72 DEFINE_DEFAULT(grayA_to_rgbA); 73 DEFINE_DEFAULT(inverted_CMYK_to_RGB1); 74 DEFINE_DEFAULT(inverted_CMYK_to_BGR1); 75 76 DEFINE_DEFAULT(memset16); 77 DEFINE_DEFAULT(memset32); 78 DEFINE_DEFAULT(memset64); 79 80 DEFINE_DEFAULT(hash_fn); 81 82 #undef DEFINE_DEFAULT 83 84 // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp. 85 void Init_ssse3(); 86 void Init_sse41(); 87 void Init_sse42(); 88 void Init_avx(); 89 void Init_crc32(); 90 91 static void init() { 92 #if !defined(SK_BUILD_NO_OPTS) 93 #if defined(SK_CPU_X86) 94 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSSE3 95 if (SkCpu::Supports(SkCpu::SSSE3)) { Init_ssse3(); } 96 #endif 97 98 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSE41 99 if (SkCpu::Supports(SkCpu::SSE41)) { Init_sse41(); } 100 #endif 101 102 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSE42 103 if (SkCpu::Supports(SkCpu::SSE42)) { Init_sse42(); } 104 #endif 105 106 #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_AVX 107 if (SkCpu::Supports(SkCpu::AVX )) { Init_avx(); } 108 #endif 109 110 #elif defined(SK_CPU_ARM64) 111 if (SkCpu::Supports(SkCpu::CRC32)) { Init_crc32(); } 112 113 #endif 114 #endif 115 } 116 117 void Init() { 118 static SkOnce once; 119 once(init); 120 } 121 } // namespace SkOpts 122