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

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

Issue 1245673002: 565 support for SIMD xfermodes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix typo Created 5 years, 5 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/core/Sk4pxXfermode.h ('k') | src/opts/Sk4px_SSE2.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 namespace { // See Sk4px.h 8 namespace { // See Sk4px.h
9 9
10 inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b((uint8x16_t)vdupq_n_ u32(px)); } 10 inline Sk4px Sk4px::DupPMColor(SkPMColor px) { return Sk16b((uint8x16_t)vdupq_n_ u32(px)); }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 inline Sk4px Sk4px::zeroColors() const { 83 inline Sk4px Sk4px::zeroColors() const {
84 return Sk16b(vandq_u8(this->fVec, (uint8x16_t)vdupq_n_u32(0xFF << SK_A32_SHI FT))); 84 return Sk16b(vandq_u8(this->fVec, (uint8x16_t)vdupq_n_u32(0xFF << SK_A32_SHI FT)));
85 } 85 }
86 86
87 inline Sk4px Sk4px::zeroAlphas() const { 87 inline Sk4px Sk4px::zeroAlphas() const {
88 // vbic(a,b) == a & ~b 88 // vbic(a,b) == a & ~b
89 return Sk16b(vbicq_u8(this->fVec, (uint8x16_t)vdupq_n_u32(0xFF << SK_A32_SHI FT))); 89 return Sk16b(vbicq_u8(this->fVec, (uint8x16_t)vdupq_n_u32(0xFF << SK_A32_SHI FT)));
90 } 90 }
91 91
92 static inline uint8x16_t widen_to_8888(uint16x4_t v) {
93 // RGB565 format: |R....|G.....|B....|
94 // Bit: 16 11 5 0
95
96 // First get each pixel into its own 32-bit lane.
97 // v == rgb3 rgb2 rgb1 rgb0
98 // spread == 0000 rgb3 0000 rgb2 0000 rgb1 0000 rgb0
99 uint32x4_t spread = vmovl_u16(v);
100
101 // Get each color independently, still in 565 precison but down at bit 0.
102 auto r5 = vshrq_n_u32(spread, 11),
103 g6 = vandq_u32(vdupq_n_u32(63), vshrq_n_u32(spread, 5)),
104 b5 = vandq_u32(vdupq_n_u32(31), spread);
105
106 // Scale 565 precision up to 8-bit each, filling low 323 bits with high bits of each component.
107 auto r8 = vorrq_u32(vshlq_n_u32(r5, 3), vshrq_n_u32(r5, 2)),
108 g8 = vorrq_u32(vshlq_n_u32(g6, 2), vshrq_n_u32(g6, 4)),
109 b8 = vorrq_u32(vshlq_n_u32(b5, 3), vshrq_n_u32(b5, 2));
110
111 // Now put all the 8-bit components into SkPMColor order.
112 return (uint8x16_t)vorrq_u32(vshlq_n_u32(r8, SK_R32_SHIFT), // TODO: one s hift is zero...
113 vorrq_u32(vshlq_n_u32(g8, SK_G32_SHIFT),
114 vorrq_u32(vshlq_n_u32(b8, SK_B32_SHIFT),
115 vdupq_n_u32(0xFF << SK_A32_SHIFT))));
116 }
117
118 static inline uint16x4_t narrow_to_565(uint8x16_t w8x16) {
119 uint32x4_t w = (uint32x4_t)w8x16;
120
121 // Extract out top RGB 565 bits of each pixel, with no rounding.
122 auto r5 = vandq_u32(vdupq_n_u32(31), vshrq_n_u32(w, SK_R32_SHIFT + 3)),
123 g6 = vandq_u32(vdupq_n_u32(63), vshrq_n_u32(w, SK_G32_SHIFT + 2)),
124 b5 = vandq_u32(vdupq_n_u32(31), vshrq_n_u32(w, SK_B32_SHIFT + 3));
125
126 // Now put the bits in place in the low 16-bits of each 32-bit lane.
127 auto spread = vorrq_u32(vshlq_n_u32(r5, 11),
128 vorrq_u32(vshlq_n_u32(g6, 5),
129 b5));
130
131 // Pack the low 16-bits of our 128-bit register down into a 64-bit register.
132 // spread == 0000 rgb3 0000 rgb2 0000 rgb1 0000 rgb0
133 // v == rgb3 rgb2 rgb1 rgb0
134 auto v = vmovn_u32(spread);
135 return v;
136 }
137
138
139 inline Sk4px Sk4px::Load4(const SkPMColor16 src[4]) {
140 return Sk16b(widen_to_8888(vld1_u16(src)));
141 }
142 inline Sk4px Sk4px::Load2(const SkPMColor16 src[2]) {
143 auto src2 = ((uint32_t)src[0] )
144 | ((uint32_t)src[1] << 16);
145 return Sk16b(widen_to_8888(vcreate_u16(src2)));
146 }
147 inline Sk4px Sk4px::Load1(const SkPMColor16 src[1]) {
148 return Sk16b(widen_to_8888(vcreate_u16(src[0])));
149 }
150
151 inline void Sk4px::store4(SkPMColor16 dst[4]) const {
152 vst1_u16(dst, narrow_to_565(this->fVec));
153 }
154 inline void Sk4px::store2(SkPMColor16 dst[2]) const {
155 auto v = narrow_to_565(this->fVec);
156 dst[0] = vget_lane_u16(v, 0);
157 dst[1] = vget_lane_u16(v, 1);
158 }
159 inline void Sk4px::store1(SkPMColor16 dst[1]) const {
160 dst[0] = vget_lane_u16(narrow_to_565(this->fVec), 0);
161 }
162
92 } // namespace 163 } // namespace
93 164
OLDNEW
« no previous file with comments | « src/core/Sk4pxXfermode.h ('k') | src/opts/Sk4px_SSE2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698