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

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

Issue 1048593002: Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: This is actually faster Created 5 years, 8 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/opts/SkPMFloat_SSSE3.h ('k') | src/opts/SkPMFloat_none.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 inline SkPMFloat& SkPMFloat::operator=(const SkPMFloat& that) {
9 fColors = that.fColors;
10 return *this;
11 }
12
13 // For SkPMFloat(SkPMFColor), we widen our 8 bit components (fix8) to 8-bit comp onents in 16 bits 8 // For SkPMFloat(SkPMFColor), we widen our 8 bit components (fix8) to 8-bit comp onents in 16 bits
14 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver t those to floats. 9 // (fix8_16), then widen those to 8-bit-in-32-bits (fix8_32), and finally conver t those to floats.
15 10
16 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit, 11 // get() and clamped() do the opposite, working from floats to 8-bit-in-32-bit,
17 // to 8-bit-in-16-bit, back down to 8-bit components. 12 // to 8-bit-in-16-bit, back down to 8-bit components.
18 // clamped() uses vqmovn to clamp while narrowing instead of just narrowing with vmovn. 13 // clamped() uses vqmovn to clamp while narrowing instead of just narrowing with vmovn.
19 14
20 inline SkPMFloat::SkPMFloat(SkPMColor c) { 15 inline SkPMFloat::SkPMFloat(SkPMColor c) {
21 SkPMColorAssert(c); 16 SkPMColorAssert(c);
22 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); 17 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c);
23 uint16x8_t fix8_16 = vmovl_u8(fix8); 18 uint16x8_t fix8_16 = vmovl_u8(fix8);
24 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); 19 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16));
25 fColors = vcvtq_f32_u32(fix8_32); 20 fColors = vcvtq_f32_u32(fix8_32);
26 SkASSERT(this->isValid()); 21 SkASSERT(this->isValid());
27 } 22 }
28 23
29 inline SkPMColor SkPMFloat::trunc() const { 24 inline SkPMColor SkPMFloat::trunc() const {
30 uint32x4_t fix8_32 = vcvtq_u32_f32(fColors); // vcvtq_u32_f32 truncates 25 uint32x4_t fix8_32 = vcvtq_u32_f32(fColors.vec()); // vcvtq_u32_f32 trunc ates
31 uint16x4_t fix8_16 = vmovn_u32(fix8_32); 26 uint16x4_t fix8_16 = vmovn_u32(fix8_32);
32 uint8x8_t fix8 = vmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); 27 uint8x8_t fix8 = vmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0)));
33 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); 28 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0);
34 SkPMColorAssert(c); 29 SkPMColorAssert(c);
35 return c; 30 return c;
36 } 31 }
37 32
38 inline SkPMColor SkPMFloat::get() const { 33 inline SkPMColor SkPMFloat::get() const {
39 SkASSERT(this->isValid()); 34 SkASSERT(this->isValid());
40 return SkPMFloat(Sk4f(0.5f) + *this).trunc(); 35 return SkPMFloat(Sk4s(0.5f) + *this).trunc();
41 } 36 }
42 37
43 inline SkPMColor SkPMFloat::clamped() const { 38 inline SkPMColor SkPMFloat::clamped() const {
44 float32x4_t add_half = vaddq_f32(fColors, vdupq_n_f32(0.5f)); 39 float32x4_t add_half = vaddq_f32(fColors.vec(), vdupq_n_f32(0.5f));
45 uint32x4_t fix8_32 = vcvtq_u32_f32(add_half); // vcvtq_u32_f32 truncates, so round manually 40 uint32x4_t fix8_32 = vcvtq_u32_f32(add_half); // vcvtq_u32_f32 truncates, so round manually
46 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); 41 uint16x4_t fix8_16 = vqmovn_u32(fix8_32);
47 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); 42 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0)));
48 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); 43 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0);
49 SkPMColorAssert(c); 44 SkPMColorAssert(c);
50 return c; 45 return c;
51 } 46 }
52 47
53 // TODO: we should be able to beat these loops on all three methods. 48 // TODO: we should be able to beat these loops on all three methods.
54 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4], 49 inline void SkPMFloat::From4PMColors(const SkPMColor colors[4],
(...skipping 14 matching lines...) Expand all
69 } 64 }
70 65
71 inline void SkPMFloat::ClampTo4PMColors( 66 inline void SkPMFloat::ClampTo4PMColors(
72 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo at& d, 67 const SkPMFloat& a, const SkPMFloat& b, const SkPMFloat&c, const SkPMFlo at& d,
73 SkPMColor colors[4]) { 68 SkPMColor colors[4]) {
74 colors[0] = a.clamped(); 69 colors[0] = a.clamped();
75 colors[1] = b.clamped(); 70 colors[1] = b.clamped();
76 colors[2] = c.clamped(); 71 colors[2] = c.clamped();
77 colors[3] = d.clamped(); 72 colors[3] = d.clamped();
78 } 73 }
OLDNEW
« no previous file with comments | « src/opts/SkPMFloat_SSSE3.h ('k') | src/opts/SkPMFloat_none.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698