Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to declare global float register for ARMCC

For a power conversion application we need to do various floating point calculations as quickly as possible on an ARM Cortex-M4 platform.

We are developing with Keil uVision.

We would like to declare some variables as register variables but get nothing but errors from the compiler.

Seems like this is something that would be very useful, as the FPU has 32 registers, and we could save a lot of cycles by storing our data in these registers rather than reloading from RAM every time our ISR is called.

We tried using:

register float a1 __asm__("s0");

but receive an error: unknown register name "s0"

It seems odd, because in the debugger interface I can see that the compiler is using the s0 register. If I declare the register as "r0" instead, there is no error, so it seems like there is some missing FPU support somewhere, but not sure where.

I look at the Assembler control string and seems like floating point is supported:

--cpu Cortex-M4.fp --pd "__EVAL SETA 1" -g --apcs=interwork 
-I D:\my_project
-I D:\Keil_v5\ARM\PACK\ARM\CMSIS\4.4.0\CMSIS\Include 

We also tried:

__global_freg(1) float a1;

This didn't work either.

Any ideas?

like image 425
David Yellin Avatar asked Nov 09 '22 04:11

David Yellin


1 Answers

You need to abide by the EABI, detailed here: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf

From perusing it, it appears you can use (as mentioned in your comment above) s16-s31. The rest are not guaranteed to be preserved by other code.

If your application processing allows, you could possibly get around this by only compiling your ISR with VFP support, and everything else without. This would prevent any code you don't know about from using the VFP registers and corrupting them.

like image 182
Russ Schultz Avatar answered Nov 14 '22 21:11

Russ Schultz