ARM assembler with and without optimisation

Status
Not open for further replies.

Mahenrev

Newbie level 1
Joined
Aug 2, 2005
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,289
I need some help with some questions.

1] If an assembly output is optimised with -O3 [ heavy optimisation ], why is all the variables kept in the register?

2] Let say we have programmed with a bigger amount of variables, say 30 variables,
- when not optimised, its stored in the memory
- when optimised, its stored in the register

when will you know the register is full? Why is even 1 variable stored in the memory?

Thanks is advance
 

Keeping variables in registers ensures that program execution is as fast as possible, because no additional reads from (slower) cache/memory have to be made.

But I don't really see how you can have 30 variables in registers all time?
As far as i know standard ARM9 design has got 16 registers, and few of those are usually used and not really available.

if you have more variables then free registers, you will end up with cache reads/writes (or in worst case, memory reads/writes) which will considerable slow down program execution. That's why everyone is trying to use as few variables as possible in inner loops that get executed MANY times per sec.

Another approach is to pack 2/more variables into one register.
Like if you have 2 16bit variables, you can put them into one 32bit register (lower 16bits = first variable, higher 16bits= second variable) - now you can get either of those variables with only 1 or 2 shift operations. With ARM core shift operations are free...
 

Will the assembler try to optimize the code by "packing" variables into registers?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…