Speed up YUV blitting on iPod Video by ~8% (FS #8075 by Andree Buschmann).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15820 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
727ada0ad2
commit
120fb4f319
2 changed files with 157 additions and 149 deletions
|
@ -19,6 +19,12 @@
|
|||
|
||||
.section .icode, "ax", %progbits
|
||||
|
||||
/****************************************************************************
|
||||
* void lcd_write_data(const fb_data *addr,
|
||||
* int pixelcount);
|
||||
*
|
||||
* Writes pixelcount pixels from src-pointer (lcd_framebuffer) to BCM dataport.
|
||||
*/
|
||||
.align 2
|
||||
.global lcd_write_data
|
||||
.type lcd_write_data, %function
|
||||
|
@ -51,35 +57,60 @@ lcd_write_data: /* r1 = pixel count, must be even */
|
|||
bx lr
|
||||
|
||||
/****************************************************************************
|
||||
* void lcd_write_yuv_420_upper(unsigned char const * const src[3],
|
||||
* unsigned char *croma_buf, int width);
|
||||
* extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
|
||||
* unsigned bcmaddr
|
||||
* int width,
|
||||
* int stride);
|
||||
*
|
||||
* void lcd_write_yuv_420_lower(unsigned char *y_src,
|
||||
* unsigned char *croma_buf, int width);
|
||||
* Conversion from Motion JPEG and MPEG Y'PbPr to RGB is:
|
||||
* |R| |1.164 0.000 1.596| |Y' - 16|
|
||||
* |G| = |1.164 -0.391 -0.813| |Pb - 128|
|
||||
* |B| |1.164 2.018 0.000| |Pr - 128|
|
||||
*
|
||||
* |R| |1.000000 -0.000001 1.402000| |Y'|
|
||||
* |G| = |1.000000 -0.334136 -0.714136| |Pb|
|
||||
* |B| |1.000000 1.772000 0.000000| |Pr|
|
||||
* Scaled, normalized, rounded and tweaked to yield RGB 565:
|
||||
* |R| |74 0 101| |Y' - 16| >> 9
|
||||
* |G| = |74 -24 -51| |Cb - 128| >> 8
|
||||
* |B| |74 128 0| |Cr - 128| >> 9
|
||||
*
|
||||
* Converts two lines from YUV to RGB565 and writes to BCM at once. First loop
|
||||
* loads Cb/Cr, calculates the chroma offset and saves them to buffer. Within
|
||||
* the second loop these chroma offset are reloaded from buffer.
|
||||
* Within each loop two pixels are calculated and written to BCM. Before each
|
||||
* loop the desired destination address is transmitted to BCM.
|
||||
*/
|
||||
.align 2
|
||||
.global lcd_write_yuv420_upper
|
||||
.type lcd_write_yuv420_upper, %function
|
||||
lcd_write_yuv420_upper:
|
||||
/* r0 = yuv_src */
|
||||
/* r1 = chroma buffer */
|
||||
.global lcd_write_yuv420_lines
|
||||
.type lcd_write_yuv420_lines, %function
|
||||
lcd_write_yuv420_lines:
|
||||
/* r0 = src = yuv_src */
|
||||
/* r1 = dst = bcmaddr */
|
||||
/* r2 = width */
|
||||
/* r3 = stride */
|
||||
stmfd sp!, { r4-r12 } /* save non-scratch */
|
||||
ldmia r0, { r10, r11, r12 } /* r10 = yuv_src[0] = Y'_p */
|
||||
ldmia r0, { r10-r12 } /* r10 = yuv_src[0] = Y'_p */
|
||||
/* r11 = yuv_src[1] = Cb_p */
|
||||
/* r12 = yuv_src[2] = Cr_p */
|
||||
add r3, r10, r3 /* r3 = &ysrc[stride] */
|
||||
add r4, r2, r2, asr #1 /* chroma buffer lenght = width/2 *3 */
|
||||
mov r4, r4, asl #2 /* use words for str/ldm possibility */
|
||||
add r4, r4, #19 /* plus room for 4 additional words, */
|
||||
bic r4, r4, #3 /* rounded up to multiples of 4 byte */
|
||||
sub sp, sp, r4 /* and allocate on stack */
|
||||
stmia sp, {r1-r4} /* bcmaddr, width, &ysrc[stride], stack_alloc */
|
||||
|
||||
mov r7, r2 /* r7 = loop count */
|
||||
mov r8, r1 /* chroma buffer */
|
||||
add r8, sp, #16 /* chroma buffer */
|
||||
mov r9, #0x30000000 /* LCD data port */
|
||||
|
||||
/* The following writes dest address to BCM and waits for write ready */
|
||||
orr r2, r9, #0x00010000 /* r2 = BCM_WR_ADDR32 */
|
||||
orr r6, r9, #0x00030000 /* r6 = BCM_CONTROL */
|
||||
str r1, [r2] /* BCM_WR_ADDR32 = bcmaddr */
|
||||
.busy_1:
|
||||
ldrh r1, [r6] /* while (!(BCM_CONTROL & 0x2)) */
|
||||
tst r1, #0x2
|
||||
beq .busy_1
|
||||
|
||||
/* 1st loop start */
|
||||
10: /* loop start */
|
||||
|
||||
|
@ -89,10 +120,10 @@ lcd_write_yuv420_upper:
|
|||
sub r0, r0, #128 /* r0 = Cb-128 */
|
||||
sub r1, r1, #128 /* r1 = Cr-128 */
|
||||
|
||||
add r3, r1, r1, asl #1 /* r3 = Cr*51 + Cb*24 */
|
||||
add r3, r3, r3, asl #4
|
||||
add r3, r3, r0, asl #3
|
||||
add r3, r3, r0, asl #4
|
||||
add r2, r1, r1, asl #1 /* r2 = Cr*51 + Cb*24 */
|
||||
add r2, r2, r2, asl #4
|
||||
add r2, r2, r0, asl #3
|
||||
add r2, r2, r0, asl #4
|
||||
|
||||
add r4, r1, r1, asl #2 /* r1 = Cr*101 */
|
||||
add r4, r4, r1, asl #5
|
||||
|
@ -100,166 +131,165 @@ lcd_write_yuv420_upper:
|
|||
|
||||
add r1, r1, #256 /* r1 = rv = (r1 + 256) >> 9 */
|
||||
mov r1, r1, asr #9
|
||||
strb r1, [r8], #1 /* store r1 to chroma_buf */
|
||||
rsb r3, r3, #128 /* r3 = guv = (-r3 + 128) >> 8 */
|
||||
mov r3, r3, asr #8
|
||||
strb r3, [r8], #1 /* store r3 to chroma_buf */
|
||||
rsb r2, r2, #128 /* r2 = guv = (-r2 + 128) >> 8 */
|
||||
mov r2, r2, asr #8
|
||||
add r0, r0, #2 /* r0 = bu = (Cb*128 + 256) >> 9 */
|
||||
mov r0, r0, asr #2
|
||||
strb r0, [r8], #1 /* store r0 to chroma_buf */
|
||||
stmia r8!, {r0-r2} /* store r0, r1 and r2 to chroma buffer */
|
||||
|
||||
/* 1st loop, first pixel */
|
||||
ldrb r5, [r10], #1 /* r5 = *ysrc++ = *Y'_p++ */
|
||||
sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
|
||||
add r2, r5, r5, asl #2
|
||||
add r5, r2, r5, asl #5
|
||||
add r3, r5, r5, asl #2
|
||||
add r5, r3, r5, asl #5
|
||||
|
||||
add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
|
||||
add r2, r3, r5, asr #7 /* r2 = g = (Y >> 8) + guv */
|
||||
add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
|
||||
add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
|
||||
|
||||
orr r5, r6, r4 /* check if clamping is needed... */
|
||||
orr r5, r5, r2, asr #1 /* ...at all */
|
||||
orr r5, r5, r3, asr #1 /* ...at all */
|
||||
cmp r5, #31
|
||||
bls 15f /* -> no clamp */
|
||||
cmp r6, #31 /* clamp r */
|
||||
mvnhi r6, r6, asr #31
|
||||
andhi r6, r6, #31
|
||||
cmp r2, #63 /* clamp g */
|
||||
mvnhi r2, r2, asr #31
|
||||
andhi r2, r2, #63
|
||||
cmp r3, #63 /* clamp g */
|
||||
mvnhi r3, r3, asr #31
|
||||
andhi r3, r3, #63
|
||||
cmp r4, #31 /* clamp b */
|
||||
mvnhi r4, r4, asr #31
|
||||
andhi r4, r4, #31
|
||||
15: /* no clamp */
|
||||
|
||||
orr r4, r4, r2, lsl #5 /* pixel = r<<11 | g<<5 | b */
|
||||
orr r4, r4, r6, lsl #11
|
||||
strh r4, [r9] /* write pixel */
|
||||
/* calculate pixel_1 and save to r5 for later pixel packing */
|
||||
orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */
|
||||
orr r5, r4, r6, lsl #11 /* r5 = pixel_1 */
|
||||
|
||||
/* 1st loop, second pixel */
|
||||
ldrb r5, [r10], #1 /* r5 = *ysrc++ = *Y'_p++ */
|
||||
sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
|
||||
add r2, r5, r5, asl #2
|
||||
add r5, r2, r5, asl #5
|
||||
ldrb r4, [r10], #1 /* r4 = *ysrc++ = *Y'_p++ */
|
||||
sub r4, r4, #16 /* r4 = (Y'-16) * 74 */
|
||||
add r3, r4, r4, asl #2
|
||||
add r4, r3, r4, asl #5
|
||||
|
||||
add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
|
||||
add r2, r3, r5, asr #7 /* r2 = g = (Y >> 8) + guv */
|
||||
add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
|
||||
add r6, r1, r4, asr #8 /* r6 = r = (Y >> 9) + rv */
|
||||
add r3, r2, r4, asr #7 /* r3 = g = (Y >> 8) + guv */
|
||||
add r4, r0, r4, asr #8 /* r4 = b = (Y >> 9) + bu */
|
||||
|
||||
orr r5, r6, r4 /* check if clamping is needed... */
|
||||
orr r5, r5, r2, asr #1 /* ...at all */
|
||||
cmp r5, #31
|
||||
orr r0, r6, r4 /* check if clamping is needed... */
|
||||
orr r0, r0, r3, asr #1 /* ...at all */
|
||||
cmp r0, #31
|
||||
bls 15f /* -> no clamp */
|
||||
cmp r6, #31 /* clamp r */
|
||||
mvnhi r6, r6, asr #31
|
||||
andhi r6, r6, #31
|
||||
cmp r2, #63 /* clamp g */
|
||||
mvnhi r2, r2, asr #31
|
||||
andhi r2, r2, #63
|
||||
cmp r3, #63 /* clamp g */
|
||||
mvnhi r3, r3, asr #31
|
||||
andhi r3, r3, #63
|
||||
cmp r4, #31 /* clamp b */
|
||||
mvnhi r4, r4, asr #31
|
||||
andhi r4, r4, #31
|
||||
15: /* no clamp */
|
||||
|
||||
orr r4, r4, r2, lsl #5 /* pixel = r<<11 | g<<5 | b */
|
||||
orr r4, r4, r6, lsl #11
|
||||
strh r4, [r9] /* write pixel */
|
||||
/* calculate pixel_2 and pack with pixel_1 before writing */
|
||||
orr r4, r4, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */
|
||||
orr r4, r4, r6, lsl #11 /* r4 = pixel_2 */
|
||||
orr r4, r5, r4, lsl #16 /* r4 = pixel_2<<16 | pixel_1 */
|
||||
str r4, [r9] /* write packed pixels */
|
||||
|
||||
subs r7, r7, #2 /* check for loop end */
|
||||
bgt 10b /* back to beginning */
|
||||
/* 1st loop end */
|
||||
|
||||
ldmfd sp!, { r4-r12 } /* restore registers */
|
||||
bx lr
|
||||
/* Reload several registers for pointer rewinding for next loop */
|
||||
add r8, sp, #16 /* chroma buffer */
|
||||
ldmia sp, { r1, r7, r10} /* r1 = bcmaddr */
|
||||
/* r7 = loop count */
|
||||
/* r10 = &ysrc[stride] */
|
||||
|
||||
.ltorg
|
||||
.size lcd_write_yuv420_upper, .-lcd_write_yuv420_upper
|
||||
/* The following writes dest address to BCM and waits for write ready */
|
||||
orr r2, r9, #0x00010000 /* r2 = BCM_WR_ADDR32 */
|
||||
orr r6, r9, #0x00030000 /* r6 = BCM_CONTROL */
|
||||
add r1, r1, #640 /* dst += (LCD_WIDTH*2) */
|
||||
str r1, [r2] /* BCM_WR_ADDR32 = dst */
|
||||
.busy_2:
|
||||
ldrh r1, [r6] /* while (!(BCM_CONTROL & 0x2)) */
|
||||
tst r1, #0x2
|
||||
beq .busy_2
|
||||
|
||||
|
||||
.align 2
|
||||
.global lcd_write_yuv420_lower
|
||||
.type lcd_write_yuv420_lower, %function
|
||||
lcd_write_yuv420_lower:
|
||||
/* r0 = y_src */
|
||||
/* r1 = croma buf */
|
||||
/* r2 = width */
|
||||
stmfd sp!, { r4-r10 } /* save non-scratch */
|
||||
mov r10, r0 /* r10 = y_src */
|
||||
mov r7, r2 /* r7 = loop count */
|
||||
mov r8, r1 /* chroma buffer */
|
||||
mov r9, #0x30000000 /* LCD data port */
|
||||
|
||||
/* 2nd loop start */
|
||||
20: /* loop start */
|
||||
|
||||
/* restore r1, r3 and r0 from chroma buffer */
|
||||
ldrsb r1, [r8], #1
|
||||
ldrsb r3, [r8], #1
|
||||
ldrsb r0, [r8], #1
|
||||
/* restore r0 (bu), r1 (rv) and r2 (guv) from chroma buffer */
|
||||
ldmia r8!, {r0-r2}
|
||||
|
||||
/* 2nd loop, first pixel */
|
||||
ldrb r5, [r10], #1 /* r5 = *ysrc++ = *Y'_p++ */
|
||||
sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
|
||||
add r2, r5, r5, asl #2
|
||||
add r5, r2, r5, asl #5
|
||||
add r3, r5, r5, asl #2
|
||||
add r5, r3, r5, asl #5
|
||||
|
||||
add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
|
||||
add r2, r3, r5, asr #7 /* r2 = g = (Y >> 8) + guv */
|
||||
add r3, r2, r5, asr #7 /* r3 = g = (Y >> 8) + guv */
|
||||
add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
|
||||
|
||||
orr r5, r6, r4 /* check if clamping is needed... */
|
||||
orr r5, r5, r2, asr #1 /* ...at all */
|
||||
orr r5, r5, r3, asr #1 /* ...at all */
|
||||
cmp r5, #31
|
||||
bls 15f /* -> no clamp */
|
||||
cmp r6, #31 /* clamp r */
|
||||
mvnhi r6, r6, asr #31
|
||||
andhi r6, r6, #31
|
||||
cmp r2, #63 /* clamp g */
|
||||
mvnhi r2, r2, asr #31
|
||||
andhi r2, r2, #63
|
||||
cmp r3, #63 /* clamp g */
|
||||
mvnhi r3, r3, asr #31
|
||||
andhi r3, r3, #63
|
||||
cmp r4, #31 /* clamp b */
|
||||
mvnhi r4, r4, asr #31
|
||||
andhi r4, r4, #31
|
||||
15: /* no clamp */
|
||||
|
||||
orr r4, r4, r2, lsl #5 /* pixel = r<<11 | g<<5 | b */
|
||||
orr r4, r4, r6, lsl #11
|
||||
strh r4, [r9] /* write pixel */
|
||||
/* calculate pixel_1 and save to r5 for later pixel packing */
|
||||
orr r4, r4, r3, lsl #5 /* pixel_1 = r<<11 | g<<5 | b */
|
||||
orr r5, r4, r6, lsl #11 /* r5 = pixel_1 */
|
||||
|
||||
/* 2nd loop, second pixel */
|
||||
ldrb r5, [r10], #1 /* r5 = *ysrc++ = *Y'_p++ */
|
||||
sub r5, r5, #16 /* r5 = (Y'-16) * 74 */
|
||||
add r2, r5, r5, asl #2
|
||||
add r5, r2, r5, asl #5
|
||||
ldrb r4, [r10], #1 /* r4 = *ysrc++ = *Y'_p++ */
|
||||
sub r4, r4, #16 /* r4 = (Y'-16) * 74 */
|
||||
add r3, r4, r4, asl #2
|
||||
add r4, r3, r4, asl #5
|
||||
|
||||
add r6, r1, r5, asr #8 /* r6 = r = (Y >> 9) + rv */
|
||||
add r2, r3, r5, asr #7 /* r2 = g = (Y >> 8) + guv */
|
||||
add r4, r0, r5, asr #8 /* r4 = b = (Y >> 9) + bu */
|
||||
add r6, r1, r4, asr #8 /* r6 = r = (Y >> 9) + rv */
|
||||
add r3, r2, r4, asr #7 /* r3 = g = (Y >> 8) + guv */
|
||||
add r4, r0, r4, asr #8 /* r4 = b = (Y >> 9) + bu */
|
||||
|
||||
orr r5, r6, r4 /* check if clamping is needed... */
|
||||
orr r5, r5, r2, asr #1 /* ...at all */
|
||||
cmp r5, #31
|
||||
orr r0, r6, r4 /* check if clamping is needed... */
|
||||
orr r0, r0, r3, asr #1 /* ...at all */
|
||||
cmp r0, #31
|
||||
bls 15f /* -> no clamp */
|
||||
cmp r6, #31 /* clamp r */
|
||||
mvnhi r6, r6, asr #31
|
||||
andhi r6, r6, #31
|
||||
cmp r2, #63 /* clamp g */
|
||||
mvnhi r2, r2, asr #31
|
||||
andhi r2, r2, #63
|
||||
cmp r3, #63 /* clamp g */
|
||||
mvnhi r3, r3, asr #31
|
||||
andhi r3, r3, #63
|
||||
cmp r4, #31 /* clamp b */
|
||||
mvnhi r4, r4, asr #31
|
||||
andhi r4, r4, #31
|
||||
15: /* no clamp */
|
||||
|
||||
orr r4, r4, r2, lsl #5 /* pixel = r<<11 | g<<5 | b */
|
||||
orr r4, r4, r6, lsl #11
|
||||
strh r4, [r9] /* write pixel */
|
||||
/* calculate pixel_2 and pack with pixel_1 before writing */
|
||||
orr r4, r4, r3, lsl #5 /* pixel_2 = r<<11 | g<<5 | b */
|
||||
orr r4, r4, r6, lsl #11 /* r4 = pixel_2 */
|
||||
orr r4, r5, r4, lsl #16 /* r4 = pixel_2<<16 | pixel_1 */
|
||||
str r4, [r9] /* write packed pixels */
|
||||
|
||||
subs r7, r7, #2 /* check for loop end */
|
||||
bgt 20b /* back to beginning */
|
||||
/* 2nd loop end */
|
||||
|
||||
ldmfd sp!, { r4-r10 } /* restore registers */
|
||||
ldr r3, [sp, #12]
|
||||
add sp, sp, r3 /* deallocate buffer */
|
||||
ldmfd sp!, { r4-r12 } /* restore registers */
|
||||
bx lr
|
||||
|
||||
.ltorg
|
||||
.size lcd_write_yuv420_lower, .-lcd_write_yuv420_lower
|
||||
.size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines
|
||||
|
|
|
@ -312,11 +312,11 @@ void lcd_update(void)
|
|||
lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
|
||||
}
|
||||
|
||||
/* Line write helper functions for lcd_yuv_blit. Write two lines of yuv420. */
|
||||
extern void lcd_write_yuv420_upper(unsigned char const * const src[3],
|
||||
unsigned char *chroma_buf, int width);
|
||||
extern void lcd_write_yuv420_lower(unsigned const char *y_src,
|
||||
unsigned char *chroma_buf, int width);
|
||||
/* Line write helper function for lcd_yuv_blit. Writes two lines of yuv420. */
|
||||
extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
|
||||
unsigned bcmaddr,
|
||||
int width,
|
||||
int stride);
|
||||
|
||||
/* Performance function to blit a YUV bitmap directly to the LCD */
|
||||
void lcd_yuv_blit(unsigned char * const src[3],
|
||||
|
@ -326,7 +326,6 @@ void lcd_yuv_blit(unsigned char * const src[3],
|
|||
unsigned bcmaddr;
|
||||
off_t z;
|
||||
unsigned char const * yuv_src[3];
|
||||
unsigned char chroma_buf[3*width]; /* dynamic */
|
||||
|
||||
/* Sorry, but width and height must be >= 2 or else */
|
||||
width &= ~1;
|
||||
|
@ -342,36 +341,15 @@ void lcd_yuv_blit(unsigned char * const src[3],
|
|||
bcmaddr = BCM_FB_BASE + (LCD_WIDTH*2) * y + (x << 1);
|
||||
height >>= 1;
|
||||
|
||||
if (width == LCD_WIDTH)
|
||||
{
|
||||
bcm_write_addr(bcmaddr);
|
||||
do
|
||||
{
|
||||
lcd_write_yuv420_upper(yuv_src, chroma_buf, width);
|
||||
yuv_src[0] += stride;
|
||||
lcd_write_yuv420_lower(yuv_src[0], chroma_buf, width);
|
||||
yuv_src[0] += stride;
|
||||
lcd_write_yuv420_lines(yuv_src, bcmaddr, width, stride);
|
||||
bcmaddr += (LCD_WIDTH*4); /* Skip up two lines */
|
||||
yuv_src[0] += stride << 1;
|
||||
yuv_src[1] += stride >> 1; /* Skip down one chroma line */
|
||||
yuv_src[2] += stride >> 1;
|
||||
}
|
||||
while (--height > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
bcm_write_addr(bcmaddr);
|
||||
bcmaddr += (LCD_WIDTH*2);
|
||||
lcd_write_yuv420_upper(yuv_src, chroma_buf, width);
|
||||
yuv_src[0] += stride;
|
||||
bcm_write_addr(bcmaddr);
|
||||
bcmaddr += (LCD_WIDTH*2);
|
||||
lcd_write_yuv420_lower(yuv_src[0], chroma_buf, width);
|
||||
yuv_src[0] += stride;
|
||||
yuv_src[1] += stride >> 1; /* Skip down one chroma line */
|
||||
yuv_src[2] += stride >> 1;
|
||||
}
|
||||
while (--height > 0);
|
||||
}
|
||||
|
||||
lcd_unblock_and_update();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue