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

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

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

Powered by Google App Engine
This is Rietveld 408576698