Here is a fast memcpy routine that is quite similar to what I use in Pocket Divx Decoder for
PocketMVP player (althought PDD uses 64bits mode).
Any developer who is still working with MIPS devices or wants to improve the performance of his app for them can use it for free.
The benefits of this code are great so long you take into consideration the following:
- It works about 2.5x faster if you´re copying a large buffer. However, while it will work on tiny buffers, it´ll be a lot slower than standard WCE memcpy on any movement of less than 32 bytes(with more than 32 will be much faster too). So it´s more suited for games and multimedia rather than 'boring' stuff.
- It won´t work with an uncached buffer. For the standard developer that means you can´t use this to drawn into the GAPI DRAM buffer** of the cassiopeia or directly into its framebuffer. Any buffer allocated with malloc or Virtualalloc (unless you have set the NOCACHE flag in the last function) will work flawlessly. Anyways I´d never use memcpy to copy to those kind of buffers.
** Unless you´re using the cached memory area of that GAPI buffer, that is, 0x8000D000. Due to conflicts with the Casio´s DMA controller, I wouldn´t do that. GAPI always return the non-cached memory address: 0xA000D000
I hope it helps.
Pedro Mateu - Pocket Divx Decoder developer[/code]
PocketMVP player (althought PDD uses 64bits mode).
Any developer who is still working with MIPS devices or wants to improve the performance of his app for them can use it for free.
The benefits of this code are great so long you take into consideration the following:
- It works about 2.5x faster if you´re copying a large buffer. However, while it will work on tiny buffers, it´ll be a lot slower than standard WCE memcpy on any movement of less than 32 bytes(with more than 32 will be much faster too). So it´s more suited for games and multimedia rather than 'boring' stuff.
- It won´t work with an uncached buffer. For the standard developer that means you can´t use this to drawn into the GAPI DRAM buffer** of the cassiopeia or directly into its framebuffer. Any buffer allocated with malloc or Virtualalloc (unless you have set the NOCACHE flag in the last function) will work flawlessly. Anyways I´d never use memcpy to copy to those kind of buffers.
** Unless you´re using the cached memory area of that GAPI buffer, that is, 0x8000D000. Due to conflicts with the Casio´s DMA controller, I wouldn´t do that. GAPI always return the non-cached memory address: 0xA000D000
- Code:
#ifdef MIPS
#define MEMCPY MIPS_memcpy
#else
#define MEMCPY memcpy
#endif
static void MIPS_memcpy(void *dst, const void *src, int size)
{
__asm(
"addi $8,$6,-32;" // Size-64
"bltz $8,bucle3;" // If it´s a small buffer, it´s not worth using cache ops.
"andi $9,$4,0xF;"
"beq $9,$0,bucle2;"
"bucle1:" // Loop until Dst buffer is 16-byte aligned
"lb $8,0($5);"
"sb $8,0($4);"
"addi $4,$4,1;"
"addi $5,$5,1;"
"addi $6,$6,-1;"
"andi $8,$4,0xF;"
"bne $8,$0,bucle1;"
"bucle2:" // Loop while nbytes to copy > 16
"ulw $8,0($5);"
"ulw $9,4($5);"
"ulw $10,8($5);"
"ulw $11,12($5);"
".set noreorder;"
"cache 13,0($4);" // Create a new cache block
".set reorder;"
"sw $8,0($4);"
"sw $9,4($4);"
"sw $10,8($4);"
"sw $11,12($4);"
"addi $4,$4,16;"
"addi $5,$5,16;"
"addi $6,$6,-16;"
"addi $8,$6,-16;"
"bgtz $8,bucle2;"
"bucle3:" // Loop until all the bytes have been copied
"lb $8,0($5);"
"sb $8,0($4);"
"addi $4,$4,1;"
"addi $5,$5,1;"
"addi $6,$6,-1;"
"bgtz $6,bucle3;",dst,src,size);
}
I hope it helps.
Pedro Mateu - Pocket Divx Decoder developer[/code]