odissey1 / libfixmath

Automatically exported from code.google.com/p/libfixmath
0 stars 0 forks source link

fix16_mul fails on Cortex M3 #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

the recent addition of fix16_mul brakes for me on a Cortex M3 target. I'm new 
to fixed point math and ARM assembler therefore I cannot be of much assistance 
for debugging. Still it might brake because the asm code is not portable to the 
thumb instruction set?

arm-none-eabi-gcc -c -mcpu=cortex-m3 -O3 -ggdb -fomit-frame-pointer 
-falign-functions=16 -std=gnu99 -ffunction-sections -fdata-sections -Wall 
-Wextra -Wstrict-prototypes -Wa,-alms=libfixmath/fix16.lst   -DTHUMB_PRESENT 
-mno-thumb-interwork -DTHUMB_NO_INTERWORKING -MD -MP -MF .dep/fix16.o.d -mthumb 
-DTHUMB -I . -Ilibfixmath/ libfixmath/fix16.c -o libfixmath/fix16.o
libfixmath/fix16.c: In function 'fix16_mul':
libfixmath/fix16.c:20: error: invalid 'asm': operand number out of range
make: *** [libfixmath/fix16.o] Error 1

At the moment I disabled the code for thumb mode via 
#if (defined(__arm__) || defined(_ARM) ) && !defined(__thumb__)

Original issue reported on code.google.com by blaic...@gmail.com on 13 Mar 2011 at 10:19

GoogleCodeExporter commented 9 years ago
Yes, I don't have many ARM targets to test the code on unfortunately, it will 
only work on ARM (not thumb) and I think it has to be v4 or above, I'll add 
your change to the code anyway to reduce this problem.

Original comment by Flatmush@googlemail.com on 13 Mar 2011 at 11:06

GoogleCodeExporter commented 9 years ago
Too bad - but I gladly test any changed thumb asm code.

Just some uniformed guesses (I have to admit that I never did assembler with 
the gcc and ARM..):
- Isn't the operand code off by one? I think the operands start with %0 and not 
%1 - so there is no operand %3 which probably triggers this error message.

- In thumb mode, there is no OR instruction.

Original comment by blaic...@gmail.com on 13 Mar 2011 at 11:41

GoogleCodeExporter commented 9 years ago
I am currently porting the fp div from a previous support ticket to the thumb 
instruction set.  Currently it runs in about ~75% of the time compared to gcc 
using 64bit integers, just the raw routine, no early outs or input formatting.  
I can take a look at multiplication for thumb.

Original comment by joe.scha...@gmail.com on 13 Mar 2011 at 2:55

GoogleCodeExporter commented 9 years ago
Ok, I made the changes (register numbering oops) so it should work now, will 
probably test it on the only arm target I have setup (XScale) tomorrow.

Original comment by Flatmush@googlemail.com on 13 Mar 2011 at 6:45

GoogleCodeExporter commented 9 years ago
Flatmush, you missed the braces in the preprocessor #if: When compiling for an 
ARM thumb target both __arm__ and __thumb__ are defined.

With the fixed operand numbers I now get the error message:
Error: bad instruction `or r3,r3,r0,LSL#16'

Original comment by blaic...@gmail.com on 14 Mar 2011 at 5:16

GoogleCodeExporter commented 9 years ago
I fixed the preprocessor stuff and that error, I had forgotten that the correct 
mnemonic for bitwise or on ARM is 'orr' to make it 3 letters long like every 
other mnemonic.
All the assemblers I've ever written have been much more accepting of obvious 
stuff like that.

Original comment by Flatmush@googlemail.com on 14 Mar 2011 at 9:04

GoogleCodeExporter commented 9 years ago
Great! Now the assembler code also compiles on my Cortex-M3. I will check out 
tomorrow if the calculations are also correct. If so, you might drop the thumb 
guard again.

Original comment by blaic...@gmail.com on 14 Mar 2011 at 9:09

GoogleCodeExporter commented 9 years ago
Your fix16_mul assembler code also works on the Cortex M3 in thumb mode. Great!

Original comment by blaic...@gmail.com on 15 Mar 2011 at 8:28

GoogleCodeExporter commented 9 years ago
Marked as fixed

Original comment by joe.scha...@gmail.com on 15 Mar 2011 at 2:52

GoogleCodeExporter commented 9 years ago
I hate to disturb again, but the issues is not properly fixed for thumb targets 
as there is still the !defined(__thumb__) in the code. This can be dropped.

Original comment by blaic...@gmail.com on 15 Mar 2011 at 3:42

GoogleCodeExporter commented 9 years ago
Thumb only targets do not have the SMULL instruction.
It should probably be changed to defined(__thumb2__).

I think cortex m3 defines __thumb__ and __thumb2__
M0 defines __thumb__.
I'll make the change

Original comment by joe.scha...@gmail.com on 15 Mar 2011 at 3:46