help me with simple iphone arm assembly routine under xcode (inline or not)
I need to write simple routine in iphone arm assembly (under xcode 4) (normal 32 bit not thumb) and have a problems (standalone asm routine do not link and with inline i have trouble with args and generall errors)
I need to assembly a function like
void clear_alpha(unsigned char*bits, int width, int height)
{ for(int j=0; j<height; j++)
for(int i=0; i<width; i++)
{
bits[j][i][4] = 0;
}
}
or so, could anyone help, tnx
If this code is slow, why not try rewriting it
void clear_alpha(unsigned char*bits, int width, int height)
{
for(int j=0; j<height; j++)
for(int i=0; i<width; i++)
{
bits[j][i][4] = 0; // this should be [3]
}
}
Not sure what the optimizer did, but indexing is multiplying. You can replace 3 multiplies in the loop fairly easily
void clear_alpha(unsigned char*bits, int width, int height)
{
char *bits_ptr = bits + 3;
char *bits_end = bits + height * width * 4;
for(; bits_ptr < bits_end; bits_ptr += 4) {
*bits_ptr = 0;
}
}
I didn't run this -- check my work to make sure you don't overrun the end. Now instead of 3 multiplies, you have one add. I am assuming that your third dimension is 5 (edit: fixed based on comment), but you have to fix that if I'm wrong.
See my answer to this ARM asm question, it shows how to conditionally compile ARM asm only when running on the device and compiling for ARM mode and not Thumb. The answer also shows a small example of passing C arguments into an ARM asm statement. You should use the simplified for loop mentioned above, then convert the instructions to ARM asm.
ARM asm example
Be aware that the compiler generated code for this example will likely be just as fast as any ASM you write. But, a good ASM coder will be able to do a lot better than the compiler when you get into more complex situations, mostly because gcc is not very good at making use of conditional ARM asm statements.
memset(bits, 0, sizeof(unsigned char)*width*height);
怎么样memset(bits, 0, sizeof(unsigned char)*width*height);
上一篇: 了解基本的在线NEON组装