• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2009 Motorola
2  *
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6 
7 #include "SkBitmapProcState.h"
8 #include "SkPerspIter.h"
9 #include "SkShader.h"
10 #include "SkUtilsArm.h"
11 #include "SkBitmapProcState_utils.h"
12 
13 #include <arm_neon.h>
14 
15 extern const SkBitmapProcState::MatrixProc ClampX_ClampY_Procs_neon[];
16 extern const SkBitmapProcState::MatrixProc RepeatX_RepeatY_Procs_neon[];
17 
18 static void decal_nofilter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
19 static void decal_filter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
20 
21 // TILEX_PROCF(fx, max)    SkClampMax((fx) >> 16, max)
sbpsm_clamp_tile8(int32x4_t low,int32x4_t high,unsigned max)22 static inline int16x8_t sbpsm_clamp_tile8(int32x4_t low, int32x4_t high, unsigned max) {
23     int16x8_t res;
24 
25     // get the hi 16s of all those 32s
26     res = vuzpq_s16(vreinterpretq_s16_s32(low), vreinterpretq_s16_s32(high)).val[1];
27 
28     // clamp
29     res = vmaxq_s16(res, vdupq_n_s16(0));
30     res = vminq_s16(res, vdupq_n_s16(max));
31 
32     return res;
33 }
34 
35 // TILEX_PROCF(fx, max)    SkClampMax((fx) >> 16, max)
sbpsm_clamp_tile4(int32x4_t f,unsigned max)36 static inline int32x4_t sbpsm_clamp_tile4(int32x4_t f, unsigned max) {
37     int32x4_t res;
38 
39     // get the hi 16s of all those 32s
40     res = vshrq_n_s32(f, 16);
41 
42     // clamp
43     res = vmaxq_s32(res, vdupq_n_s32(0));
44     res = vminq_s32(res, vdupq_n_s32(max));
45 
46     return res;
47 }
48 
49 // EXTRACT_LOW_BITS(fy, max)         (((fy) >> 12) & 0xF)
sbpsm_clamp_tile4_low_bits(int32x4_t fx)50 static inline int32x4_t sbpsm_clamp_tile4_low_bits(int32x4_t fx) {
51     int32x4_t ret;
52 
53     ret = vshrq_n_s32(fx, 12);
54 
55     /* We don't need the mask below because the caller will
56      * overwrite the non-masked bits
57      */
58     //ret = vandq_s32(ret, vdupq_n_s32(0xF));
59 
60     return ret;
61 }
62 
63 // TILEX_PROCF(fx, max) (((fx)&0xFFFF)*((max)+1)>> 16)
sbpsm_repeat_tile8(int32x4_t low,int32x4_t high,unsigned max)64 static inline int16x8_t sbpsm_repeat_tile8(int32x4_t low, int32x4_t high, unsigned max) {
65     uint16x8_t res;
66     uint32x4_t tmpl, tmph;
67 
68     // get the lower 16 bits
69     res = vuzpq_u16(vreinterpretq_u16_s32(low), vreinterpretq_u16_s32(high)).val[0];
70 
71     // bare multiplication, not SkFixedMul
72     tmpl = vmull_u16(vget_low_u16(res), vdup_n_u16(max+1));
73     tmph = vmull_u16(vget_high_u16(res), vdup_n_u16(max+1));
74 
75     // extraction of the 16 upper bits
76     res = vuzpq_u16(vreinterpretq_u16_u32(tmpl), vreinterpretq_u16_u32(tmph)).val[1];
77 
78     return vreinterpretq_s16_u16(res);
79 }
80 
81 // TILEX_PROCF(fx, max) (((fx)&0xFFFF)*((max)+1)>> 16)
sbpsm_repeat_tile4(int32x4_t f,unsigned max)82 static inline int32x4_t sbpsm_repeat_tile4(int32x4_t f, unsigned max) {
83     uint16x4_t res;
84     uint32x4_t tmp;
85 
86     // get the lower 16 bits
87     res = vmovn_u32(vreinterpretq_u32_s32(f));
88 
89     // bare multiplication, not SkFixedMul
90     tmp = vmull_u16(res, vdup_n_u16(max+1));
91 
92     // extraction of the 16 upper bits
93     tmp = vshrq_n_u32(tmp, 16);
94 
95     return vreinterpretq_s32_u32(tmp);
96 }
97 
98 // EXTRACT_LOW_BITS(fx, max)         ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
sbpsm_repeat_tile4_low_bits(int32x4_t fx,unsigned max)99 static inline int32x4_t sbpsm_repeat_tile4_low_bits(int32x4_t fx, unsigned max) {
100     uint16x4_t res;
101     uint32x4_t tmp;
102     int32x4_t ret;
103 
104     // get the lower 16 bits
105     res = vmovn_u32(vreinterpretq_u32_s32(fx));
106 
107     // bare multiplication, not SkFixedMul
108     tmp = vmull_u16(res, vdup_n_u16(max + 1));
109 
110     // shift and mask
111     ret = vshrq_n_s32(vreinterpretq_s32_u32(tmp), 12);
112 
113     /* We don't need the mask below because the caller will
114      * overwrite the non-masked bits
115      */
116     //ret = vandq_s32(ret, vdupq_n_s32(0xF));
117 
118     return ret;
119 }
120 
121 #define MAKENAME(suffix)                ClampX_ClampY ## suffix ## _neon
122 #define TILEX_PROCF(fx, max)            SkClampMax((fx) >> 16, max)
123 #define TILEY_PROCF(fy, max)            SkClampMax((fy) >> 16, max)
124 #define TILEX_PROCF_NEON8(l, h, max)    sbpsm_clamp_tile8(l, h, max)
125 #define TILEY_PROCF_NEON8(l, h, max)    sbpsm_clamp_tile8(l, h, max)
126 #define TILEX_PROCF_NEON4(fx, max)      sbpsm_clamp_tile4(fx, max)
127 #define TILEY_PROCF_NEON4(fy, max)      sbpsm_clamp_tile4(fy, max)
128 #define EXTRACT_LOW_BITS(v, max)        (((v) >> 12) & 0xF)
129 #define EXTRACT_LOW_BITS_NEON4(v, max)  sbpsm_clamp_tile4_low_bits(v)
130 #define CHECK_FOR_DECAL
131 #include "SkBitmapProcState_matrix_neon.h"
132 
133 #define MAKENAME(suffix)                RepeatX_RepeatY ## suffix ## _neon
134 #define TILEX_PROCF(fx, max)            SK_USHIFT16(((fx) & 0xFFFF) * ((max) + 1))
135 #define TILEY_PROCF(fy, max)            SK_USHIFT16(((fy) & 0xFFFF) * ((max) + 1))
136 #define TILEX_PROCF_NEON8(l, h, max)    sbpsm_repeat_tile8(l, h, max)
137 #define TILEY_PROCF_NEON8(l, h, max)    sbpsm_repeat_tile8(l, h, max)
138 #define TILEX_PROCF_NEON4(fx, max)      sbpsm_repeat_tile4(fx, max)
139 #define TILEY_PROCF_NEON4(fy, max)      sbpsm_repeat_tile4(fy, max)
140 #define EXTRACT_LOW_BITS(v, max)        ((((v) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
141 #define EXTRACT_LOW_BITS_NEON4(v, max)  sbpsm_repeat_tile4_low_bits(v, max)
142 #include "SkBitmapProcState_matrix_neon.h"
143 
144 
145 
decal_nofilter_scale_neon(uint32_t dst[],SkFixed fx,SkFixed dx,int count)146 void decal_nofilter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count) {
147     if (count >= 8) {
148         // SkFixed is 16.16 fixed point
149         SkFixed dx8 = dx * 8;
150         int32x4_t vdx8 = vdupq_n_s32(dx8);
151 
152         // setup lbase and hbase
153         int32x4_t lbase, hbase;
154         lbase = vdupq_n_s32(fx);
155         lbase = vsetq_lane_s32(fx + dx, lbase, 1);
156         lbase = vsetq_lane_s32(fx + dx + dx, lbase, 2);
157         lbase = vsetq_lane_s32(fx + dx + dx + dx, lbase, 3);
158         hbase = lbase + vdupq_n_s32(4 * dx);
159 
160         do {
161             // store the upper 16 bits
162             vst1q_u32(dst, vreinterpretq_u32_s16(
163                 vuzpq_s16(vreinterpretq_s16_s32(lbase), vreinterpretq_s16_s32(hbase)).val[1]
164             ));
165 
166             // on to the next group of 8
167             lbase += vdx8;
168             hbase += vdx8;
169             dst += 4; // we did 8 elements but the result is twice smaller
170             count -= 8;
171             fx += dx8;
172         } while (count >= 8);
173     }
174 
175     uint16_t* xx = (uint16_t*)dst;
176     for (int i = count; i > 0; --i) {
177         *xx++ = SkToU16(fx >> 16); fx += dx;
178     }
179 }
180 
decal_filter_scale_neon(uint32_t dst[],SkFixed fx,SkFixed dx,int count)181 void decal_filter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count) {
182     if (count >= 8) {
183         SkFixed dx8 = dx * 8;
184         int32x4_t vdx8 = vdupq_n_s32(dx8);
185 
186         int32x4_t wide_fx, wide_fx2;
187         wide_fx = vdupq_n_s32(fx);
188         wide_fx = vsetq_lane_s32(fx + dx, wide_fx, 1);
189         wide_fx = vsetq_lane_s32(fx + dx + dx, wide_fx, 2);
190         wide_fx = vsetq_lane_s32(fx + dx + dx + dx, wide_fx, 3);
191 
192         wide_fx2 = vaddq_s32(wide_fx, vdupq_n_s32(4 * dx));
193 
194         while (count >= 8) {
195             int32x4_t wide_out;
196             int32x4_t wide_out2;
197 
198             wide_out = vshlq_n_s32(vshrq_n_s32(wide_fx, 12), 14);
199             wide_out = wide_out | (vshrq_n_s32(wide_fx,16) + vdupq_n_s32(1));
200 
201             wide_out2 = vshlq_n_s32(vshrq_n_s32(wide_fx2, 12), 14);
202             wide_out2 = wide_out2 | (vshrq_n_s32(wide_fx2,16) + vdupq_n_s32(1));
203 
204             vst1q_u32(dst, vreinterpretq_u32_s32(wide_out));
205             vst1q_u32(dst+4, vreinterpretq_u32_s32(wide_out2));
206 
207             dst += 8;
208             fx += dx8;
209             wide_fx += vdx8;
210             wide_fx2 += vdx8;
211             count -= 8;
212         }
213     }
214 
215     if (count & 1)
216     {
217         SkASSERT((fx >> (16 + 14)) == 0);
218         *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1);
219         fx += dx;
220     }
221     while ((count -= 2) >= 0)
222     {
223         SkASSERT((fx >> (16 + 14)) == 0);
224         *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1);
225         fx += dx;
226 
227         *dst++ = (fx >> 12 << 14) | ((fx >> 16) + 1);
228         fx += dx;
229     }
230 }
231