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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
Index: src/opts/SkPMFloat_neon.h
diff --git a/src/opts/SkPMFloat_neon.h b/src/opts/SkPMFloat_neon.h
index 4e099f91ecce2593719c211a32bf408bcac2bf1b..aeb1a70a5b86bb9376db37e3f9e8d6799dcfc5ea 100644
--- a/src/opts/SkPMFloat_neon.h
+++ b/src/opts/SkPMFloat_neon.h
@@ -9,18 +9,28 @@ namespace { // See SkPMFloat.h
static_assert(SK_A32_SHIFT == 24, "This file assumes little-endian.");
-inline SkPMFloat::SkPMFloat(SkPMColor c) {
+template <int kBias>
+inline SkPMFloat<kBias>::SkPMFloat(SkPMColor c) {
SkPMColorAssert(c);
uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c);
uint16x8_t fix8_16 = vmovl_u8(fix8);
uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16));
- fVec = vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255));
+ fVec = vcvtq_f32_u32(fix8_32);
+ if (kBias == 1) {
+ fVec = vmulq_f32(fVec, vdupq_n_f32(1.0f/255));
+ }
SkASSERT(this->isValid());
}
-inline SkPMColor SkPMFloat::round() const {
+template <int kBias>
+inline SkPMColor SkPMFloat<kBias>::round() const {
// vcvt_u32_f32 truncates, so we round manually by adding a half before converting.
- float32x4_t rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255));
+ float32x4_t rounded;
+ if (kBias == 1) {
+ rounded = vmlaq_f32(vdupq_n_f32(0.5f), fVec, vdupq_n_f32(255));
+ } else {
+ rounded = vaddq_f32(vdupq_n_f32(0.5f), fVec);
+ }
uint32x4_t fix8_32 = vcvtq_u32_f32(rounded);
uint16x4_t fix8_16 = vqmovn_u32(fix8_32);
uint8x8_t fix8 = vqmovn_u16(vcombine_u16(fix8_16, vdup_n_u16(0)));
@@ -29,11 +39,13 @@ inline SkPMColor SkPMFloat::round() const {
return c;
}
-inline Sk4f SkPMFloat::alphas() const {
+template <int kBias>
+inline Sk4f SkPMFloat<kBias>::alphas() const {
return vdupq_lane_f32(vget_high_f32(fVec), 1); // Duplicate high lane of high half i.e. lane 3.
}
-inline SkPMFloat SkPMFloat::FromOpaqueColor(SkColor c) {
+template <int kBias>
+inline SkPMFloat<kBias> SkPMFloat<kBias>::FromOpaqueColor(SkColor c) {
SkASSERT(SkColorGetA(c) == 0xFF);
uint8x8_t fix8 = (uint8x8_t)vdup_n_u32(c);
#if defined(SK_PMCOLOR_IS_RGBA)
@@ -42,7 +54,11 @@ inline SkPMFloat SkPMFloat::FromOpaqueColor(SkColor c) {
uint16x8_t fix8_16 = vmovl_u8(fix8);
uint32x4_t fix8_32 = vmovl_u16(vget_low_u16(fix8_16));
- SkPMFloat pmf = Sk4f(vmulq_f32(vcvtq_f32_u32(fix8_32), vdupq_n_f32(1.0f/255)));
+ float32x4_t floats = vcvtq_f32_u32(fix8_32);
+ if (kBias == 1) {
+ floats = vmulq_f32(floats, vdupq_n_f32(1.0f/255));
+ }
+ SkPMFloat pmf = Sk4f(floats);
SkASSERT(pmf.isValid());
return pmf;
}

Powered by Google App Engine
This is Rietveld 408576698