summaryrefslogtreecommitdiffstats
path: root/src/fastscale/asm_scale.S
blob: 08b43da9f63a8e7a9cf4f1e58a494159911df3d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
#ifdef HAVE_X86_MMX

#ifdef __EMX__
/* Due to strange behaviour of as.exe we use this macros */
/* For all OS/2 coders - please use PGCC to compile this code */
#define PR_(foo) ___##foo
#define PT_(foo,func) ___##foo,func
#define SIZE(sym)                              \
	.___end_##sym:;                        \
	.size ___##sym,.___end_##sym-___##sym; \
	.align 8;
#else
#define PR_(foo) __##foo
#define PT_(foo,func) __##foo,func
#define SIZE(sym)                           \
	.__end_##sym:;                      \
	.size __##sym,.__end_##sym-__##sym; \
	.align 8;
#endif

/*\ 
|*| MMX assembly scaling routine for Imlib2
|*| Written by Willem Monsuwe <[email protected]>
\*/

.text
        .align 8
.globl PR_(mimageScale_mmx_AARGBA)
/*	.type PT_(mimageScale_mmx_AARGBA,@function) */ 


/*\ Prototype: __mimageScale_mmx_AARGBA(ImlibScaleInfo *isi, DATA32 *dest,
|*|	int dxx, int dyy, int dx, int dy, int dw, int dh, int dow, int sow)
\*/

#define isi	8(%ebp)
#define dest	12(%ebp)
#define dxx	16(%ebp)
#define dyy	20(%ebp)
#define dx	24(%ebp)
#define dy	28(%ebp)
#define dw	32(%ebp)
#define dh	36(%ebp)
#define dow	40(%ebp)
#define sow	44(%ebp)

/*\ Local variables that didn't fit in registers \*/
#define y	-4(%ebp)
#define yp	-8(%ebp)
#define yap	-12(%ebp)
#define xp	-16(%ebp)
#define xap	-20(%ebp)
#define Cx	-24(%ebp)
#define Mx	-28(%ebp)
#define Cy	-32(%ebp)
#define My	-36(%ebp)
#define sow_4	-40(%ebp)

/*\ When %edx points to ImlibScaleInfo, these are the members \*/
#define xpoints		(%edx)
#define ypoints		4(%edx)
#define xapoints	8(%edx)
#define yapoints	12(%edx)
#define xup_yup		16(%edx)

PR_(mimageScale_mmx_AARGBA):
	pushl %ebp
	movl %esp, %ebp
	subl $40, %esp
	pushl %ebx
	pushl %ecx
	pushl %edx
	pushl %edi
	pushl %esi
	movl isi, %edx

	/*\ Check (dw > 0) && (dh > 0) \*/
	cmpl $0, dw
	jle .scale_leave
	cmpl $0, dh
	jle .scale_leave

	/*\ X-based array pointers point to the end; we're looping up to 0 \*/
	/*\ %edi = dest + dow * dy + dx + dw \*/
	movl dow, %eax
	imull dy, %eax
	addl dx, %eax
	addl dw, %eax
	movl dest, %edi
	leal (%edi, %eax, 4), %edi
	/*\ xp = xpoints + dxx + dw \*/
	movl dxx, %ebx
	addl dw, %ebx
	movl xpoints, %eax
	leal (%eax, %ebx, 4), %eax
	movl %eax, xp
	/*\ xap = xapoints + dxx + dw \*/
	movl xapoints, %eax
	leal (%eax, %ebx, 4), %eax
	movl %eax, xap
	/*\ y = dh \*/
	movl dh, %eax
	movl %eax, y
	/*\ yp = ypoints + dyy \*/
	movl dyy, %ebx
	movl ypoints, %eax
	leal (%eax, %ebx, 4), %eax
	movl %eax, yp
	/*\ yap = yapoints + dyy \*/
	movl yapoints, %eax
	leal (%eax, %ebx, 4), %eax
	movl %eax, yap

	pxor %mm7, %mm7

	/*\ Test xup bit \*/
	movl xup_yup, %eax
	sarl $1, %eax
	jnc .scale_x_down

.scale_x_up:
	/*\ Test yup bit \*/
	sarl $1, %eax
	jnc .scale_x_up_y_down


/*\ Scaling up both ways \*/

.scale_x_up_y_up:
	movl sow, %ebx

.up_up_loop_y:

	/*\ x = -dw \*/
	movl dw, %ecx
	negl %ecx

	/*\ %eax = *yap << 4 \*/
	movl yap, %eax
	movl (%eax), %eax
	sall $4, %eax
	jz .up_up_yap_0
	movd %eax, %mm1
	punpcklwd %mm1, %mm1
	punpckldq %mm1, %mm1

.up_up_loop1_x:
	/*\ %esi = *yp + xp[x] \*/
	movl yp, %eax
	movl (%eax), %esi
	movl xp, %eax
	movl (%eax, %ecx, 4), %eax
	leal (%esi, %eax, 4), %esi

	/*\ %eax = xap[x] << 4 \*/
	movl xap, %eax
	movl (%eax, %ecx, 4), %eax
	sall $4, %eax
	jz .up_up_xap_0

	/*\ %mm0 = xap[x] << 4 \*/
	movd %eax, %mm0
	punpcklwd %mm0, %mm0
	punpckldq %mm0, %mm0

	/*\ Load and unpack four pixels in parralel
	|*| %mm2 = ptr[0],   %mm3 = ptr[1]
	|*| %mm4 = ptr[sow], %mm5 = ptr[sow + 1]
	\*/
	movq (%esi), %mm2
	movq (%esi, %ebx, 4), %mm4
	movq %mm2, %mm3
	movq %mm4, %mm5
	punpcklbw %mm7, %mm2
	punpcklbw %mm7, %mm4
	punpckhbw %mm7, %mm3
	punpckhbw %mm7, %mm5

	/*\ X interpolation: r = l + (r - l) * xap \*/
	psubw %mm2, %mm3
	psubw %mm4, %mm5
	psllw $4, %mm3
	psllw $4, %mm5
	pmulhw %mm0, %mm3
	pmulhw %mm0, %mm5
	paddw %mm2, %mm3
	paddw %mm4, %mm5
	/*\ Now %mm3 = I(ptr[0], ptr[1]), %mm5 = I(ptr[sow], ptr[sow + 1]) \*/
	jmp .up_up_common
.up_up_xap_0:
	/*\ Load and unpack two pixels
	|*| %mm3 = ptr[0], %mm5 = ptr[sow]
	\*/
	movd (%esi), %mm3
	movd (%esi, %ebx, 4), %mm5
	punpcklbw %mm7, %mm3
	punpcklbw %mm7, %mm5
.up_up_common:
	/*\ Y interpolation: d = u + (d - u) * yap \*/
	psubw %mm3, %mm5
	psllw $4, %mm5
	pmulhw %mm1, %mm5
	paddw %mm3, %mm5
	packuswb %mm5, %mm5
	movd %mm5, (%edi, %ecx, 4)

	/*\ while (++x) \*/
	incl %ecx
	jnz .up_up_loop1_x
	jmp .up_up_yap_end
.up_up_yap_0:

.up_up_loop2_x:
	/*\ %esi = *yp + xp[x] \*/
	movl yp, %eax
	movl (%eax), %esi
	movl xp, %eax
	movl (%eax, %ecx, 4), %eax
	leal (%esi, %eax, 4), %esi

	/*\ %eax = xap[x] << 4 \*/
	movl xap, %eax
	movl (%eax, %ecx, 4), %eax
	sall $4, %eax
	jz .up_up_0

	/*\ %mm0 = xap[x] << 4 \*/
	movd %eax, %mm0
	punpcklwd %mm0, %mm0
	punpckldq %mm0, %mm0

	/*\ Load and unpack two pixels in parralel
	|*| %mm2 = ptr[0], %mm3 = ptr[1]
	\*/
	movq (%esi), %mm2
	movq %mm2, %mm3
	punpcklbw %mm7, %mm2
	punpckhbw %mm7, %mm3

	/*\ X interpolation: r = l + (r - l) * xap \*/
	psubw %mm2, %mm3
	psllw $4, %mm3
	pmulhw %mm0, %mm3
	paddw %mm2, %mm3
	packuswb %mm3, %mm3
	movd %mm3, (%edi, %ecx, 4)
	jmp .up_up_1
.up_up_0:
	/*\ dptr[x] = *sptr \*/
	movl (%esi), %eax
	movl %eax, (%edi, %ecx, 4)
.up_up_1:
	incl %ecx
	jnz .up_up_loop2_x

.up_up_yap_end:
	/*\ dptr += dow \*/
	movl dow, %eax
	leal (%edi, %eax, 4), %edi
	/*\ yap++; yp++ \*/
	addl $4, yap
	addl $4, yp
	/*\ while (y--) \*/
	decl y
	jnz .up_up_loop_y

	jmp .scale_leave


/*\ Scaling down vertically \*/

.scale_x_up_y_down:
	/*\ sow_4 = sow * 4 \*/
	movl sow, %eax
	sall $2, %eax
	movl %eax, sow_4

.up_down_loop_y:

	/*\ Setup My and Cy \*/
	movl yap, %eax
	movzwl (%eax), %ebx
	movl %ebx, My
	movzwl 2(%eax), %eax
	movl %eax, Cy

	/*\ mm4 = Cy \*/
	movd %eax, %mm4
	punpcklwd %mm4, %mm4
	punpckldq %mm4, %mm4
	/*\ mm5 = My \*/
	movd %ebx, %mm5
	punpcklwd %mm5, %mm5
	punpckldq %mm5, %mm5

	/*\ x = -dw \*/
	movl dw, %ecx
	negl %ecx
.up_down_loop_x:
	/*\ %esi = *yp + xp[x] \*/
	movl yp, %eax
	movl (%eax), %esi
	movl xp, %eax
	movl (%eax, %ecx, 4), %eax
	leal (%esi, %eax, 4), %esi

	movl %esi, %eax
	/*\ v = (*p * My) >> 10 \*/
	movd (%eax), %mm0
	punpcklbw %mm7, %mm0
	psllw $6, %mm0
	pmulhw %mm5, %mm0
	
	/*\ i = 0x4000 - My \*/
	movl $0x4000, %ebx
	subl My, %ebx
	jbe 5f
	jmp 2f
1:
	/*\ p += sow; v += (*p * Cy) >> 10 \*/
	addl sow_4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm4, %mm1
	paddw %mm1, %mm0
	
	/*\ i -= Cy; while (i > Cy) \*/
	subl Cy, %ebx
2:
	cmpl Cy, %ebx
	jg 1b
	
	/*\ mm6 = i \*/
	movd %ebx, %mm6
	punpcklwd %mm6, %mm6
	punpckldq %mm6, %mm6
	
	/*\ p += sow; v += (*p * i) >> 10 \*/
	addl sow_4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm6, %mm1
	paddw %mm1, %mm0
5:
	/*\ %eax = xap[x] << 5 \*/
	movl xap, %eax
	movl (%eax, %ecx, 4), %eax
	sall $5, %eax
	jz 6f
	/*\ mm3 = xap[x] << 5 \*/
	movd %eax, %mm3
	punpcklwd %mm3, %mm3
	punpckldq %mm3, %mm3
	
	/*\ p + 1 \*/
	movl %esi, %eax
	addl $4, %eax
	/*\ vv = (*p * My) >> 10 \*/
	movd (%eax), %mm2
	punpcklbw %mm7, %mm2
	psllw $6, %mm2
	pmulhw %mm5, %mm2
	
	/*\ i = 0x4000 - My \*/
	movl $0x4000, %ebx
	subl My, %ebx
	jbe 5f
	jmp 2f
1:
	/*\ p += sow; vv += (*p * Cy) >> 10 \*/
	addl sow_4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm4, %mm1
	paddw %mm1, %mm2
	
	/*\ i -= Cy; while (i > Cy) \*/
	subl Cy, %ebx
2:
	cmpl Cy, %ebx
	jg 1b
	
	/*\ p += sow; v += (*p * i) >> 10 \*/
	addl sow_4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm6, %mm1
	paddw %mm1, %mm2
5:
	/*\ v = v + (vv - v) * xap \*/
	psubw %mm0, %mm2
	psllw $3, %mm2
	pmulhw %mm3, %mm2
	paddw %mm2, %mm0
6:
	/*\ dest[x] = v >> 4 \*/
	psrlw $4, %mm0
	packuswb %mm0, %mm0
	movd %mm0, (%edi, %ecx, 4)

	/*\ while (++x) \*/
	incl %ecx
	jnz .up_down_loop_x

	/*\ dptr += dow \*/
	movl dow, %eax
	leal (%edi, %eax, 4), %edi
	/*\ yap++; yp++ \*/
	addl $4, yap
	addl $4, yp
	/*\ while (y--) \*/
	decl y
	jnz .up_down_loop_y

	jmp .scale_leave

.scale_x_down:
	/*\ Test yup bit \*/
	sarl $1, %eax
	jnc .scale_x_down_y_down


/*\ Scaling down horizontally \*/

.scale_x_down_y_up:
	/*\ sow_4 = sow * 4 \*/
	movl sow, %eax
	sall $2, %eax
	movl %eax, sow_4

.down_up_loop_y:

	/*\ %eax = *yap << 5 \*/
	movl yap, %eax
	movl (%eax), %eax
	sall $5, %eax
	/*\ mm3 = *yap << 5 \*/
	movd %eax, %mm3
	punpcklwd %mm3, %mm3
	punpckldq %mm3, %mm3
	
	/*\ x = -dw \*/
	movl dw, %ecx
	negl %ecx
.down_up_loop_x:
	/*\ %esi = *yp + xp[x] \*/
	movl yp, %eax
	movl (%eax), %esi
	movl xp, %eax
	movl (%eax, %ecx, 4), %eax
	leal (%esi, %eax, 4), %esi

	/*\ Setup Mx and Cx \*/
	movl xap, %eax
	movzwl (%eax, %ecx, 4), %ebx
	movl %ebx, Mx
	movzwl 2(%eax, %ecx, 4), %eax
	movl %eax, Cx

	/*\ mm4 = Cx \*/
	movd %eax, %mm4
	punpcklwd %mm4, %mm4
	punpckldq %mm4, %mm4
	/*\ mm5 = Mx \*/
	movd %ebx, %mm5
	punpcklwd %mm5, %mm5
	punpckldq %mm5, %mm5

	movl %esi, %eax
	/*\ v = (*p * Mx) >> 10 \*/
	movd (%eax), %mm0
	punpcklbw %mm7, %mm0
	psllw $6, %mm0
	pmulhw %mm5, %mm0
	
	/*\ i = 0x4000 - Mx \*/
	movl $0x4000, %ebx
	subl Mx, %ebx
	jbe 5f
	jmp 2f
1:
	/*\ p += sow; v += (*p * Cx) >> 10 \*/
	addl $4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm4, %mm1
	paddw %mm1, %mm0
	
	/*\ i -= Cx; while (i > Cx) \*/
	subl Cx, %ebx
2:
	cmpl Cx, %ebx
	jg 1b
	
	/*\ mm6 = i \*/
	movd %ebx, %mm6
	punpcklwd %mm6, %mm6
	punpckldq %mm6, %mm6
	
	/*\ p += sow; v += (*p * i) >> 10 \*/
	addl $4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm6, %mm1
	paddw %mm1, %mm0
5:
	movd %mm3, %eax
	testl %eax, %eax
	jz 6f
	/*\ p + sow \*/
	movl %esi, %eax
	addl sow_4, %eax
	/*\ vv = (*p * Mx) >> 10 \*/
	movd (%eax), %mm2
	punpcklbw %mm7, %mm2
	psllw $6, %mm2
	pmulhw %mm5, %mm2
	
	/*\ i = 0x4000 - Mx \*/
	movl $0x4000, %ebx
	subl Mx, %ebx
	jbe 5f
	jmp 2f
1:
	/*\ p += sow; vv += (*p * Cx) >> 10 \*/
	addl $4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm4, %mm1
	paddw %mm1, %mm2
	
	/*\ i -= Cx; while (i > Cx) \*/
	subl Cx, %ebx
2:
	cmpl Cx, %ebx
	jg 1b
	
	/*\ p += sow; v += (*p * i) >> 10 \*/
	addl $4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $6, %mm1
	pmulhw %mm6, %mm1
	paddw %mm1, %mm2
5:
	/*\ v = v + (vv - v) * yap \*/
	psubw %mm0, %mm2
	psllw $3, %mm2
	pmulhw %mm3, %mm2
	paddw %mm2, %mm0
6:
	/*\ dest[x] = v >> 4 \*/
	psrlw $4, %mm0
	packuswb %mm0, %mm0
	movd %mm0, (%edi, %ecx, 4)

	/*\ while (++x) \*/
	incl %ecx
	jnz .down_up_loop_x

	/*\ dptr += dow \*/
	movl dow, %eax
	leal (%edi, %eax, 4), %edi
	/*\ yap++; yp++ \*/
	addl $4, yap
	addl $4, yp
	/*\ while (y--) \*/
	decl y
	jnz .down_up_loop_y

	jmp .scale_leave


/*\ Scaling down both ways \*/

.scale_x_down_y_down:
	/*\ sow_4 = sow * 4 \*/
	movl sow, %eax
	sall $2, %eax
	movl %eax, sow_4

.down_down_loop_y:

	/*\ Setup My and Cy \*/
	movl yap, %eax
	movzwl (%eax), %ebx
	movl %ebx, My
	movzwl 2(%eax), %eax
	movl %eax, Cy

	/*\ x = -dw \*/
	movl dw, %ecx
	negl %ecx
.down_down_loop_x:
	/*\ %esi = *yp + xp[x] \*/
	movl yp, %eax
	movl (%eax), %esi
	movl xp, %eax
	movl (%eax, %ecx, 4), %eax
	leal (%esi, %eax, 4), %esi

	/*\ Setup Mx and Cx \*/
	movl xap, %eax
	movzwl (%eax, %ecx, 4), %ebx
	movl %ebx, Mx
	movzwl 2(%eax, %ecx, 4), %eax
	movl %eax, Cx

	/*\ mm3 = Cx \*/
	movd %eax, %mm3
	punpcklwd %mm3, %mm3
	punpckldq %mm3, %mm3
	/*\ mm5 = Mx \*/
	movd %ebx, %mm5
	punpcklwd %mm5, %mm5
	punpckldq %mm5, %mm5
	
	/*\ p = sptr; v = (*p * Mx) >> 9 \*/
	movl %esi, %eax
	movd (%eax), %mm0
	punpcklbw %mm7, %mm0
	psllw $7, %mm0
	pmulhw %mm5, %mm0
	
	/*\ i = 0x4000 - Mx \*/
	movl $0x4000, %ebx
	subl Mx, %ebx
	jbe 5f
	jmp 2f
1:
	/*\ v += (*++p * Cx) >> 9 \*/
	addl $4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $7, %mm1
	pmulhw %mm3, %mm1
	paddw %mm1, %mm0
	
	/*\ i -= Cx; while (i > Cx) \*/
	subl Cx, %ebx
2:
	cmpl Cx, %ebx
	jg 1b
	
	/*\ mm6 = i \*/
	movd %ebx, %mm6
	punpcklwd %mm6, %mm6
	punpckldq %mm6, %mm6
	
	/*\ v += (*++p * i) >> 9 \*/
	addl $4, %eax
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $7, %mm1
	pmulhw %mm6, %mm1
	paddw %mm1, %mm0
5:
	/*\ v *= My \*/
	movd My, %mm4
	punpcklwd %mm4, %mm4
	punpckldq %mm4, %mm4
	psllw $2, %mm0
	pmulhw %mm4, %mm0
	
	/*\ j = 0x4000 - My \*/
	movl $0x4000, %edx
	subl My, %edx
	jbe 6f
	jmp 4f
3:
	/*\ sptr += sow; p = sptr \*/
	addl sow_4, %esi
	movl %esi, %eax
	/*\ vx = (*p * Mx) >> 9 \*/
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $7, %mm1
	pmulhw %mm5, %mm1
	
	/*\ i = 0x4000 - Mx \*/
	movl $0x4000, %ebx
	subl Mx, %ebx
	jbe 5f
	jmp 2f
1:
	/*\ vx += (*++p * Cx) >> 9 \*/
	addl $4, %eax
	movd (%eax), %mm2
	punpcklbw %mm7, %mm2
	psllw $7, %mm2
	pmulhw %mm3, %mm2
	paddw %mm2, %mm1
	
	/*\ i -= Cx; while (i > Cx) \*/
	subl Cx, %ebx
2:
	cmpl Cx, %ebx
	jg 1b
	
	/*\ vx += (*++p * i) >> 9 \*/
	addl $4, %eax
	movd (%eax), %mm2
	punpcklbw %mm7, %mm2
	psllw $7, %mm2
	pmulhw %mm6, %mm2
	paddw %mm2, %mm1
5:
	/*\ v += (vx * Cy) >> 14 \*/
	movd Cy, %mm4
	punpcklwd %mm4, %mm4
	punpckldq %mm4, %mm4
	psllw $2, %mm1
	pmulhw %mm4, %mm1
	paddw %mm1, %mm0
	
	/*\ j -= Cy; while (j > Cy) \*/
	subl Cy, %edx
4:
	cmpl Cy, %edx
	jg 3b
	
	/*\ sptr += sow; p = sptr \*/
	addl sow_4, %esi
	movl %esi, %eax
	/*\ vx = (*p * Mx) >> 9 \*/
	movd (%eax), %mm1
	punpcklbw %mm7, %mm1
	psllw $7, %mm1
	pmulhw %mm5, %mm1
	
	/*\ i = 0x4000 - Mx \*/
	movl $0x4000, %ebx
	subl Mx, %ebx
	jbe 5f
	jmp 2f
1:
	/*\ vx += (*++p * Cx) >> 9 \*/
	addl $4, %eax
	movd (%eax), %mm2
	punpcklbw %mm7, %mm2
	psllw $7, %mm2
	pmulhw %mm3, %mm2
	paddw %mm2, %mm1
	
	/*\ i -= Cx; while (i > Cx) \*/
	subl Cx, %ebx
2:
	cmpl Cx, %ebx
	jg 1b
	
	/*\ vx += (*++p * i) >> 9 \*/
	addl $4, %eax
	movd (%eax), %mm2
	punpcklbw %mm7, %mm2
	psllw $7, %mm2
	pmulhw %mm6, %mm2
	paddw %mm2, %mm1
5:
	/*\ v += (vx * j) >> 14 \*/
	movd %edx, %mm4
	punpcklwd %mm4, %mm4
	punpckldq %mm4, %mm4
	psllw $2, %mm1
	pmulhw %mm4, %mm1
	paddw %mm1, %mm0
6:
	/*\ dptr[x] = mm0 >> 5 \*/
	psrlw $5, %mm0
	packuswb %mm0, %mm0
	movd %mm0, (%edi, %ecx, 4)

	/*\ while (++x) \*/
	incl %ecx
	jnz .down_down_loop_x

	/*\ dptr += dow \*/
	movl dow, %eax
	leal (%edi, %eax, 4), %edi
	/*\ yap++; yp++ \*/
	addl $4, yap
	addl $4, yp
	/*\ while (y--) \*/
	decl y
	jnz .down_down_loop_y

	jmp .scale_leave

.scale_leave:
	emms
	popl %esi
	popl %edi
	popl %edx
	popl %ecx
	popl %ebx
	movl %ebp, %esp
	popl %ebp
	ret

SIZE(mimageScale_mmx_AARGBA)

#endif

.section	.note.GNU-stack,"",%progbits