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

Side by Side Diff: src/opts/SkBlitRow_opts_arm_neon.cpp

Issue 1092433002: Rework SSE and NEON Color32 algorithms to be more correct and faster. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: support 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/SkBlitRow_opts_SSE2.cpp ('k') | no next file » | 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 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 #include "SkBlitRow_opts_arm_neon.h" 8 #include "SkBlitRow_opts_arm_neon.h"
9 9
10 #include "SkBlitMask.h" 10 #include "SkBlitMask.h"
(...skipping 1661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 SkPMColorAssert(c); 1672 SkPMColorAssert(c);
1673 SkASSERT(SkGetPackedA32(c) == 255); 1673 SkASSERT(SkGetPackedA32(c) == 255);
1674 1674
1675 unsigned dither = DITHER_VALUE(x); 1675 unsigned dither = DITHER_VALUE(x);
1676 *dst++ = SkDitherRGB32To565(c, dither); 1676 *dst++ = SkDitherRGB32To565(c, dither);
1677 DITHER_INC_X(x); 1677 DITHER_INC_X(x);
1678 } while (--count != 0); 1678 } while (--count != 0);
1679 } 1679 }
1680 } 1680 }
1681 1681
1682 void Color32_arm_neon(SkPMColor* dst, const SkPMColor* src, int count, 1682 #define SK_SUPPORT_LEGACY_COLOR32_MATHx
1683 SkPMColor color) { 1683
1684 if (count <= 0) { 1684 // Color32 and its SIMD specializations use the blend_256_round_alt algorithm
1685 return; 1685 // from tests/BlendTest.cpp. It's not quite perfect, but it's never wrong in th e
1686 // interesting edge cases, and it's quite a bit faster than blend_perfect.
1687 //
1688 // blend_256_round_alt is our currently blessed algorithm. Please use it or an analogous one.
1689 void Color32_arm_neon(SkPMColor* dst, const SkPMColor* src, int count, SkPMColor color) {
1690 switch (SkGetPackedA32(color)) {
1691 case 0: memmove(dst, src, count * sizeof(SkPMColor)); return;
1692 case 255: sk_memset32(dst, color, count); return;
1686 } 1693 }
1687 1694
1688 if (0 == color) { 1695 uint16x8_t colorHigh = vshll_n_u8((uint8x8_t)vdup_n_u32(color), 8);
1689 if (src != dst) { 1696 #ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
1690 memcpy(dst, src, count * sizeof(SkPMColor)); 1697 uint16x8_t colorAndRound = colorHigh;
1691 } 1698 #else // blend_256_round_alt, good
1692 return; 1699 uint16x8_t colorAndRound = vaddq_u16(colorHigh, vdupq_n_u16(128));
1693 }
1694
1695 unsigned colorA = SkGetPackedA32(color);
1696 if (255 == colorA) {
1697 sk_memset32(dst, color, count);
1698 return;
1699 }
1700
1701 unsigned scale = 256 - SkAlpha255To256(colorA);
1702
1703 if (count >= 8) {
1704 uint32x4_t vcolor;
1705 uint8x8_t vscale;
1706
1707 vcolor = vdupq_n_u32(color);
1708
1709 // scale numerical interval [0-255], so load as 8 bits
1710 vscale = vdup_n_u8(scale);
1711
1712 do {
1713 // load src color, 8 pixels, 4 64 bit registers
1714 // (and increment src).
1715 uint32x2x4_t vsrc;
1716 #if defined(SK_CPU_ARM32) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINO R__ > 6)))
1717 asm (
1718 "vld1.32 %h[vsrc], [%[src]]!"
1719 : [vsrc] "=w" (vsrc), [src] "+r" (src)
1720 : :
1721 );
1722 #else // 64bit targets and Clang
1723 vsrc.val[0] = vld1_u32(src);
1724 vsrc.val[1] = vld1_u32(src+2);
1725 vsrc.val[2] = vld1_u32(src+4);
1726 vsrc.val[3] = vld1_u32(src+6);
1727 src += 8;
1728 #endif 1700 #endif
1729 1701
1730 // multiply long by scale, 64 bits at a time, 1702 unsigned invA = 255 - SkGetPackedA32(color);
1731 // destination into a 128 bit register. 1703 #ifdef SK_SUPPORT_LEGACY_COLOR32_MATH // blend_256_plus1_trunc, busted
1732 uint16x8x4_t vtmp; 1704 uint8x8_t invA8 = vdup_n_u8(invA);
1733 vtmp.val[0] = vmull_u8(vreinterpret_u8_u32(vsrc.val[0]), vscale); 1705 #else // blend_256_round_alt, good
1734 vtmp.val[1] = vmull_u8(vreinterpret_u8_u32(vsrc.val[1]), vscale); 1706 SkASSERT(invA + (invA >> 7) < 256); // This next part only works if alpha i s not 0.
1735 vtmp.val[2] = vmull_u8(vreinterpret_u8_u32(vsrc.val[2]), vscale); 1707 uint8x8_t invA8 = vdup_n_u8(invA + (invA >> 7));
1736 vtmp.val[3] = vmull_u8(vreinterpret_u8_u32(vsrc.val[3]), vscale); 1708 #endif
1737 1709
1738 // shift the 128 bit registers, containing the 16 1710 // Does the core work of blending color onto 4 pixels, returning the resulti ng 4 pixels.
1739 // bit scaled values back to 8 bits, narrowing the 1711 auto kernel = [&](const uint32x4_t& src4) -> uint32x4_t {
1740 // results to 64 bit registers. 1712 uint16x8_t lo = vmull_u8(vget_low_u8( (uint8x16_t)src4), invA8),
1741 uint8x16x2_t vres; 1713 hi = vmull_u8(vget_high_u8((uint8x16_t)src4), invA8);
1742 vres.val[0] = vcombine_u8( 1714 return (uint32x4_t)
1743 vshrn_n_u16(vtmp.val[0], 8), 1715 vcombine_u8(vaddhn_u16(colorAndRound, lo), vaddhn_u16(colorAndRound, hi));
1744 vshrn_n_u16(vtmp.val[1], 8)); 1716 };
1745 vres.val[1] = vcombine_u8(
1746 vshrn_n_u16(vtmp.val[2], 8),
1747 vshrn_n_u16(vtmp.val[3], 8));
1748 1717
1749 // adding back the color, using 128 bit registers. 1718 while (count >= 8) {
1750 uint32x4x2_t vdst; 1719 uint32x4_t dst0 = kernel(vld1q_u32(src+0)),
1751 vdst.val[0] = vreinterpretq_u32_u8(vres.val[0] + 1720 dst4 = kernel(vld1q_u32(src+4));
1752 vreinterpretq_u8_u32(vcolor)); 1721 vst1q_u32(dst+0, dst0);
1753 vdst.val[1] = vreinterpretq_u32_u8(vres.val[1] + 1722 vst1q_u32(dst+4, dst4);
1754 vreinterpretq_u8_u32(vcolor)); 1723 src += 8;
1755 1724 dst += 8;
1756 // store back the 8 calculated pixels (2 128 bit 1725 count -= 8;
1757 // registers), and increment dst.
1758 #if defined(SK_CPU_ARM32) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINO R__ > 6)))
1759 asm (
1760 "vst1.32 %h[vdst], [%[dst]]!"
1761 : [dst] "+r" (dst)
1762 : [vdst] "w" (vdst)
1763 : "memory"
1764 );
1765 #else // 64bit targets and Clang
1766 vst1q_u32(dst, vdst.val[0]);
1767 vst1q_u32(dst+4, vdst.val[1]);
1768 dst += 8;
1769 #endif
1770 count -= 8;
1771
1772 } while (count >= 8);
1773 } 1726 }
1774 1727 if (count >= 4) {
1775 while (count > 0) { 1728 vst1q_u32(dst, kernel(vld1q_u32(src)));
1776 *dst = color + SkAlphaMulQ(*src, scale); 1729 src += 4;
1777 src += 1; 1730 dst += 4;
1778 dst += 1; 1731 count -= 4;
1779 count--; 1732 }
1733 if (count >= 2) {
1734 uint32x2_t src2 = vld1_u32(src);
1735 vst1_u32(dst, vget_low_u32(kernel(vcombine_u32(src2, src2))));
1736 src += 2;
1737 dst += 2;
1738 count -= 2;
1739 }
1740 if (count >= 1) {
1741 vst1q_lane_u32(dst, kernel(vdupq_n_u32(*src)), 0);
1780 } 1742 }
1781 } 1743 }
1782 1744
1783 /////////////////////////////////////////////////////////////////////////////// 1745 ///////////////////////////////////////////////////////////////////////////////
1784 1746
1785 const SkBlitRow::Proc16 sk_blitrow_platform_565_procs_arm_neon[] = { 1747 const SkBlitRow::Proc16 sk_blitrow_platform_565_procs_arm_neon[] = {
1786 // no dither 1748 // no dither
1787 S32_D565_Opaque_neon, 1749 S32_D565_Opaque_neon,
1788 S32_D565_Blend_neon, 1750 S32_D565_Blend_neon,
1789 S32A_D565_Opaque_neon, 1751 S32A_D565_Opaque_neon,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 S32A_Opaque_BlitRow32_neon_src_alpha, // S32A_Opaque, 1786 S32A_Opaque_BlitRow32_neon_src_alpha, // S32A_Opaque,
1825 #else 1787 #else
1826 S32A_Opaque_BlitRow32_neon, // S32A_Opaque, 1788 S32A_Opaque_BlitRow32_neon, // S32A_Opaque,
1827 #endif 1789 #endif
1828 #ifdef SK_CPU_ARM32 1790 #ifdef SK_CPU_ARM32
1829 S32A_Blend_BlitRow32_neon // S32A_Blend 1791 S32A_Blend_BlitRow32_neon // S32A_Blend
1830 #else 1792 #else
1831 NULL 1793 NULL
1832 #endif 1794 #endif
1833 }; 1795 };
OLDNEW
« no previous file with comments | « src/opts/SkBlitRow_opts_SSE2.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698