diff options
author | mtklein <mtklein@chromium.org> | 2015-03-19 10:44:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-19 10:44:27 -0700 |
commit | bbecae0832996b72d1f6e7d39d2754651300d31e (patch) | |
tree | 3828d8ead74f089fb61d5aff3e4540e38306c20a /src/core | |
parent | 665b038b5745a9f5dc88b7ccfb39466a4c8750bf (diff) |
Sk2x
This adds an API, an SSE impl, a portable impl, and some tests for Sk2f/Sk2d/Sk2s.
BUG=skia:
Review URL: https://codereview.chromium.org/1025463002
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/Sk2x.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/core/Sk2x.h b/src/core/Sk2x.h new file mode 100644 index 0000000000..6b3fd86b27 --- /dev/null +++ b/src/core/Sk2x.h @@ -0,0 +1,72 @@ +/* + * 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 Sk2x_DEFINED +#define Sk2x_DEFINED + +#include "SkTypes.h" + +#define SK2X_PREAMBLE 1 + #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 + #include "../opts/Sk2x_sse.h" + #else + #include "../opts/Sk2x_none.h" + #endif +#undef SK2X_PREAMBLE + +template <typename T> class Sk2x; +typedef Sk2x<float> Sk2f; +typedef Sk2x<double> Sk2d; + +#if SK_SCALAR_IS_FLOAT + typedef Sk2f Sk2s; +#elif SK_SCALAR_IS_DOUBLE + typedef Sk2d Sk2s; +#endif + +// This API is meant to be manageably small, not comprehensive. +// Please talk to mtklein if you find yourself wanting more. +template <typename T> class Sk2x { +public: + Sk2x(); // Uninitialized; use Sk2x(0) for zero. + explicit Sk2x(T); // Same as Sk2x(T,T); + Sk2x(T, T); + + Sk2x(const Sk2x& o) { *this = o; } + Sk2x& operator=(const Sk2x&); + + // These assume no particular alignment. + static Sk2x Load(const T[2]); + void store(T[2]) const; + + Sk2x add(const Sk2x&) const; + Sk2x subtract(const Sk2x&) const; + Sk2x multiply(const Sk2x&) const; + + Sk2x rsqrt() const; // Approximate 1/this->sqrt(). + Sk2x sqrt() const; // this->multiply(this->rsqrt()) may be faster, but less precise. + + static Sk2x Min(const Sk2x&, const Sk2x&); + static Sk2x Max(const Sk2x&, const Sk2x&); + +private: +#define SK2X_PRIVATE 1 + #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 + #include "../opts/Sk2x_sse.h" + #else + #include "../opts/Sk2x_none.h" + #endif +#undef SK2X_PRIVATE +}; + +#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 + #include "../opts/Sk2x_sse.h" +#else + #include "../opts/Sk2x_none.h" +#endif + +#endif//Sk2x_DEFINED |