diff options
author | Mike Klein <mtklein@chromium.org> | 2017-09-15 14:02:08 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-09-15 18:25:34 +0000 |
commit | 7c55726156a6b2bda10035188be0077848bd3ede (patch) | |
tree | 3944c8628aedd7181637c64d384fc98a09277028 /src | |
parent | cb4d58766668b003fea67798027fc25d84acd059 (diff) |
centralize SI, Ctx, and load_and_inc()
We've got independent definitions of SI, LazyCtx/Ctx, and load_and_inc()
in _stages.cpp and _lowp.cpp. It's a good time to centralize them,
taking _stages.cpp's SI and load_and_inc(), and _lowp's Ctx.
SI and load_and_inc() are uninterestingly different. But using _lowp's
Ctx will let us get its prettier typed stage definitions into
_stages.cpp, but that is not not done here.
This is a pure refactor with no generated code changes.
Change-Id: I53260b0fdc71a77bf9e3ed6f3df3a2a4cbd2392b
Reviewed-on: https://skia-review.googlesource.com/47181
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/jumper/SkJumper_misc.h | 10 | ||||
-rw-r--r-- | src/jumper/SkJumper_stages.cpp | 46 | ||||
-rw-r--r-- | src/jumper/SkJumper_stages_lowp.cpp | 31 |
3 files changed, 30 insertions, 57 deletions
diff --git a/src/jumper/SkJumper_misc.h b/src/jumper/SkJumper_misc.h index 09758fba7d..8f7ebb56ac 100644 --- a/src/jumper/SkJumper_misc.h +++ b/src/jumper/SkJumper_misc.h @@ -63,19 +63,21 @@ SI void* load_and_inc(void**& program) { #endif } -// LazyCtx doesn't do anything unless you call operator T*(), encapsulating the logic -// from above that stages without a context pointer are represented by just 1 void*. -struct LazyCtx { +// Lazily resolved on first cast. Does nothing if cast to Ctx::None. +struct Ctx { + using None = decltype(nullptr); + void* ptr; void**& program; - explicit LazyCtx(void**& p) : ptr(nullptr), program(p) {} + explicit Ctx(void**& p) : ptr(nullptr), program(p) {} template <typename T> operator T*() { if (!ptr) { ptr = load_and_inc(program); } return (T*)ptr; } + operator None() { return nullptr; } }; #endif//SkJumper_misc_DEFINED diff --git a/src/jumper/SkJumper_stages.cpp b/src/jumper/SkJumper_stages.cpp index 18fff43bd4..c5b4cd58e1 100644 --- a/src/jumper/SkJumper_stages.cpp +++ b/src/jumper/SkJumper_stages.cpp @@ -95,31 +95,31 @@ extern "C" void WRAP(start_pipeline)(size_t x, size_t y, size_t xlimit, size_t y } #if defined(__i386__) || defined(_M_IX86) || defined(__arm__) - #define STAGE(name) \ - SI void name##_k(LazyCtx ctx, size_t x, size_t y, size_t tail, \ - F& r, F& g, F& b, F& a, F& dr, F& dg, F& db, F& da); \ - extern "C" void WRAP(name)(Params* params, void** program, \ - F r, F g, F b, F a) { \ - LazyCtx ctx(program); \ - name##_k(ctx,params->x,params->y,params->tail, r,g,b,a, \ - params->dr, params->dg, params->db, params->da); \ - auto next = (Stage*)load_and_inc(program); \ - next(params,program, r,g,b,a); \ - } \ - SI void name##_k(LazyCtx ctx, size_t x, size_t y, size_t tail, \ + #define STAGE(name) \ + SI void name##_k(Ctx ctx, size_t x, size_t y, size_t tail, \ + F& r, F& g, F& b, F& a, F& dr, F& dg, F& db, F& da); \ + extern "C" void WRAP(name)(Params* params, void** program, \ + F r, F g, F b, F a) { \ + Ctx ctx(program); \ + name##_k(ctx,params->x,params->y,params->tail, r,g,b,a, \ + params->dr, params->dg, params->db, params->da); \ + auto next = (Stage*)load_and_inc(program); \ + next(params,program, r,g,b,a); \ + } \ + SI void name##_k(Ctx ctx, size_t x, size_t y, size_t tail, \ F& r, F& g, F& b, F& a, F& dr, F& dg, F& db, F& da) #else - #define STAGE(name) \ - SI void name##_k(LazyCtx ctx, size_t x, size_t y, size_t tail, \ - F& r, F& g, F& b, F& a, F& dr, F& dg, F& db, F& da); \ - extern "C" void WRAP(name)(size_t tail, void** program, size_t x, size_t y, \ - F r, F g, F b, F a, F dr, F dg, F db, F da) { \ - LazyCtx ctx(program); \ - name##_k(ctx,x,y,tail, r,g,b,a, dr,dg,db,da); \ - auto next = (Stage*)load_and_inc(program); \ - next(tail,program,x,y, r,g,b,a, dr,dg,db,da); \ - } \ - SI void name##_k(LazyCtx ctx, size_t x, size_t y, size_t tail, \ + #define STAGE(name) \ + SI void name##_k(Ctx ctx, size_t x, size_t y, size_t tail, \ + F& r, F& g, F& b, F& a, F& dr, F& dg, F& db, F& da); \ + extern "C" void WRAP(name)(size_t tail, void** program, size_t x, size_t y, \ + F r, F g, F b, F a, F dr, F dg, F db, F da) { \ + Ctx ctx(program); \ + name##_k(ctx,x,y,tail, r,g,b,a, dr,dg,db,da); \ + auto next = (Stage*)load_and_inc(program); \ + next(tail,program,x,y, r,g,b,a, dr,dg,db,da); \ + } \ + SI void name##_k(Ctx ctx, size_t x, size_t y, size_t tail, \ F& r, F& g, F& b, F& a, F& dr, F& dg, F& db, F& da) #endif diff --git a/src/jumper/SkJumper_stages_lowp.cpp b/src/jumper/SkJumper_stages_lowp.cpp index f6bc6ff545..4761320c7c 100644 --- a/src/jumper/SkJumper_stages_lowp.cpp +++ b/src/jumper/SkJumper_stages_lowp.cpp @@ -10,11 +10,10 @@ // backend with stage definitions that can be shared by x86 and ARM. #include "SkJumper.h" +#include "SkJumper_misc.h" #if defined(__clang__) // This file is empty when not compiled by Clang. -#define SI static inline - #if defined(__ARM_NEON) #include <arm_neon.h> #if defined(__arm__) @@ -58,17 +57,6 @@ using Stage = void (ABI*)(size_t tail, void** program, size_t x, size_t y, U16 r, U16 g, U16 b, U16 a, U16 dr, U16 dg, U16 db, U16 da); -SI void* load_and_inc(void**& program) { -#if defined(__x86_64__) - // If program is in %rsi, this is a single-instruction *program++. - void* rax; - asm("lodsq" : "=a"(rax), "+S"(program)); - return rax; -#else - return *program++; -#endif -} - MAYBE_MSABI ABI extern "C" void WRAP(start_pipeline)(const size_t x0, const size_t y0, @@ -90,23 +78,6 @@ ABI extern "C" void WRAP(start_pipeline)(const size_t x0, ABI extern "C" void WRAP(just_return)(size_t,void**,size_t,size_t, U16,U16,U16,U16, U16,U16,U16,U16) {} -// Lazily resolved on first cast. Does nothing if cast to Ctx::None. -struct Ctx { - using None = decltype(nullptr); - - void* ptr; - void**& program; - - explicit Ctx(void**& p) : ptr(nullptr), program(p) {} - - template <typename T> - operator T*() { - if (!ptr) { ptr = load_and_inc(program); } - return (T*)ptr; - } - operator None() { return nullptr; } -}; - #define STAGE(name, ...) \ SI void name##_k(__VA_ARGS__, size_t x, size_t y, size_t tail, \ U16& r, U16& g, U16& b, U16& a, \ |