blob: 50e165397aecd8c7a250ba09e1ae351937f5113a [file] [log] [blame]
reed@android.com7d2e3222009-07-30 02:22:31 +00001/*
borenet@google.com84d67152012-07-26 14:20:13 +00002 * Copyright 2012 The Android Open Source Project
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com7d2e3222009-07-30 02:22:31 +00006 */
7
digit@google.coma8dd1ce2012-08-08 22:06:29 +00008#include "SkBlitRow_opts_arm.h"
9
reed@google.com58af9a62011-10-12 13:43:52 +000010#include "SkBlitMask.h"
borenet@google.com84d67152012-07-26 14:20:13 +000011#include "SkBlitRow.h"
reed@android.com6123e472009-08-04 01:52:27 +000012#include "SkColorPriv.h"
13#include "SkDither.h"
reed@google.com686c04c2012-08-07 21:44:47 +000014#include "SkMathPriv.h"
borenet@google.com84d67152012-07-26 14:20:13 +000015#include "SkUtils.h"
16
17#include "SkCachePreload_arm.h"
reed@android.com7d2e3222009-07-30 02:22:31 +000018
digit@google.coma8dd1ce2012-08-08 22:06:29 +000019#if USE_ARM_CODE
agl@chromium.org94d14642010-08-17 16:24:15 +000020static void S32A_Opaque_BlitRow32_arm(SkPMColor* SK_RESTRICT dst,
21 const SkPMColor* SK_RESTRICT src,
22 int count, U8CPU alpha) {
23
24 SkASSERT(255 == alpha);
25
agl@chromium.org94d14642010-08-17 16:24:15 +000026 asm volatile (
27 "cmp %[count], #0 \n\t" /* comparing count with 0 */
28 "beq 3f \n\t" /* if zero exit */
29
30 "mov ip, #0xff \n\t" /* load the 0xff mask in ip */
31 "orr ip, ip, ip, lsl #16 \n\t" /* convert it to 0xff00ff in ip */
32
33 "cmp %[count], #2 \n\t" /* compare count with 2 */
34 "blt 2f \n\t" /* if less than 2 -> single loop */
35
36 /* Double Loop */
37 "1: \n\t" /* <double loop> */
38 "ldm %[src]!, {r5,r6} \n\t" /* load the src(s) at r5-r6 */
39 "ldm %[dst], {r7,r8} \n\t" /* loading dst(s) into r7-r8 */
40 "lsr r4, r5, #24 \n\t" /* extracting the alpha from source and storing it to r4 */
41
42 /* ----------- */
43 "and r9, ip, r7 \n\t" /* r9 = br masked by ip */
44 "rsb r4, r4, #256 \n\t" /* subtracting the alpha from 256 -> r4=scale */
45 "and r10, ip, r7, lsr #8 \n\t" /* r10 = ag masked by ip */
46
47 "mul r9, r9, r4 \n\t" /* br = br * scale */
48 "mul r10, r10, r4 \n\t" /* ag = ag * scale */
49 "and r9, ip, r9, lsr #8 \n\t" /* lsr br by 8 and mask it */
50
51 "and r10, r10, ip, lsl #8 \n\t" /* mask ag with reverse mask */
52 "lsr r4, r6, #24 \n\t" /* extracting the alpha from source and storing it to r4 */
53 "orr r7, r9, r10 \n\t" /* br | ag*/
54
55 "add r7, r5, r7 \n\t" /* dst = src + calc dest(r7) */
56 "rsb r4, r4, #256 \n\t" /* subtracting the alpha from 255 -> r4=scale */
57
58 /* ----------- */
59 "and r9, ip, r8 \n\t" /* r9 = br masked by ip */
60
61 "and r10, ip, r8, lsr #8 \n\t" /* r10 = ag masked by ip */
62 "mul r9, r9, r4 \n\t" /* br = br * scale */
63 "sub %[count], %[count], #2 \n\t"
64 "mul r10, r10, r4 \n\t" /* ag = ag * scale */
65
66 "and r9, ip, r9, lsr #8 \n\t" /* lsr br by 8 and mask it */
67 "and r10, r10, ip, lsl #8 \n\t" /* mask ag with reverse mask */
68 "cmp %[count], #1 \n\t" /* comparing count with 1 */
69 "orr r8, r9, r10 \n\t" /* br | ag */
70
71 "add r8, r6, r8 \n\t" /* dst = src + calc dest(r8) */
72
73 /* ----------------- */
74 "stm %[dst]!, {r7,r8} \n\t" /* *dst = r7, increment dst by two (each times 4) */
75 /* ----------------- */
76
77 "bgt 1b \n\t" /* if greater than 1 -> reloop */
78 "blt 3f \n\t" /* if less than 1 -> exit */
79
80 /* Single Loop */
81 "2: \n\t" /* <single loop> */
82 "ldr r5, [%[src]], #4 \n\t" /* load the src pointer into r5 r5=src */
83 "ldr r7, [%[dst]] \n\t" /* loading dst into r7 */
84 "lsr r4, r5, #24 \n\t" /* extracting the alpha from source and storing it to r4 */
85
86 /* ----------- */
87 "and r9, ip, r7 \n\t" /* r9 = br masked by ip */
88 "rsb r4, r4, #256 \n\t" /* subtracting the alpha from 256 -> r4=scale */
89
90 "and r10, ip, r7, lsr #8 \n\t" /* r10 = ag masked by ip */
91 "mul r9, r9, r4 \n\t" /* br = br * scale */
92 "mul r10, r10, r4 \n\t" /* ag = ag * scale */
93 "and r9, ip, r9, lsr #8 \n\t" /* lsr br by 8 and mask it */
94
95 "and r10, r10, ip, lsl #8 \n\t" /* mask ag */
96 "orr r7, r9, r10 \n\t" /* br | ag */
97
98 "add r7, r5, r7 \n\t" /* *dst = src + calc dest(r7) */
99
100 /* ----------------- */
101 "str r7, [%[dst]], #4 \n\t" /* *dst = r7, increment dst by one (times 4) */
102 /* ----------------- */
103
104 "3: \n\t" /* <exit> */
105 : [dst] "+r" (dst), [src] "+r" (src), [count] "+r" (count)
106 :
107 : "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "ip", "memory"
108 );
109}
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000110#endif // USE_ARM_CODE
reed@android.com4e635f92009-10-19 17:39:46 +0000111
agl@chromium.org8b17ac32010-09-10 15:09:42 +0000112/*
113 * ARM asm version of S32A_Blend_BlitRow32
114 */
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000115// This version is also used by the NEON procs table, so always compile it
116void S32A_Blend_BlitRow32_arm(SkPMColor* SK_RESTRICT dst,
117 const SkPMColor* SK_RESTRICT src,
118 int count, U8CPU alpha) {
agl@chromium.org8b17ac32010-09-10 15:09:42 +0000119 asm volatile (
120 "cmp %[count], #0 \n\t" /* comparing count with 0 */
121 "beq 3f \n\t" /* if zero exit */
122
123 "mov r12, #0xff \n\t" /* load the 0xff mask in r12 */
124 "orr r12, r12, r12, lsl #16 \n\t" /* convert it to 0xff00ff in r12 */
125
126 /* src1,2_scale */
127 "add %[alpha], %[alpha], #1 \n\t" /* loading %[alpha]=src_scale=alpha+1 */
128
129 "cmp %[count], #2 \n\t" /* comparing count with 2 */
130 "blt 2f \n\t" /* if less than 2 -> single loop */
131
132 /* Double Loop */
133 "1: \n\t" /* <double loop> */
134 "ldm %[src]!, {r5, r6} \n\t" /* loading src pointers into r5 and r6 */
135 "ldm %[dst], {r7, r8} \n\t" /* loading dst pointers into r7 and r8 */
136
137 /* dst1_scale and dst2_scale*/
138 "lsr r9, r5, #24 \n\t" /* src >> 24 */
139 "lsr r10, r6, #24 \n\t" /* src >> 24 */
george@mozilla.com2092c402012-07-27 21:08:01 +0000140#ifdef SK_ARM_HAS_EDSP
agl@chromium.org8b17ac32010-09-10 15:09:42 +0000141 "smulbb r9, r9, %[alpha] \n\t" /* r9 = SkMulS16 r9 with src_scale */
142 "smulbb r10, r10, %[alpha] \n\t" /* r10 = SkMulS16 r10 with src_scale */
george@mozilla.com2092c402012-07-27 21:08:01 +0000143#else
144 "mul r9, r9, %[alpha] \n\t" /* r9 = SkMulS16 r9 with src_scale */
145 "mul r10, r10, %[alpha] \n\t" /* r10 = SkMulS16 r10 with src_scale */
146#endif
agl@chromium.org8b17ac32010-09-10 15:09:42 +0000147 "lsr r9, r9, #8 \n\t" /* r9 >> 8 */
148 "lsr r10, r10, #8 \n\t" /* r10 >> 8 */
149 "rsb r9, r9, #256 \n\t" /* dst1_scale = r9 = 255 - r9 + 1 */
150 "rsb r10, r10, #256 \n\t" /* dst2_scale = r10 = 255 - r10 + 1 */
151
152 /* ---------------------- */
153
154 /* src1, src1_scale */
155 "and r11, r12, r5, lsr #8 \n\t" /* ag = r11 = r5 masked by r12 lsr by #8 */
156 "and r4, r12, r5 \n\t" /* rb = r4 = r5 masked by r12 */
157 "mul r11, r11, %[alpha] \n\t" /* ag = r11 times src_scale */
158 "mul r4, r4, %[alpha] \n\t" /* rb = r4 times src_scale */
159 "and r11, r11, r12, lsl #8 \n\t" /* ag masked by reverse mask (r12) */
160 "and r4, r12, r4, lsr #8 \n\t" /* rb masked by mask (r12) */
161 "orr r5, r11, r4 \n\t" /* r5 = (src1, src_scale) */
162
163 /* dst1, dst1_scale */
164 "and r11, r12, r7, lsr #8 \n\t" /* ag = r11 = r7 masked by r12 lsr by #8 */
165 "and r4, r12, r7 \n\t" /* rb = r4 = r7 masked by r12 */
166 "mul r11, r11, r9 \n\t" /* ag = r11 times dst_scale (r9) */
167 "mul r4, r4, r9 \n\t" /* rb = r4 times dst_scale (r9) */
168 "and r11, r11, r12, lsl #8 \n\t" /* ag masked by reverse mask (r12) */
169 "and r4, r12, r4, lsr #8 \n\t" /* rb masked by mask (r12) */
170 "orr r9, r11, r4 \n\t" /* r9 = (dst1, dst_scale) */
171
172 /* ---------------------- */
173 "add r9, r5, r9 \n\t" /* *dst = src plus dst both scaled */
174 /* ---------------------- */
175
176 /* ====================== */
177
178 /* src2, src2_scale */
179 "and r11, r12, r6, lsr #8 \n\t" /* ag = r11 = r6 masked by r12 lsr by #8 */
180 "and r4, r12, r6 \n\t" /* rb = r4 = r6 masked by r12 */
181 "mul r11, r11, %[alpha] \n\t" /* ag = r11 times src_scale */
182 "mul r4, r4, %[alpha] \n\t" /* rb = r4 times src_scale */
183 "and r11, r11, r12, lsl #8 \n\t" /* ag masked by reverse mask (r12) */
184 "and r4, r12, r4, lsr #8 \n\t" /* rb masked by mask (r12) */
185 "orr r6, r11, r4 \n\t" /* r6 = (src2, src_scale) */
186
187 /* dst2, dst2_scale */
188 "and r11, r12, r8, lsr #8 \n\t" /* ag = r11 = r8 masked by r12 lsr by #8 */
189 "and r4, r12, r8 \n\t" /* rb = r4 = r8 masked by r12 */
190 "mul r11, r11, r10 \n\t" /* ag = r11 times dst_scale (r10) */
191 "mul r4, r4, r10 \n\t" /* rb = r4 times dst_scale (r6) */
192 "and r11, r11, r12, lsl #8 \n\t" /* ag masked by reverse mask (r12) */
193 "and r4, r12, r4, lsr #8 \n\t" /* rb masked by mask (r12) */
194 "orr r10, r11, r4 \n\t" /* r10 = (dst2, dst_scale) */
195
196 "sub %[count], %[count], #2 \n\t" /* decrease count by 2 */
197 /* ---------------------- */
198 "add r10, r6, r10 \n\t" /* *dst = src plus dst both scaled */
199 /* ---------------------- */
200 "cmp %[count], #1 \n\t" /* compare count with 1 */
201 /* ----------------- */
202 "stm %[dst]!, {r9, r10} \n\t" /* copy r9 and r10 to r7 and r8 respectively */
203 /* ----------------- */
204
205 "bgt 1b \n\t" /* if %[count] greater than 1 reloop */
206 "blt 3f \n\t" /* if %[count] less than 1 exit */
207 /* else get into the single loop */
208 /* Single Loop */
209 "2: \n\t" /* <single loop> */
210 "ldr r5, [%[src]], #4 \n\t" /* loading src pointer into r5: r5=src */
211 "ldr r7, [%[dst]] \n\t" /* loading dst pointer into r7: r7=dst */
212
213 "lsr r6, r5, #24 \n\t" /* src >> 24 */
214 "and r8, r12, r5, lsr #8 \n\t" /* ag = r8 = r5 masked by r12 lsr by #8 */
george@mozilla.com2092c402012-07-27 21:08:01 +0000215#ifdef SK_ARM_HAS_EDSP
agl@chromium.org8b17ac32010-09-10 15:09:42 +0000216 "smulbb r6, r6, %[alpha] \n\t" /* r6 = SkMulS16 with src_scale */
george@mozilla.com2092c402012-07-27 21:08:01 +0000217#else
218 "mul r6, r6, %[alpha] \n\t" /* r6 = SkMulS16 with src_scale */
219#endif
agl@chromium.org8b17ac32010-09-10 15:09:42 +0000220 "and r9, r12, r5 \n\t" /* rb = r9 = r5 masked by r12 */
221 "lsr r6, r6, #8 \n\t" /* r6 >> 8 */
222 "mul r8, r8, %[alpha] \n\t" /* ag = r8 times scale */
223 "rsb r6, r6, #256 \n\t" /* r6 = 255 - r6 + 1 */
224
225 /* src, src_scale */
226 "mul r9, r9, %[alpha] \n\t" /* rb = r9 times scale */
227 "and r8, r8, r12, lsl #8 \n\t" /* ag masked by reverse mask (r12) */
228 "and r9, r12, r9, lsr #8 \n\t" /* rb masked by mask (r12) */
229 "orr r10, r8, r9 \n\t" /* r10 = (scr, src_scale) */
230
231 /* dst, dst_scale */
232 "and r8, r12, r7, lsr #8 \n\t" /* ag = r8 = r7 masked by r12 lsr by #8 */
233 "and r9, r12, r7 \n\t" /* rb = r9 = r7 masked by r12 */
234 "mul r8, r8, r6 \n\t" /* ag = r8 times scale (r6) */
235 "mul r9, r9, r6 \n\t" /* rb = r9 times scale (r6) */
236 "and r8, r8, r12, lsl #8 \n\t" /* ag masked by reverse mask (r12) */
237 "and r9, r12, r9, lsr #8 \n\t" /* rb masked by mask (r12) */
238 "orr r7, r8, r9 \n\t" /* r7 = (dst, dst_scale) */
239
240 "add r10, r7, r10 \n\t" /* *dst = src plus dst both scaled */
241
242 /* ----------------- */
243 "str r10, [%[dst]], #4 \n\t" /* *dst = r10, postincrement dst by one (times 4) */
244 /* ----------------- */
245
246 "3: \n\t" /* <exit> */
247 : [dst] "+r" (dst), [src] "+r" (src), [count] "+r" (count), [alpha] "+r" (alpha)
248 :
249 : "cc", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "memory"
250 );
251
252}
reed@android.com4e635f92009-10-19 17:39:46 +0000253
254///////////////////////////////////////////////////////////////////////////////
255
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000256#if USE_ARM_CODE
257const SkBlitRow::Proc sk_blitrow_platform_565_procs_arm[] = {
reed@android.com7d2e3222009-07-30 02:22:31 +0000258 // no dither
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000259 NULL, // S32_D565_Opaque
260 NULL, // S32_D565_Blend
261 NULL, // S32A_D565_Opaque
262 NULL, // S32A_D565_Blend
263
reed@android.com7d2e3222009-07-30 02:22:31 +0000264 // dither
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000265 NULL, // S32_D565_Opaque_Dither
266 NULL, // S32_D565_Blend_Dither
267 NULL, // S32A_D565_Opaque_Dither
reed@android.com7d2e3222009-07-30 02:22:31 +0000268 NULL, // S32A_D565_Blend_Dither
269};
270
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000271const SkBlitRow::Proc sk_blitrow_platform_4444_procs_arm[] = {
reed@android.com7d2e3222009-07-30 02:22:31 +0000272 // no dither
273 NULL, // S32_D4444_Opaque,
274 NULL, // S32_D4444_Blend,
275 NULL, // S32A_D4444_Opaque,
276 NULL, // S32A_D4444_Blend,
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000277
reed@android.com7d2e3222009-07-30 02:22:31 +0000278 // dither
279 NULL, // S32_D4444_Opaque_Dither,
280 NULL, // S32_D4444_Blend_Dither,
281 NULL, // S32A_D4444_Opaque_Dither,
282 NULL, // S32A_D4444_Blend_Dither
283};
284
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000285const SkBlitRow::Proc32 sk_blitrow_platform_32_procs_arm[] = {
reed@android.com3bbac132009-09-23 18:48:10 +0000286 NULL, // S32_Opaque,
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000287 NULL, // S32_Blend,
288 S32A_Opaque_BlitRow32_arm, // S32A_Opaque,
289 S32A_Blend_BlitRow32_arm // S32A_Blend
reed@android.com3bbac132009-09-23 18:48:10 +0000290};
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000291#endif
reed@android.com3bbac132009-09-23 18:48:10 +0000292
reed@android.comf0f4e9a2009-11-13 19:00:49 +0000293SkBlitRow::Proc SkBlitRow::PlatformProcs4444(unsigned flags) {
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000294 return SK_ARM_NEON_WRAP(sk_blitrow_platform_4444_procs_arm)[flags];
senorblanco@chromium.org92727612009-11-04 20:51:06 +0000295}
296
reed@android.comf0f4e9a2009-11-13 19:00:49 +0000297SkBlitRow::Proc SkBlitRow::PlatformProcs565(unsigned flags) {
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000298 return SK_ARM_NEON_WRAP(sk_blitrow_platform_565_procs_arm)[flags];
senorblanco@chromium.org92727612009-11-04 20:51:06 +0000299}
300
reed@android.comf0f4e9a2009-11-13 19:00:49 +0000301SkBlitRow::Proc32 SkBlitRow::PlatformProcs32(unsigned flags) {
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000302 return SK_ARM_NEON_WRAP(sk_blitrow_platform_32_procs_arm)[flags];
senorblanco@chromium.org92727612009-11-04 20:51:06 +0000303}
reed@android.com229d9b32010-04-09 18:44:46 +0000304
reed@google.com56846802011-11-16 13:54:47 +0000305///////////////////////////////////////////////////////////////////////////////
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000306#define Color32_arm NULL
borenet@google.com84d67152012-07-26 14:20:13 +0000307SkBlitRow::ColorProc SkBlitRow::PlatformColorProc() {
digit@google.coma8dd1ce2012-08-08 22:06:29 +0000308 return SK_ARM_NEON_WRAP(Color32_arm);
borenet@google.com84d67152012-07-26 14:20:13 +0000309}
reed@google.com981d4792011-03-09 12:55:47 +0000310
reed@google.com56846802011-11-16 13:54:47 +0000311SkBlitMask::ColorProc SkBlitMask::PlatformColorProcs(SkBitmap::Config dstConfig,
312 SkMask::Format maskFormat,
313 SkColor color) {
314 return NULL;
315}
316
tomhudson@google.comd6770e62012-02-14 16:01:15 +0000317SkBlitMask::BlitLCD16RowProc SkBlitMask::PlatformBlitRowProcs16(bool isOpaque) {
318 return NULL;
319}
320
reed@google.com56846802011-11-16 13:54:47 +0000321SkBlitMask::RowProc SkBlitMask::PlatformRowProcs(SkBitmap::Config dstConfig,
322 SkMask::Format maskFormat,
323 RowFlags flags) {
324 return NULL;
reed@google.com981d4792011-03-09 12:55:47 +0000325}