Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: src/opts/Sk2x_neon.h

Issue 1020963002: Specialize Sk2d for ARM64 (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Avoid use of vset[q]_lane, instead intializing vectors directly. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkUtilsArm.h ('k') | src/opts/Sk4x_neon.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 // It is important _not_ to put header guards here. 8 // It is important _not_ to put header guards here.
9 // This file will be intentionally included three times. 9 // This file will be intentionally included three times.
10 10
11 #include "SkTypes.h" // Keep this before any #ifdef for skbug.com/3362 11 #include "SkTypes.h" // Keep this before any #ifdef for skbug.com/3362
12 12
13 #if defined(SK2X_PREAMBLE) 13 #if defined(SK2X_PREAMBLE)
14 #include <arm_neon.h> 14 #include <arm_neon.h>
15 #include <math.h> 15 #include <math.h>
16 template <typename T> struct SkScalarToSIMD; 16 template <typename T> struct SkScalarToSIMD;
17 template <> struct SkScalarToSIMD< float> { typedef float32x2_t Type; }; 17 template <> struct SkScalarToSIMD< float> { typedef float32x2_t Type; };
18 template <> struct SkScalarToSIMD<double> { typedef double Type[2]; }; 18 #if defined(SK_CPU_ARM64)
19 template <> struct SkScalarToSIMD<double> { typedef float64x2_t Type; };
20 #else
21 template <> struct SkScalarToSIMD<double> { typedef double Type[2]; };
22 #endif
19 23
20 24
21 #elif defined(SK2X_PRIVATE) 25 #elif defined(SK2X_PRIVATE)
22 typename SkScalarToSIMD<T>::Type fVec; 26 typename SkScalarToSIMD<T>::Type fVec;
23 /*implicit*/ Sk2x(const typename SkScalarToSIMD<T>::Type vec) { fVec = vec; } 27 /*implicit*/ Sk2x(const typename SkScalarToSIMD<T>::Type vec) { fVec = vec; }
24 28
25 #else 29 #else
26 30
27 #define M(...) template <> inline __VA_ARGS__ Sk2x<float>:: 31 #define M(...) template <> inline __VA_ARGS__ Sk2x<float>::
28 32
29 M() Sk2x() {} 33 M() Sk2x() {}
30 M() Sk2x(float val) { fVec = vdup_n_f32(val); } 34 M() Sk2x(float val) { fVec = vdup_n_f32(val); }
31 M() Sk2x(float a, float b) { 35 M() Sk2x(float a, float b) { fVec = (float32x2_t) { a, b }; }
32 fVec = vset_lane_f32(a, fVec, 0);
33 fVec = vset_lane_f32(b, fVec, 1);
34 }
35 M(Sk2f&) operator=(const Sk2f& o) { fVec = o.fVec; return *this; } 36 M(Sk2f&) operator=(const Sk2f& o) { fVec = o.fVec; return *this; }
36 37
37 M(Sk2f) Load(const float vals[2]) { return vld1_f32(vals); } 38 M(Sk2f) Load(const float vals[2]) { return vld1_f32(vals); }
38 M(void) store(float vals[2]) const { vst1_f32(vals, fVec); } 39 M(void) store(float vals[2]) const { vst1_f32(vals, fVec); }
39 40
40 M(Sk2f) add(const Sk2f& o) const { return vadd_f32(fVec, o.fVec); } 41 M(Sk2f) add(const Sk2f& o) const { return vadd_f32(fVec, o.fVec); }
41 M(Sk2f) subtract(const Sk2f& o) const { return vsub_f32(fVec, o.fVec); } 42 M(Sk2f) subtract(const Sk2f& o) const { return vsub_f32(fVec, o.fVec); }
42 M(Sk2f) multiply(const Sk2f& o) const { return vmul_f32(fVec, o.fVec); } 43 M(Sk2f) multiply(const Sk2f& o) const { return vmul_f32(fVec, o.fVec); }
43 44
44 M(Sk2f) Min(const Sk2f& a, const Sk2f& b) { return vmin_f32(a.fVec, b.fVec); } 45 M(Sk2f) Min(const Sk2f& a, const Sk2f& b) { return vmin_f32(a.fVec, b.fVec); }
45 M(Sk2f) Max(const Sk2f& a, const Sk2f& b) { return vmax_f32(a.fVec, b.fVec); } 46 M(Sk2f) Max(const Sk2f& a, const Sk2f& b) { return vmax_f32(a.fVec, b.fVec); }
46 47
47 M(Sk2f) rsqrt() const { 48 M(Sk2f) rsqrt() const {
48 float32x2_t est0 = vrsqrte_f32(fVec), 49 float32x2_t est0 = vrsqrte_f32(fVec),
49 est1 = vmul_f32(vrsqrts_f32(fVec, vmul_f32(est0, est0)), est0); 50 est1 = vmul_f32(vrsqrts_f32(fVec, vmul_f32(est0, est0)), est0);
50 return est1; 51 return est1;
51 } 52 }
52 M(Sk2f) sqrt() const { 53 M(Sk2f) sqrt() const {
53 float32x2_t est1 = this->rsqrt().fVec, 54 float32x2_t est1 = this->rsqrt().fVec,
54 // An extra step of Newton's method to refine the estimate of 1/sqrt(this). 55 // An extra step of Newton's method to refine the estimate of 1/sqrt(this).
55 est2 = vmul_f32(vrsqrts_f32(fVec, vmul_f32(est1, est1)), est1); 56 est2 = vmul_f32(vrsqrts_f32(fVec, vmul_f32(est1, est1)), est1);
56 return vmul_f32(fVec, est2); 57 return vmul_f32(fVec, est2);
57 } 58 }
58 59
59 #undef M 60 #undef M
60 61
61 #define M(...) template <> inline __VA_ARGS__ Sk2x<double>:: 62 #define M(...) template <> inline __VA_ARGS__ Sk2x<double>::
62 63
63 // TODO: #ifdef SK_CPU_ARM64 use float64x2_t for Sk2d. 64 #if defined(SK_CPU_ARM64)
65 M() Sk2x() {}
66 M() Sk2x(double val) { fVec = vdupq_n_f64(val); }
67 M() Sk2x(double a, double b) { fVec = (float64x2_t) { a, b }; }
68 M(Sk2d&) operator=(const Sk2d& o) { fVec = o.fVec; return *this; }
64 69
65 M() Sk2x() {} 70 M(Sk2d) Load(const double vals[2]) { return vld1q_f64(vals); }
66 M() Sk2x(double val) { fVec[0] = fVec[1] = val; } 71 M(void) store(double vals[2]) const { vst1q_f64(vals, fVec); }
67 M() Sk2x(double a, double b) { fVec[0] = a; fVec[1] = b; }
68 M(Sk2d&) operator=(const Sk2d& o) {
69 fVec[0] = o.fVec[0];
70 fVec[1] = o.fVec[1];
71 return *this;
72 }
73 72
74 M(Sk2d) Load(const double vals[2]) { return Sk2d(vals[0], vals[1]); } 73 M(Sk2d) add(const Sk2d& o) const { return vaddq_f64(fVec, o.fVec); }
75 M(void) store(double vals[2]) const { vals[0] = fVec[0]; vals[1] = fVec[1]; } 74 M(Sk2d) subtract(const Sk2d& o) const { return vsubq_f64(fVec, o.fVec); }
75 M(Sk2d) multiply(const Sk2d& o) const { return vmulq_f64(fVec, o.fVec); }
76 76
77 M(Sk2d) add(const Sk2d& o) const { return Sk2d(fVec[0] + o.fVec[0], fVec[1] + o.fVec[1]); } 77 M(Sk2d) Min(const Sk2d& a, const Sk2d& b) { return vminq_f64(a.fVec, b.fVec) ; }
78 M(Sk2d) subtract(const Sk2d& o) const { return Sk2d(fVec[0] - o.fVec[0], fVec[1] - o.fVec[1]); } 78 M(Sk2d) Max(const Sk2d& a, const Sk2d& b) { return vmaxq_f64(a.fVec, b.fVec) ; }
79 M(Sk2d) multiply(const Sk2d& o) const { return Sk2d(fVec[0] * o.fVec[0], fVec[1] * o.fVec[1]); }
80 79
81 M(Sk2d) Min(const Sk2d& a, const Sk2d& b) { 80 M(Sk2d) rsqrt() const {
82 return Sk2d(SkTMin(a.fVec[0], b.fVec[0]), SkTMin(a.fVec[1], b.fVec[1])); 81 float64x2_t est0 = vrsqrteq_f64(fVec),
83 } 82 est1 = vmulq_f64(vrsqrtsq_f64(fVec, vmulq_f64(est0, est0)), est0);
84 M(Sk2d) Max(const Sk2d& a, const Sk2d& b) { 83 return est1;
85 return Sk2d(SkTMax(a.fVec[0], b.fVec[0]), SkTMax(a.fVec[1], b.fVec[1])); 84 }
86 } 85 M(Sk2d) sqrt() const {
86 float64x2_t est1 = this->rsqrt().fVec,
87 // Two extra steps of Newton's method to refine the estimate of 1/sqrt(t his).
88 est2 = vmulq_f64(vrsqrtsq_f64(fVec, vmulq_f64(est1, est1)), est1),
89 est3 = vmulq_f64(vrsqrtsq_f64(fVec, vmulq_f64(est2, est2)), est2);
90 return vmulq_f64(fVec, est3);
91 }
87 92
88 M(Sk2d) rsqrt() const { return Sk2d(1.0/::sqrt(fVec[0]), 1.0/::sqrt(fVec[1])); } 93 #else // Scalar implementation for 32-bit chips, which don't have float64x2_t.
89 M(Sk2d) sqrt() const { return Sk2d( ::sqrt(fVec[0]), ::sqrt(fVec[1])); } 94 M() Sk2x() {}
95 M() Sk2x(double val) { fVec[0] = fVec[1] = val; }
96 M() Sk2x(double a, double b) { fVec[0] = a; fVec[1] = b; }
97 M(Sk2d&) operator=(const Sk2d& o) {
98 fVec[0] = o.fVec[0];
99 fVec[1] = o.fVec[1];
100 return *this;
101 }
102
103 M(Sk2d) Load(const double vals[2]) { return Sk2d(vals[0], vals[1]); }
104 M(void) store(double vals[2]) const { vals[0] = fVec[0]; vals[1] = fVec[1]; }
105
106 M(Sk2d) add(const Sk2d& o) const { return Sk2d(fVec[0] + o.fVec[0], fVe c[1] + o.fVec[1]); }
107 M(Sk2d) subtract(const Sk2d& o) const { return Sk2d(fVec[0] - o.fVec[0], fVe c[1] - o.fVec[1]); }
108 M(Sk2d) multiply(const Sk2d& o) const { return Sk2d(fVec[0] * o.fVec[0], fVe c[1] * o.fVec[1]); }
109
110 M(Sk2d) Min(const Sk2d& a, const Sk2d& b) {
111 return Sk2d(SkTMin(a.fVec[0], b.fVec[0]), SkTMin(a.fVec[1], b.fVec[1]));
112 }
113 M(Sk2d) Max(const Sk2d& a, const Sk2d& b) {
114 return Sk2d(SkTMax(a.fVec[0], b.fVec[0]), SkTMax(a.fVec[1], b.fVec[1]));
115 }
116
117 M(Sk2d) rsqrt() const { return Sk2d(1.0/::sqrt(fVec[0]), 1.0/::sqrt(fVec[1]) ); }
118 M(Sk2d) sqrt() const { return Sk2d( ::sqrt(fVec[0]), ::sqrt(fVec[1]) ); }
119 #endif
90 120
91 #undef M 121 #undef M
92 122
93 #endif 123 #endif
OLDNEW
« no previous file with comments | « src/core/SkUtilsArm.h ('k') | src/opts/Sk4x_neon.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698