! C1V2 hot kernels in SH-2 assembly: the IDCT and the YCbCr -> RGB555 conversion. ! Both compute exactly what c1dec.c's C versions compute (r32x/c1.py is the spec). ! ! c1_fast_t layout (c1dec.h; c1dec.c checks the offsets with _Static_assert): ! +0 int16 tT[64] IDCT pass 1, transposed: tT[c*8 + u] (the C build uses int32 t) ! +256 int32 res[64] IDCT output, res[y*8 + c] ! +512 int16 coef[64] coefficients X[u*8 + v] ! +768 int16 kt[64] the basis transposed: kt[c*8 + v] = K[v][c] ! +1024 conversion tables (CONV_*), see c1_conv_mb .section .sdram_text,"ax",@progbits ! --------------------------------------------------------------------------------- ! void c1_idct_mac(c1_fast_t *f, int rows, int cols) r4 = f, r5 = rows, r6 = cols ! ! Pass 1, u < rows, every c: tT[c*8+u] = (2048 + sum_{v> 12 ! Pass 2, every y and c: res[y*8+c] = (2048 + sum_{u> 12 ! (kt[y*8+u] = K[u][y].) Each sum is a run of MAC.W @Rm+,@Rn+ entered with BRAF so that ! exactly n MACs run, n = cols or rows. |X| < 2400 so |tT| < 13.6k fits 16 bits, and the ! sums fit MACL (32 bits). >> 12 is arithmetic: ((x ^ 0x80000000) >>> 12) - 0x80000. ! --------------------------------------------------------------------------------- .align 2 .global _c1_idct_mac _c1_idct_mac: mov.l r8,@-r15 mov.l r9,@-r15 mov.l r10,@-r15 mov.l r11,@-r15 mov.l r12,@-r15 mov.l r13,@-r15 mov.l r14,@-r15 mov.l .Li2048,r9 mov.l .Lisign,r10 mov.l .Libias,r11 mov #8,r0 sub r5,r0 add r0,r0 mov.l r0,@-r15 ! pass 2's BRAF offset: (8 - rows) * 2 mov #8,r0 sub r6,r0 add r0,r0 mov r0,r6 ! pass 1's BRAF offset: (8 - cols) * 2 mov.w .Li512,r12 add r4,r12 ! r12 = &X[u*8] mov.w .Li768,r13 add r4,r13 ! r13 = kt mov r4,r14 ! r14 = &tT[u] .Lp1u: mov r13,r2 ! &kt[c*8] mov r14,r8 ! &tT[c*8 + u] mov #8,r7 .Lp1c: mov r12,r1 mov r2,r3 clrmac mov r6,r0 braf r0 nop mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ sts macl,r0 add r9,r0 xor r10,r0 shlr8 r0 shlr2 r0 shlr2 r0 add r11,r0 mov.w r0,@r8 add #16,r8 dt r7 bf/s .Lp1c add #16,r2 add #16,r12 dt r5 bf/s .Lp1u add #2,r14 mov.l @r15+,r6 ! pass 2's offset mov.w .Li256,r8 add r4,r8 ! r8 = &res[0] mov #8,r5 ! y .Lp2y: mov r4,r2 ! &tT[c*8] mov #8,r7 .Lp2c: mov r13,r1 ! &kt[y*8] mov r2,r3 clrmac mov r6,r0 braf r0 nop mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ mac.w @r1+,@r3+ sts macl,r0 add r9,r0 xor r10,r0 shlr8 r0 shlr2 r0 shlr2 r0 add r11,r0 mov.l r0,@r8 add #4,r8 dt r7 bf/s .Lp2c add #16,r2 dt r5 bf/s .Lp2y add #16,r13 mov.l @r15+,r14 mov.l @r15+,r13 mov.l @r15+,r12 mov.l @r15+,r11 mov.l @r15+,r10 mov.l @r15+,r9 rts mov.l @r15+,r8 .align 1 .Li512: .short 512 .Li768: .short 768 .Li256: .short 256 .align 2 .Li2048: .long 2048 .Lisign: .long 0x80000000 .Libias: .long 0xFFF80000 ! --------------------------------------------------------------------------------- ! void c1_conv_mb(const uint8_t *y, const uint8_t *cb, const uint8_t *cr, ! volatile uint32_t *dst, const uint8_t *tabs) ! r4 = y (the MB's top-left, stride 320), r5 = cb, r6 = cr (stride 160), ! r7 = dst (frame buffer words, stride 640 bytes), @r15 = tabs: ! tabs + 0 uint8 cl5[768] clip to 0-255 then 5 bits, index v + 256 ! tabs + 768 int32 cbT[256] (BCB[u] << 16) | (GCB[u] & 0xFFFF) ! tabs + 1792 int32 crT[256] (RCR[v] << 16) | (GCR[v] & 0xFFFF) ! Per 2x2: tr = cl5 + 256 + RCR, tg = ... + GCB + GCR, tb = ... + BCB; each pixel is ! tr[y] | tg[y] << 5 | tb[y] << 10, two pixels per longword (big-endian: left first). ! --------------------------------------------------------------------------------- .align 2 .global _c1_conv_mb _c1_conv_mb: mov.l @r15,r0 ! tabs mov.l r8,@-r15 mov.l r9,@-r15 mov.l r10,@-r15 mov.l r11,@-r15 mov.l r12,@-r15 mov.l r13,@-r15 mov.l r14,@-r15 mov.w .Lc256,r8 add r0,r8 ! r8 = cl5 + 256 mov.w .Lc768,r9 add r0,r9 ! r9 = cbT mov.w .Lc1792,r10 add r0,r10 ! r10 = crT mov #8,r0 mov.l r0,@-r15 ! row pairs left .Lcrow: mov #8,r11 ! 2x2 blocks left in this row pair .Lcblk: mov.b @r5+,r0 extu.b r0,r0 shll2 r0 mov.l @(r0,r9),r12 ! cbT[u] mov.b @r6+,r0 extu.b r0,r0 shll2 r0 mov.l @(r0,r10),r13 ! crT[v] exts.w r12,r2 exts.w r13,r0 add r0,r2 add r8,r2 ! tg swap.w r12,r3 exts.w r3,r3 add r8,r3 ! tb swap.w r13,r1 exts.w r1,r1 add r8,r1 ! tr ! pixel (0, 0) mov.b @r4,r0 extu.b r0,r0 mov.b @(r0,r2),r12 mov.b @(r0,r3),r13 shll2 r12 shll8 r13 shll2 r12 shll2 r13 shll r12 or r13,r12 mov.b @(r0,r1),r13 or r13,r12 mov r12,r14 shll16 r14 ! pixel (0, 1) mov.b @(1,r4),r0 extu.b r0,r0 mov.b @(r0,r2),r12 mov.b @(r0,r3),r13 shll2 r12 shll8 r13 shll2 r12 shll2 r13 shll r12 or r13,r12 mov.b @(r0,r1),r13 or r13,r12 or r12,r14 mov.l r14,@r7 ! pixel (1, 0) mov.w .Lc320,r0 mov.b @(r0,r4),r0 extu.b r0,r0 mov.b @(r0,r2),r12 mov.b @(r0,r3),r13 shll2 r12 shll8 r13 shll2 r12 shll2 r13 shll r12 or r13,r12 mov.b @(r0,r1),r13 or r13,r12 mov r12,r14 shll16 r14 ! pixel (1, 1) mov.w .Lc321,r0 mov.b @(r0,r4),r0 extu.b r0,r0 mov.b @(r0,r2),r12 mov.b @(r0,r3),r13 shll2 r12 shll8 r13 shll2 r12 shll2 r13 shll r12 or r13,r12 mov.b @(r0,r1),r13 or r13,r12 or r12,r14 mov.w .Lc640,r0 mov.l r14,@(r0,r7) add #2,r4 dt r11 bf/s .Lcblk add #4,r7 mov.w .Lc624,r0 ! next row pair: y += 640 - 16 add r0,r4 mov.w .Lc1248,r0 ! dst += 1280 - 32 add r0,r7 mov.w .Lc152,r0 ! chroma += 160 - 8 add r0,r5 add r0,r6 mov.l @r15,r0 dt r0 bf/s .Lcrow mov.l r0,@r15 add #4,r15 mov.l @r15+,r14 mov.l @r15+,r13 mov.l @r15+,r12 mov.l @r15+,r11 mov.l @r15+,r10 mov.l @r15+,r9 rts mov.l @r15+,r8 .align 1 .Lc256: .short 256 .Lc768: .short 768 .Lc1792: .short 1792 .Lc320: .short 320 .Lc321: .short 321 .Lc640: .short 640 .Lc624: .short 624 .Lc1248: .short 1248 .Lc152: .short 152 .align 2