Optimize RGB16 blitV functions with NEON for ARM platform.
authoryang.zhang <yang.zhang@linaro.org>
Wed, 15 Jul 2015 14:07:30 +0000 (07:07 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 15 Jul 2015 14:07:30 +0000 (07:07 -0700)
Here are some performance resultsi on Nexus 9:
SkRGB16BlitterBlitV_neon:
+--------+-----------+
|height  |  C/NEON   |
+--------+-----------+
|1       | 0.765230  |
+--------+-----------+
|8       | 1.273330  |
+--------+-----------+
|18      | 1.441462  |
+--------+-----------+
|32      | 1.627798  |
+--------+-----------+
|76      | 1.683131  |
+--------+-----------+
|85      | 1.679456  |
+--------+-----------+
|120     | 1.721311  |
+--------+-----------+
|128     | 1.725482  |
+--------+-----------+
|512     | 1.784117  |
+--------+-----------+

BUG=skia:

Review URL: https://codereview.chromium.org/1213723002

AUTHORS
src/core/SkBlitter_RGB16.cpp
src/opts/SkBlitMask_opts_arm_neon.cpp

diff --git a/AUTHORS b/AUTHORS
index 76e2f44..9d8e661 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -36,3 +36,4 @@ Steve Singer <steve@ssinger.info>
 The Chromium Authors <*@chromium.org>
 Thiago Fransosi Farina <thiago.farina@gmail.com>
 Jose Mayol <jei.mayol@gmail.com>
+Linaro <*@linaro.org>
index 6724b12..8caf908 100644 (file)
@@ -22,6 +22,11 @@ extern void blitmask_d565_opaque_mips(int width, int height, uint16_t* device,
 
 #if SK_ARM_NEON_IS_ALWAYS && defined(SK_CPU_LENDIAN)
     #include <arm_neon.h>
+extern void SkRGB16BlitterBlitV_neon(uint16_t* device,
+                                     int height,
+                                     size_t deviceRB,
+                                     unsigned scale,
+                                     uint32_t src32);
 #else
     // if we don't have neon, then our black blitter is worth the extra code
     #define USE_BLACK_BLITTER
@@ -484,11 +489,15 @@ void SkRGB16_Opaque_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
     unsigned scale5 = SkAlpha255To256(alpha) >> 3;
     uint32_t src32 =  fExpandedRaw16 * scale5;
     scale5 = 32 - scale5;
+#if SK_ARM_NEON_IS_ALWAYS && defined(SK_CPU_LENDIAN)
+    SkRGB16BlitterBlitV_neon(device, height, deviceRB, scale5, src32);
+#else
     do {
         uint32_t dst32 = SkExpand_rgb_16(*device) * scale5;
         *device = SkCompact_rgb_16((src32 + dst32) >> 5);
         device = (uint16_t*)((char*)device + deviceRB);
     } while (--height != 0);
+#endif
 }
 
 void SkRGB16_Opaque_Blitter::blitRect(int x, int y, int width, int height) {
@@ -659,11 +668,15 @@ void SkRGB16_Blitter::blitV(int x, int y, int height, SkAlpha alpha) {
     unsigned scale5 = SkAlpha255To256(alpha) * fScale >> (8 + 3);
     uint32_t src32 =  fExpandedRaw16 * scale5;
     scale5 = 32 - scale5;
+#if SK_ARM_NEON_IS_ALWAYS && defined(SK_CPU_LENDIAN)
+    SkRGB16BlitterBlitV_neon(device, height, deviceRB, scale5, src32);
+#else
     do {
         uint32_t dst32 = SkExpand_rgb_16(*device) * scale5;
         *device = SkCompact_rgb_16((src32 + dst32) >> 5);
         device = (uint16_t*)((char*)device + deviceRB);
     } while (--height != 0);
+#endif
 }
 
 void SkRGB16_Blitter::blitRect(int x, int y, int width, int height) {
index aa59a92..3361a5d 100644 (file)
@@ -258,3 +258,77 @@ void SkBlitLCD16Row_neon(SkPMColor dst[], const uint16_t src[],
         dst[i] = SkBlendLCD16(colA, colR, colG, colB, dst[i], src[i]);
     }
 }
+
+#define LOAD_LANE_16(reg, n) \
+    reg = vld1q_lane_u16(device, reg, n); \
+    device = (uint16_t*)((char*)device + deviceRB);
+
+#define STORE_LANE_16(reg, n) \
+    vst1_lane_u16(dst, reg, n); \
+    dst = (uint16_t*)((char*)dst + deviceRB);
+
+void SkRGB16BlitterBlitV_neon(uint16_t* device,
+                              int height,
+                              size_t deviceRB,
+                              unsigned scale,
+                              uint32_t src32) {
+    if (height >= 8)
+    {
+        uint16_t* dst = device;
+
+        // prepare constants
+        uint16x8_t vdev = vdupq_n_u16(0);
+        uint16x8_t vmaskq_g16 = vdupq_n_u16(SK_G16_MASK_IN_PLACE);
+        uint16x8_t vmaskq_ng16 = vdupq_n_u16(~SK_G16_MASK_IN_PLACE);
+        uint32x4_t vsrc32 = vdupq_n_u32(src32);
+        uint32x4_t vscale5 = vdupq_n_u32((uint32_t)scale);
+
+        while (height >= 8){
+            LOAD_LANE_16(vdev, 0)
+            LOAD_LANE_16(vdev, 1)
+            LOAD_LANE_16(vdev, 2)
+            LOAD_LANE_16(vdev, 3)
+            LOAD_LANE_16(vdev, 4)
+            LOAD_LANE_16(vdev, 5)
+            LOAD_LANE_16(vdev, 6)
+            LOAD_LANE_16(vdev, 7)
+
+            // Expand_rgb_16
+            uint16x8x2_t vdst = vzipq_u16((vdev & vmaskq_ng16), (vdev & vmaskq_g16));
+            uint32x4_t vdst32_lo = vmulq_u32(vreinterpretq_u32_u16(vdst.val[0]), vscale5);
+            uint32x4_t vdst32_hi = vmulq_u32(vreinterpretq_u32_u16(vdst.val[1]), vscale5);
+
+            // Compact_rgb_16
+            vdst32_lo = vaddq_u32(vdst32_lo, vsrc32);
+            vdst32_hi = vaddq_u32(vdst32_hi, vsrc32);
+            vdst32_lo = vshrq_n_u32(vdst32_lo, 5);
+            vdst32_hi = vshrq_n_u32(vdst32_hi, 5);
+
+            uint16x4_t vtmp_lo = vmovn_u32(vdst32_lo) & vget_low_u16(vmaskq_ng16);
+            uint16x4_t vtmp_hi = vshrn_n_u32(vdst32_lo, 16) & vget_low_u16(vmaskq_g16);
+            uint16x4_t vdst16_lo = vorr_u16(vtmp_lo, vtmp_hi);
+            vtmp_lo = vmovn_u32(vdst32_hi) & vget_low_u16(vmaskq_ng16);
+            vtmp_hi = vshrn_n_u32(vdst32_hi, 16) & vget_low_u16(vmaskq_g16);
+            uint16x4_t vdst16_hi = vorr_u16(vtmp_lo, vtmp_hi);
+
+            STORE_LANE_16(vdst16_lo, 0)
+            STORE_LANE_16(vdst16_lo, 1)
+            STORE_LANE_16(vdst16_lo, 2)
+            STORE_LANE_16(vdst16_lo, 3)
+            STORE_LANE_16(vdst16_hi, 0)
+            STORE_LANE_16(vdst16_hi, 1)
+            STORE_LANE_16(vdst16_hi, 2)
+            STORE_LANE_16(vdst16_hi, 3)
+            height -= 8;
+        }
+    }
+    while (height != 0){
+        uint32_t dst32 = SkExpand_rgb_16(*device) * scale;
+        *device = SkCompact_rgb_16((src32 + dst32) >> 5);
+        device = (uint16_t*)((char*)device + deviceRB);
+        height--;
+    }
+}
+
+#undef LOAD_LANE_16
+#undef STORE_LANE_16