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

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

Issue 1308903003: Templatize SkPMFloat to support both 1 and 255 biases. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: pump the loops for Android Created 5 years, 3 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
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 namespace { // See SkPMFloat.h 8 namespace { // See SkPMFloat.h
9 9
10 static_assert(SK_A32_SHIFT == 24, "This file assumes little-endian."); 10 static_assert(SK_A32_SHIFT == 24, "This file assumes little-endian.");
11 11
12 inline SkPMFloat::SkPMFloat(SkPMColor c) { 12 template <int kBias>
13 inline SkPMFloat<kBias>::SkPMFloat(SkPMColor c) {
13 SkPMColorAssert(c); 14 SkPMColorAssert(c);
14 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); 15 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c);
15 uint16x8_t fix8_16 = vmovl_u8(fix8); 16 uint16x8_t fix8_16 = vmovl_u8(fix8);
16 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); 17 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16));
17 fVec = vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255)); 18 fVec = vcvtq_f32_u32(fix8_32);
19 if (kBias == 1) {
20 fVec = vmulq_f32(fVec, vdupq_n_f32(1.0f/255));
21 }
18 SkASSERT(this->isValid()); 22 SkASSERT(this->isValid());
19 } 23 }
20 24
21 inline SkPMColor SkPMFloat::round() const { 25 template <int kBias>
26 inline SkPMColor SkPMFloat<kBias>::round() const {
22 // vcvt_u32_f32 truncates, so we round manually by adding a half before conv erting. 27 // vcvt_u32_f32 truncates, so we round manually by adding a half before conv erting.
23 float32x4_t rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255)); 28 float32x4_t rounded;
29 if (kBias == 1) {
30 rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255));
31 } else {
32 rounded = vaddq_f32(vdupq_n_f32(0.5f), fVec);
33 }
24 uint32x4_t fix8_32 = vcvtq_u32_f32(rounded); 34 uint32x4_t fix8_32 = vcvtq_u32_f32(rounded);
25 uint16x4_t fix8_16 = vqmovn_u32(fix8_32); 35 uint16x4_t fix8_16 = vqmovn_u32(fix8_32);
26 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0))); 36 uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0)));
27 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0); 37 SkPMColor c = vget_lane_u32((uint32x2_t)fix8, 0);
28 SkPMColorAssert(c); 38 SkPMColorAssert(c);
29 return c; 39 return c;
30 } 40 }
31 41
32 inline Sk4f SkPMFloat::alphas() const { 42 template <int kBias>
43 inline Sk4f SkPMFloat<kBias>::alphas() const {
33 return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of hi gh half i.e. lane 3. 44 return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of hi gh half i.e. lane 3.
34 } 45 }
35 46
36 inline SkPMFloat SkPMFloat::FromOpaqueColor(SkColor c) { 47 template <int kBias>
48 inline SkPMFloat<kBias> SkPMFloat<kBias>::FromOpaqueColor(SkColor c) {
37 SkASSERT(SkColorGetA(c) == 0xFF); 49 SkASSERT(SkColorGetA(c) == 0xFF);
38 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c); 50 uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c);
39 #if defined(SK_PMCOLOR_IS_RGBA) 51 #if defined(SK_PMCOLOR_IS_RGBA)
40 fix8 = vtbl1_u8(fix8, vcreate_u8(0x0300010203000102ULL)); // 03 00 01 02, 2 x, i.e. swap R&B. 52 fix8 = vtbl1_u8(fix8, vcreate_u8(0x0300010203000102ULL)); // 03 00 01 02, 2 x, i.e. swap R&B.
41 #endif 53 #endif
42 uint16x8_t fix8_16 = vmovl_u8(fix8); 54 uint16x8_t fix8_16 = vmovl_u8(fix8);
43 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16)); 55 uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16));
44 56
45 SkPMFloat pmf = Sk4f(vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255) )); 57 float32x4_t floats = vcvtq_f32_u32(fix8_32);
58 if (kBias == 1) {
59 floats = vmulq_f32(floats, vdupq_n_f32(1.0f/255));
60 }
61 SkPMFloat pmf = Sk4f(floats);
46 SkASSERT(pmf.isValid()); 62 SkASSERT(pmf.isValid());
47 return pmf; 63 return pmf;
48 } 64 }
49 65
50 } // namespace 66 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698