Go Down

Topic: Another optimization question - can I speed up this 32 bit multiply? (Read 2 times) previous topic - next topic

scswift

What the hell is going on here?

Code: [Select]

#define MultiU16X16to32(longRes, intIn1, intIn2) \
asm volatile ( \
"clr r26 \n\t" \
"mul %A1, %A2 \n\t" \
"movw %A0, r0 \n\t" \
"mul %B1, %B2 \n\t" \
"movw %C0, r0 \n\t" \
"mul %B2, %A1 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"mul %B1, %A2 \n\t" \
"add %B0, r0 \n\t" \
"adc %C0, r1 \n\t" \
"adc %D0, r26 \n\t" \
"clr r1 \n\t" \
: \
"=&r" (longRes) \
: \
"a" (intIn1), \
"a" (intIn2) \
: \
"r26" \
)



#define MultiU8X16to24(longRes, charIn1, intIn2) \
asm volatile ( \
"clr r16 \n\t" \       
"mul %A1, %A2 \n\t" \   
"movw %A0, r0 \n\t" \   
"mov %C0, r16 \n\t" \   
"mov %D0, r16 \n\t" \   
"mul %A1, %B2 \n\t" \ 
"add %B0, r0 \n\t" \   
"adc %C0, r1 \n\t" \   
"adc %D0, r16 \n\t" \ 
"clr r1 \n\t" \
: \                 
"=&r" (longRes) \ 
: \               
"a" (charIn1), \
"a" (intIn2) \
: \               
"r16" \           
)



I was getting an error in the second define, "expected ) before : token", so I copied another example assembly function which is nearly identical, pasted that before the one that's broken, and I get no errors on that one, but of course the second one still errors. 

scswift

Now I'm getting "expected unqualified ID before string constant" on:
"mul %A1, %A2 \n\t" \

Code: [Select]

#define MultiU8X16to24(longRes, charIn1, intIn2) \
asm volatile ( \
"clr r16 \n\t" \     
"mul %A1, %A2 \n\t" \ 
"movw %A0, r0 \n\t" \ 
"mov %C0, r16 \n\t" \ 
"mov %D0, r16 \n\t" \   
"mul %A1, %B2 \n\t" \
"add %B0, r0 \n\t" \   
"adc %C0, r1 \n\t" \   
"adc %D0, r16 \n\t" \
"clr r1 \n\t" \       
: \                 
"=&r" (longRes) \ 
: \               
"a" (charIn1), \
"a" (intIn2) \
: \               
"r16" \           
)

scswift

I removed the first backslash which seems to have fixed that error, but I'm back to to getting an error about expecitng ) before : ...

Code: [Select]

"clr r1 \n\t" \       
: \ 


Right there, on the : \ line.

scswift

What the hell!

I'm still getting that stupid error no matter what I do!

I copied example code from here:
http://www.nongnu.org/avr-libc/user-manual/inline_asm.html

Code: [Select]

asm volatile("mov __tmp_reg__, %A0" "\n\t"
             "mov %A0, %B0"         "\n\t"
             "mov %B0, __tmp_reg__" "\n\t"
             : "=r" (value)
             : "0" (value)
            );



And I get THE SAME ERROR!

scswift

I've been copying examples from everywhere into new sketches and NONE of them are working.  Is there some kind of bug in the IDE?

Code: [Select]

uint8_t n=10;
__asm(" inc #0\n"::"r");


Go Up