blob: 612ef0472051d6227e05ff451a3b5ad0adf501d7 [file] [log] [blame]
Florin Malitad1c550e2016-12-19 10:55:41 -05001/* Copyright 2009 Motorola
digit@google.comfce02ac2012-08-01 14:25:07 +00002 *
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"
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +000011#include "SkBitmapProcState_utils.h"
digit@google.comfce02ac2012-08-01 14:25:07 +000012
commit-bot@chromium.orga96176d2014-01-28 15:18:54 +000013#include <arm_neon.h>
14
digit@google.comfce02ac2012-08-01 14:25:07 +000015extern const SkBitmapProcState::MatrixProc ClampX_ClampY_Procs_neon[];
16extern const SkBitmapProcState::MatrixProc RepeatX_RepeatY_Procs_neon[];
17
18static void decal_nofilter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
19static void decal_filter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count);
20
commit-bot@chromium.orga96176d2014-01-28 15:18:54 +000021// TILEX_PROCF(fx, max) SkClampMax((fx) >> 16, max)
22static inline int16x8_t sbpsm_clamp_tile8(int32x4_t low, int32x4_t high, unsigned max) {
23 int16x8_t res;
digit@google.comfce02ac2012-08-01 14:25:07 +000024
commit-bot@chromium.orga96176d2014-01-28 15:18:54 +000025 // 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)
36static 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
Florin Malitad1c550e2016-12-19 10:55:41 -050049// EXTRACT_LOW_BITS(fy, max) (((fy) >> 12) & 0xF)
commit-bot@chromium.orga96176d2014-01-28 15:18:54 +000050static 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)
64static 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)
82static 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
Florin Malitad1c550e2016-12-19 10:55:41 -050098// EXTRACT_LOW_BITS(fx, max) ((((fx) & 0xFFFF) * ((max) + 1) >> 12) & 0xF)
commit-bot@chromium.orga96176d2014-01-28 15:18:54 +000099static 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)
Florin Malitad1c550e2016-12-19 10:55:41 -0500128#define EXTRACT_LOW_BITS(v, max) (((v) >> 12) & 0xF)
129#define EXTRACT_LOW_BITS_NEON4(v, max) sbpsm_clamp_tile4_low_bits(v)
commit-bot@chromium.orga96176d2014-01-28 15:18:54 +0000130#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)
Florin Malitad1c550e2016-12-19 10:55:41 -0500140#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)
commit-bot@chromium.orga96176d2014-01-28 15:18:54 +0000142#include "SkBitmapProcState_matrix_neon.h"
digit@google.comfce02ac2012-08-01 14:25:07 +0000143
144
digit@google.comfce02ac2012-08-01 14:25:07 +0000145
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000146void decal_nofilter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count) {
digit@google.comfce02ac2012-08-01 14:25:07 +0000147 if (count >= 8) {
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000148 // SkFixed is 16.16 fixed point
149 SkFixed dx8 = dx * 8;
150 int32x4_t vdx8 = vdupq_n_s32(dx8);
digit@google.comfce02ac2012-08-01 14:25:07 +0000151
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000152 // setup lbase and hbase
digit@google.comfce02ac2012-08-01 14:25:07 +0000153 int32x4_t lbase, hbase;
digit@google.comfce02ac2012-08-01 14:25:07 +0000154 lbase = vdupq_n_s32(fx);
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000155 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);
digit@google.comfce02ac2012-08-01 14:25:07 +0000159
digit@google.comfce02ac2012-08-01 14:25:07 +0000160 do {
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000161 // 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 ));
digit@google.comfce02ac2012-08-01 14:25:07 +0000165
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000166 // 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
digit@google.comfce02ac2012-08-01 14:25:07 +0000170 count -= 8;
171 fx += dx8;
172 } while (count >= 8);
digit@google.comfce02ac2012-08-01 14:25:07 +0000173 }
174
175 uint16_t* xx = (uint16_t*)dst;
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000176 for (int i = count; i > 0; --i) {
digit@google.comfce02ac2012-08-01 14:25:07 +0000177 *xx++ = SkToU16(fx >> 16); fx += dx;
178 }
179}
180
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000181void decal_filter_scale_neon(uint32_t dst[], SkFixed fx, SkFixed dx, int count) {
digit@google.comfce02ac2012-08-01 14:25:07 +0000182 if (count >= 8) {
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000183 SkFixed dx8 = dx * 8;
184 int32x4_t vdx8 = vdupq_n_s32(dx8);
digit@google.comfce02ac2012-08-01 14:25:07 +0000185
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000186 int32x4_t wide_fx, wide_fx2;
digit@google.comfce02ac2012-08-01 14:25:07 +0000187 wide_fx = vdupq_n_s32(fx);
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000188 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);
digit@google.comfce02ac2012-08-01 14:25:07 +0000191
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000192 wide_fx2 = vaddq_s32(wide_fx, vdupq_n_s32(4 * dx));
digit@google.comfce02ac2012-08-01 14:25:07 +0000193
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);
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000199 wide_out = wide_out | (vshrq_n_s32(wide_fx,16) + vdupq_n_s32(1));
digit@google.comfce02ac2012-08-01 14:25:07 +0000200
201 wide_out2 = vshlq_n_s32(vshrq_n_s32(wide_fx2, 12), 14);
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000202 wide_out2 = wide_out2 | (vshrq_n_s32(wide_fx2,16) + vdupq_n_s32(1));
digit@google.comfce02ac2012-08-01 14:25:07 +0000203
204 vst1q_u32(dst, vreinterpretq_u32_s32(wide_out));
205 vst1q_u32(dst+4, vreinterpretq_u32_s32(wide_out2));
206
207 dst += 8;
commit-bot@chromium.orga8c09662013-09-05 18:27:57 +0000208 fx += dx8;
209 wide_fx += vdx8;
210 wide_fx2 += vdx8;
digit@google.comfce02ac2012-08-01 14:25:07 +0000211 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}