1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "include/private/SkHalf.h"
9cb93a386Sopenharmony_ci#include "include/private/SkOnce.h"
10cb93a386Sopenharmony_ci#include "src/core/SkCpu.h"
11cb93a386Sopenharmony_ci#include "src/core/SkOpts.h"
12cb93a386Sopenharmony_ci
13cb93a386Sopenharmony_ci#if defined(SK_ARM_HAS_NEON)
14cb93a386Sopenharmony_ci    #if defined(SK_ARM_HAS_CRC32)
15cb93a386Sopenharmony_ci        #define SK_OPTS_NS neon_and_crc32
16cb93a386Sopenharmony_ci    #else
17cb93a386Sopenharmony_ci        #define SK_OPTS_NS neon
18cb93a386Sopenharmony_ci    #endif
19cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SKX
20cb93a386Sopenharmony_ci    #define SK_OPTS_NS skx
21cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2
22cb93a386Sopenharmony_ci    #define SK_OPTS_NS avx2
23cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX
24cb93a386Sopenharmony_ci    #define SK_OPTS_NS avx
25cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE42
26cb93a386Sopenharmony_ci    #define SK_OPTS_NS sse42
27cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE41
28cb93a386Sopenharmony_ci    #define SK_OPTS_NS sse41
29cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
30cb93a386Sopenharmony_ci    #define SK_OPTS_NS ssse3
31cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE3
32cb93a386Sopenharmony_ci    #define SK_OPTS_NS sse3
33cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
34cb93a386Sopenharmony_ci    #define SK_OPTS_NS sse2
35cb93a386Sopenharmony_ci#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
36cb93a386Sopenharmony_ci    #define SK_OPTS_NS sse
37cb93a386Sopenharmony_ci#else
38cb93a386Sopenharmony_ci    #define SK_OPTS_NS portable
39cb93a386Sopenharmony_ci#endif
40cb93a386Sopenharmony_ci
41cb93a386Sopenharmony_ci#include "src/core/SkCubicSolver.h"
42cb93a386Sopenharmony_ci#include "src/opts/SkBitmapProcState_opts.h"
43cb93a386Sopenharmony_ci#include "src/opts/SkBlitMask_opts.h"
44cb93a386Sopenharmony_ci#include "src/opts/SkBlitRow_opts.h"
45cb93a386Sopenharmony_ci#include "src/opts/SkChecksum_opts.h"
46cb93a386Sopenharmony_ci#include "src/opts/SkRasterPipeline_opts.h"
47cb93a386Sopenharmony_ci#include "src/opts/SkSwizzler_opts.h"
48cb93a386Sopenharmony_ci#include "src/opts/SkUtils_opts.h"
49cb93a386Sopenharmony_ci#include "src/opts/SkVM_opts.h"
50cb93a386Sopenharmony_ci#include "src/opts/SkXfermode_opts.h"
51cb93a386Sopenharmony_ci
52cb93a386Sopenharmony_cinamespace SkOpts {
53cb93a386Sopenharmony_ci    // Define default function pointer values here...
54cb93a386Sopenharmony_ci    // If our global compile options are set high enough, these defaults might even be
55cb93a386Sopenharmony_ci    // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defaults.
56cb93a386Sopenharmony_ci    // They'll still get a chance to be replaced with even better ones, e.g. using SSE4.1.
57cb93a386Sopenharmony_ci#define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name
58cb93a386Sopenharmony_ci    DEFINE_DEFAULT(create_xfermode);
59cb93a386Sopenharmony_ci
60cb93a386Sopenharmony_ci    DEFINE_DEFAULT(blit_mask_d32_a8);
61cb93a386Sopenharmony_ci
62cb93a386Sopenharmony_ci    DEFINE_DEFAULT(blit_row_color32);
63cb93a386Sopenharmony_ci    DEFINE_DEFAULT(blit_row_s32a_opaque);
64cb93a386Sopenharmony_ci
65cb93a386Sopenharmony_ci    DEFINE_DEFAULT(RGBA_to_BGRA);
66cb93a386Sopenharmony_ci    DEFINE_DEFAULT(RGBA_to_rgbA);
67cb93a386Sopenharmony_ci    DEFINE_DEFAULT(RGBA_to_bgrA);
68cb93a386Sopenharmony_ci    DEFINE_DEFAULT(RGB_to_RGB1);
69cb93a386Sopenharmony_ci    DEFINE_DEFAULT(RGB_to_BGR1);
70cb93a386Sopenharmony_ci    DEFINE_DEFAULT(gray_to_RGB1);
71cb93a386Sopenharmony_ci    DEFINE_DEFAULT(grayA_to_RGBA);
72cb93a386Sopenharmony_ci    DEFINE_DEFAULT(grayA_to_rgbA);
73cb93a386Sopenharmony_ci    DEFINE_DEFAULT(inverted_CMYK_to_RGB1);
74cb93a386Sopenharmony_ci    DEFINE_DEFAULT(inverted_CMYK_to_BGR1);
75cb93a386Sopenharmony_ci
76cb93a386Sopenharmony_ci    DEFINE_DEFAULT(memset16);
77cb93a386Sopenharmony_ci    DEFINE_DEFAULT(memset32);
78cb93a386Sopenharmony_ci    DEFINE_DEFAULT(memset64);
79cb93a386Sopenharmony_ci
80cb93a386Sopenharmony_ci    DEFINE_DEFAULT(rect_memset16);
81cb93a386Sopenharmony_ci    DEFINE_DEFAULT(rect_memset32);
82cb93a386Sopenharmony_ci    DEFINE_DEFAULT(rect_memset64);
83cb93a386Sopenharmony_ci
84cb93a386Sopenharmony_ci    DEFINE_DEFAULT(cubic_solver);
85cb93a386Sopenharmony_ci
86cb93a386Sopenharmony_ci    DEFINE_DEFAULT(hash_fn);
87cb93a386Sopenharmony_ci
88cb93a386Sopenharmony_ci    DEFINE_DEFAULT(S32_alpha_D32_filter_DX);
89cb93a386Sopenharmony_ci    DEFINE_DEFAULT(S32_alpha_D32_filter_DXDY);
90cb93a386Sopenharmony_ci
91cb93a386Sopenharmony_ci    DEFINE_DEFAULT(interpret_skvm);
92cb93a386Sopenharmony_ci#undef DEFINE_DEFAULT
93cb93a386Sopenharmony_ci
94cb93a386Sopenharmony_ci#define M(st) (StageFn)SK_OPTS_NS::st,
95cb93a386Sopenharmony_ci    StageFn stages_highp[] = { SK_RASTER_PIPELINE_STAGES(M) };
96cb93a386Sopenharmony_ci    StageFn just_return_highp = (StageFn)SK_OPTS_NS::just_return;
97cb93a386Sopenharmony_ci    void (*start_pipeline_highp)(size_t,size_t,size_t,size_t,void**)
98cb93a386Sopenharmony_ci        = SK_OPTS_NS::start_pipeline;
99cb93a386Sopenharmony_ci#undef M
100cb93a386Sopenharmony_ci
101cb93a386Sopenharmony_ci#define M(st) (StageFn)SK_OPTS_NS::lowp::st,
102cb93a386Sopenharmony_ci    StageFn stages_lowp[] = { SK_RASTER_PIPELINE_STAGES(M) };
103cb93a386Sopenharmony_ci    StageFn just_return_lowp = (StageFn)SK_OPTS_NS::lowp::just_return;
104cb93a386Sopenharmony_ci    void (*start_pipeline_lowp)(size_t,size_t,size_t,size_t,void**)
105cb93a386Sopenharmony_ci        = SK_OPTS_NS::lowp::start_pipeline;
106cb93a386Sopenharmony_ci#undef M
107cb93a386Sopenharmony_ci
108cb93a386Sopenharmony_ci    // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp.
109cb93a386Sopenharmony_ci/*
110cb93a386Sopenharmony_ci    void Init_ssse3();
111cb93a386Sopenharmony_ci    void Init_sse42();
112cb93a386Sopenharmony_ci    void Init_avx();
113cb93a386Sopenharmony_ci    void Init_hsw();
114cb93a386Sopenharmony_ci    void Init_skx();
115cb93a386Sopenharmony_ci    void Init_erms();
116cb93a386Sopenharmony_ci    void Init_crc32();
117cb93a386Sopenharmony_ci*/
118cb93a386Sopenharmony_ci
119cb93a386Sopenharmony_ci    static void init() {
120cb93a386Sopenharmony_ci/*
121cb93a386Sopenharmony_ci    #if defined(SK_CPU_X86)
122cb93a386Sopenharmony_ci        #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSSE3
123cb93a386Sopenharmony_ci            if (SkCpu::Supports(SkCpu::SSSE3)) { Init_ssse3(); }
124cb93a386Sopenharmony_ci        #endif
125cb93a386Sopenharmony_ci
126cb93a386Sopenharmony_ci        #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSE42
127cb93a386Sopenharmony_ci            if (SkCpu::Supports(SkCpu::SSE42)) { Init_sse42(); }
128cb93a386Sopenharmony_ci        #endif
129cb93a386Sopenharmony_ci
130cb93a386Sopenharmony_ci        #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_AVX
131cb93a386Sopenharmony_ci            if (SkCpu::Supports(SkCpu::AVX)) { Init_avx();   }
132cb93a386Sopenharmony_ci            if (SkCpu::Supports(SkCpu::HSW)) { Init_hsw();   }
133cb93a386Sopenharmony_ci        #endif
134cb93a386Sopenharmony_ci
135cb93a386Sopenharmony_ci        #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SKX
136cb93a386Sopenharmony_ci            if (SkCpu::Supports(SkCpu::SKX)) { Init_skx(); }
137cb93a386Sopenharmony_ci        #endif
138cb93a386Sopenharmony_ci
139cb93a386Sopenharmony_ci        if (SkCpu::Supports(SkCpu::ERMS)) { Init_erms(); }
140cb93a386Sopenharmony_ci
141cb93a386Sopenharmony_ci    #elif defined(SK_CPU_ARM64)
142cb93a386Sopenharmony_ci        if (SkCpu::Supports(SkCpu::CRC32)) { Init_crc32(); }
143cb93a386Sopenharmony_ci
144cb93a386Sopenharmony_ci    #endif
145cb93a386Sopenharmony_ci*/
146cb93a386Sopenharmony_ci    }
147cb93a386Sopenharmony_ci
148cb93a386Sopenharmony_ci    void Init() {
149cb93a386Sopenharmony_ci        static SkOnce once;
150cb93a386Sopenharmony_ci        once(init);
151cb93a386Sopenharmony_ci    }
152cb93a386Sopenharmony_ci}  // namespace SkOpts
153