Skip to content
Snippets Groups Projects
Commit 4651cd2b authored by Alberto Nidasio's avatar Alberto Nidasio Committed by Alberto Nidasio
Browse files

Removed `register` keyword from code

For example in interrupts_cortexMx.cpp:
```cpp
static unsigned int getProgramCounter()
{
    unsigned int result;
    // Get program counter when the exception was thrown from stack frame
    asm volatile("mrs   %0,  psp    \n\t"
                 "add   %0, %0, #24 \n\t"
                 "ldr   %0, [%0]    \n\t":"=r"(result));
    return result;
}
```

To check differences in the generated code we disassempled the compiled source with and without the keyword, both for O0 and O2 and both for gcc and clang.
Only in a couple of cases with O0 and gcc there were some differences in the instructions, but non in the semantics

Removed `register` keyword and changed how the stack pointer is copied in `getCurrentFreeStack` function
parent 84031d73
Branches
No related tags found
No related merge requests found
Showing
with 56 additions and 56 deletions
...@@ -32,7 +32,7 @@ namespace miosix { ...@@ -32,7 +32,7 @@ namespace miosix {
void delayMs(unsigned int mseconds) void delayMs(unsigned int mseconds)
{ {
#ifdef SYSCLK_FREQ_32MHz #ifdef SYSCLK_FREQ_32MHz
register const unsigned int count=4000; const unsigned int count=4000;
#else #else
#error "Delays are uncalibrated for this clock frequency" #error "Delays are uncalibrated for this clock frequency"
#endif #endif
......
...@@ -32,7 +32,7 @@ namespace miosix { ...@@ -32,7 +32,7 @@ namespace miosix {
void delayMs(unsigned int mseconds) void delayMs(unsigned int mseconds)
{ {
register const unsigned int count=cpuFrequency/4000; const unsigned int count=cpuFrequency/4000;
for(unsigned int i=0;i<mseconds;i++) for(unsigned int i=0;i<mseconds;i++)
{ {
......
...@@ -32,7 +32,7 @@ namespace miosix { ...@@ -32,7 +32,7 @@ namespace miosix {
void delayMs(unsigned int mseconds) void delayMs(unsigned int mseconds)
{ {
register const unsigned int count=cpuFrequency/4000; const unsigned int count=cpuFrequency/4000;
for(unsigned int i=0;i<mseconds;i++) for(unsigned int i=0;i<mseconds;i++)
{ {
......
...@@ -33,33 +33,33 @@ void delayMs(unsigned int mseconds) ...@@ -33,33 +33,33 @@ void delayMs(unsigned int mseconds)
{ {
#ifndef __CODE_IN_XRAM #ifndef __CODE_IN_XRAM
#ifdef SYSCLK_FREQ_72MHz #ifdef SYSCLK_FREQ_72MHz
register const unsigned int count=12000; //Flash 2 wait state const unsigned int count=12000; //Flash 2 wait state
#elif SYSCLK_FREQ_56MHz #elif SYSCLK_FREQ_56MHz
register const unsigned int count=9333; //Flash 2 wait state const unsigned int count=9333; //Flash 2 wait state
#elif SYSCLK_FREQ_48MHz #elif SYSCLK_FREQ_48MHz
register const unsigned int count=12000; //Flash 1 wait state const unsigned int count=12000; //Flash 1 wait state
#elif SYSCLK_FREQ_36MHz #elif SYSCLK_FREQ_36MHz
register const unsigned int count=9000; //Flash 1 wait state const unsigned int count=9000; //Flash 1 wait state
#elif SYSCLK_FREQ_24MHz #elif SYSCLK_FREQ_24MHz
register const unsigned int count=8000; //Flash 0 wait state const unsigned int count=8000; //Flash 0 wait state
#else #else
register const unsigned int count=2678; //Flash 0 wait state const unsigned int count=2678; //Flash 0 wait state
#endif #endif
#else //__CODE_IN_XRAM #else //__CODE_IN_XRAM
//These delays are calibrated on an stm3210e-eval, and are only correct when //These delays are calibrated on an stm3210e-eval, and are only correct when
//running from ram memories with similar access timings //running from ram memories with similar access timings
#ifdef SYSCLK_FREQ_72MHz #ifdef SYSCLK_FREQ_72MHz
register const unsigned int count=1889; //Linear scaling, factor 26.236 const unsigned int count=1889; //Linear scaling, factor 26.236
#elif SYSCLK_FREQ_56MHz #elif SYSCLK_FREQ_56MHz
register const unsigned int count=1469; const unsigned int count=1469;
#elif SYSCLK_FREQ_48MHz #elif SYSCLK_FREQ_48MHz
register const unsigned int count=1259; const unsigned int count=1259;
#elif SYSCLK_FREQ_36MHz #elif SYSCLK_FREQ_36MHz
register const unsigned int count=945; const unsigned int count=945;
#elif SYSCLK_FREQ_24MHz #elif SYSCLK_FREQ_24MHz
register const unsigned int count=630; const unsigned int count=630;
#else #else
register const unsigned int count=210; const unsigned int count=210;
#endif #endif
#endif //__CODE_IN_XRAM #endif //__CODE_IN_XRAM
for(unsigned int i=0;i<mseconds;i++) for(unsigned int i=0;i<mseconds;i++)
......
...@@ -34,7 +34,7 @@ void delayMs(unsigned int mseconds) ...@@ -34,7 +34,7 @@ void delayMs(unsigned int mseconds)
#ifndef __CODE_IN_XRAM #ifndef __CODE_IN_XRAM
#ifdef SYSCLK_FREQ_120MHz #ifdef SYSCLK_FREQ_120MHz
register const unsigned int count=40000; //Flash 3 wait state const unsigned int count=40000; //Flash 3 wait state
#else //SYSCLK_FREQ_120MHz #else //SYSCLK_FREQ_120MHz
#error "Delays are uncalibrated for this clock frequency" #error "Delays are uncalibrated for this clock frequency"
#endif //SYSCLK_FREQ_120MHz #endif //SYSCLK_FREQ_120MHz
...@@ -45,9 +45,9 @@ void delayMs(unsigned int mseconds) ...@@ -45,9 +45,9 @@ void delayMs(unsigned int mseconds)
//When running code from external RAM delays depend on the RAM timings //When running code from external RAM delays depend on the RAM timings
#if defined(_BOARD_STM3220G_EVAL) #if defined(_BOARD_STM3220G_EVAL)
register const unsigned int count=5000; const unsigned int count=5000;
#elif defined(_BOARD_ETHBOARDV2) #elif defined(_BOARD_ETHBOARDV2)
register const unsigned int count=6000; const unsigned int count=6000;
#else #else
#error "Delays are uncalibrated for this clock board" #error "Delays are uncalibrated for this clock board"
#endif #endif
......
...@@ -32,7 +32,7 @@ namespace miosix { ...@@ -32,7 +32,7 @@ namespace miosix {
void delayMs(unsigned int mseconds) void delayMs(unsigned int mseconds)
{ {
register const unsigned int count = bootClock / 4000; const unsigned int count = bootClock / 4000;
for(unsigned int i=0;i<mseconds;i++) for(unsigned int i=0;i<mseconds;i++)
{ {
......
...@@ -35,17 +35,17 @@ void delayMs(unsigned int mseconds) ...@@ -35,17 +35,17 @@ void delayMs(unsigned int mseconds)
{ {
#ifdef SYSCLK_FREQ_72MHz #ifdef SYSCLK_FREQ_72MHz
#warning delayMs has not been calibrated yet with 72MHz clock #warning delayMs has not been calibrated yet with 72MHz clock
register const unsigned int count=5350; const unsigned int count=5350;
#elif SYSCLK_FREQ_56MHz #elif SYSCLK_FREQ_56MHz
register const unsigned int count=5350; const unsigned int count=5350;
#elif SYSCLK_FREQ_48MHz #elif SYSCLK_FREQ_48MHz
register const unsigned int count=5350; const unsigned int count=5350;
#elif SYSCLK_FREQ_36MHz #elif SYSCLK_FREQ_36MHz
register const unsigned int count=4010; const unsigned int count=4010;
#elif SYSCLK_FREQ_24MHz #elif SYSCLK_FREQ_24MHz
register const unsigned int count=4010; const unsigned int count=4010;
#else // 8MHz clock #else // 8MHz clock
register const unsigned int count=2000; const unsigned int count=2000;
#endif #endif
for(unsigned int i=0;i<mseconds;i++) for(unsigned int i=0;i<mseconds;i++)
......
...@@ -32,13 +32,13 @@ namespace miosix { ...@@ -32,13 +32,13 @@ namespace miosix {
void delayMs(unsigned int mseconds) void delayMs(unsigned int mseconds)
{ {
#ifdef SYSCLK_FREQ_180MHz #ifdef SYSCLK_FREQ_180MHz
register const unsigned int count=45000; const unsigned int count=45000;
#elif defined(SYSCLK_FREQ_168MHz) #elif defined(SYSCLK_FREQ_168MHz)
register const unsigned int count=42000; const unsigned int count=42000;
#elif defined(SYSCLK_FREQ_100MHz) #elif defined(SYSCLK_FREQ_100MHz)
register const unsigned int count=25000; const unsigned int count=25000;
#elif SYSCLK_FREQ_84MHz #elif SYSCLK_FREQ_84MHz
register const unsigned int count=21000; const unsigned int count=21000;
#else #else
#warning "Delays are uncalibrated for this clock frequency" #warning "Delays are uncalibrated for this clock frequency"
#endif #endif
......
...@@ -32,23 +32,23 @@ namespace miosix { ...@@ -32,23 +32,23 @@ namespace miosix {
void delayMs(unsigned int mseconds) void delayMs(unsigned int mseconds)
{ {
#ifdef SYSCLK_FREQ_80MHz #ifdef SYSCLK_FREQ_80MHz
register const unsigned int count=20000; const unsigned int count=20000;
#elif defined(SYSCLK_FREQ_56MHz) #elif defined(SYSCLK_FREQ_56MHz)
register const unsigned int count=14000; const unsigned int count=14000;
#elif defined(SYSCLK_FREQ_48MHz) #elif defined(SYSCLK_FREQ_48MHz)
register const unsigned int count=12000; const unsigned int count=12000;
#elif defined(SYSCLK_FREQ_36MHz) #elif defined(SYSCLK_FREQ_36MHz)
register const unsigned int count=9000; const unsigned int count=9000;
#elif defined(SYSCLK_FREQ_24MHz) #elif defined(SYSCLK_FREQ_24MHz)
register const unsigned int count=6000; const unsigned int count=6000;
#elif defined(HSE_VALUE) && HSE_VALUE==16000000 #elif defined(HSE_VALUE) && HSE_VALUE==16000000
register const unsigned int count=4000; const unsigned int count=4000;
#elif defined(HSE_VALUE) && HSE_VALUE==8000000 #elif defined(HSE_VALUE) && HSE_VALUE==8000000
register const unsigned int count=2000; const unsigned int count=2000;
#elif defined(RUN_WITH_HSI) #elif defined(RUN_WITH_HSI)
register const unsigned int count=4000; const unsigned int count=4000;
#elif defined(RUN_WITH_MSI) #elif defined(RUN_WITH_MSI)
register const unsigned int count=1000; const unsigned int count=1000;
#else #else
#error "Delays are uncalibrated for this clock frequency" #error "Delays are uncalibrated for this clock frequency"
#endif #endif
......
...@@ -33,7 +33,7 @@ void delayMs(unsigned int mseconds) ...@@ -33,7 +33,7 @@ void delayMs(unsigned int mseconds)
{ {
//Note: flash wait state don't matter because of icache //Note: flash wait state don't matter because of icache
#ifdef SYSCLK_FREQ_216MHz #ifdef SYSCLK_FREQ_216MHz
register const unsigned int count=216000; const unsigned int count=216000;
#else #else
#warning "Delays are uncalibrated for this clock frequency" #warning "Delays are uncalibrated for this clock frequency"
#endif #endif
......
...@@ -33,9 +33,9 @@ void delayMs(unsigned int mseconds) ...@@ -33,9 +33,9 @@ void delayMs(unsigned int mseconds)
{ {
//Note: flash wait state don't matter because of icache //Note: flash wait state don't matter because of icache
#ifdef SYSCLK_FREQ_550MHz #ifdef SYSCLK_FREQ_550MHz
register const unsigned int count=550000; const unsigned int count=550000;
#elif defined(SYSCLK_FREQ_400MHz) #elif defined(SYSCLK_FREQ_400MHz)
register const unsigned int count=400000; const unsigned int count=400000;
#else #else
#error "Delays are uncalibrated for this clock frequency" #error "Delays are uncalibrated for this clock frequency"
#endif #endif
......
...@@ -32,14 +32,14 @@ namespace miosix { ...@@ -32,14 +32,14 @@ namespace miosix {
inline int atomicSwap(volatile int *p, int v) inline int atomicSwap(volatile int *p, int v)
{ {
//This is the only atomic operation in the ARM7 assembler //This is the only atomic operation in the ARM7 assembler
register int result; int result;
asm volatile("swp %0, %1, [%2]" : "=&r"(result) : "r"(v),"r"(p) : "memory"); asm volatile("swp %0, %1, [%2]" : "=&r"(result) : "r"(v),"r"(p) : "memory");
return result; return result;
} }
inline void atomicAdd(volatile int *p, int incr) inline void atomicAdd(volatile int *p, int incr)
{ {
register int a,b; //Temporaries used by ASM code int a,b; //Temporaries used by ASM code
asm volatile(" mrs %0, cpsr \n" asm volatile(" mrs %0, cpsr \n"
" tst %0, #0x80 \n" " tst %0, #0x80 \n"
" orreq %1, %0, #0x80 \n" " orreq %1, %0, #0x80 \n"
...@@ -56,8 +56,8 @@ inline void atomicAdd(volatile int *p, int incr) ...@@ -56,8 +56,8 @@ inline void atomicAdd(volatile int *p, int incr)
inline int atomicAddExchange(volatile int *p, int incr) inline int atomicAddExchange(volatile int *p, int incr)
{ {
register int a; //Temporaries used by ASM code int a; //Temporaries used by ASM code
register int result; int result;
asm volatile(" mrs %0, cpsr \n" asm volatile(" mrs %0, cpsr \n"
" tst %0, #0x80 \n" " tst %0, #0x80 \n"
" orreq %1, %0, #0x80 \n" " orreq %1, %0, #0x80 \n"
...@@ -75,8 +75,8 @@ inline int atomicAddExchange(volatile int *p, int incr) ...@@ -75,8 +75,8 @@ inline int atomicAddExchange(volatile int *p, int incr)
inline int atomicCompareAndSwap(volatile int *p, int prev, int next) inline int atomicCompareAndSwap(volatile int *p, int prev, int next)
{ {
register int a; //Temporaries used by ASM code int a; //Temporaries used by ASM code
register int result; int result;
asm volatile(" mrs %0, cpsr \n" asm volatile(" mrs %0, cpsr \n"
" tst %0, #0x80 \n" " tst %0, #0x80 \n"
" orreq %1, %0, #0x80 \n" " orreq %1, %0, #0x80 \n"
...@@ -95,8 +95,8 @@ inline int atomicCompareAndSwap(volatile int *p, int prev, int next) ...@@ -95,8 +95,8 @@ inline int atomicCompareAndSwap(volatile int *p, int prev, int next)
inline void *atomicFetchAndIncrement(void * const volatile * p, int offset, inline void *atomicFetchAndIncrement(void * const volatile * p, int offset,
int incr) int incr)
{ {
register int a,b; //Temporaries used by ASM code int a,b; //Temporaries used by ASM code
register void *result; void *result;
asm volatile(" mrs %0, cpsr \n" asm volatile(" mrs %0, cpsr \n"
" tst %0, #0x80 \n" " tst %0, #0x80 \n"
" orreq %1, %0, #0x80 \n" " orreq %1, %0, #0x80 \n"
......
...@@ -95,7 +95,7 @@ extern "C" void UNDEF_Routine() ...@@ -95,7 +95,7 @@ extern "C" void UNDEF_Routine()
//These two instructions MUST be the first two instructions of the interrupt //These two instructions MUST be the first two instructions of the interrupt
//routine. They store in return_address the pc of the instruction that //routine. They store in return_address the pc of the instruction that
//caused the interrupt. //caused the interrupt.
register int returnAddress; int returnAddress;
asm volatile("mov %0, lr" : "=r"(returnAddress)); asm volatile("mov %0, lr" : "=r"(returnAddress));
IRQerrorLog("\r\n***Unexpected UNDEF @ "); IRQerrorLog("\r\n***Unexpected UNDEF @ ");
...@@ -119,7 +119,7 @@ extern "C" void DABT_Routine() ...@@ -119,7 +119,7 @@ extern "C" void DABT_Routine()
//These two instructions MUST be the first two instructions of the interrupt //These two instructions MUST be the first two instructions of the interrupt
//routine. They store in return_address the pc of the instruction that //routine. They store in return_address the pc of the instruction that
//caused the interrupt. (lr has an offset of 8 during a data abort) //caused the interrupt. (lr has an offset of 8 during a data abort)
register int returnAddress; int returnAddress;
asm volatile("sub %0, lr, #8" : "=r"(returnAddress)); asm volatile("sub %0, lr, #8" : "=r"(returnAddress));
IRQerrorLog("\r\n***Unexpected data abort @ "); IRQerrorLog("\r\n***Unexpected data abort @ ");
...@@ -143,7 +143,7 @@ extern "C" void PABT_Routine() ...@@ -143,7 +143,7 @@ extern "C" void PABT_Routine()
//These two instructions MUST be the first two instructions of the interrupt //These two instructions MUST be the first two instructions of the interrupt
//routine. They store in return_address the pc of the instruction that //routine. They store in return_address the pc of the instruction that
//caused the interrupt. (lr has an offset of 4 during a data abort) //caused the interrupt. (lr has an offset of 4 during a data abort)
register int returnAddress; int returnAddress;
asm volatile("sub %0, lr, #4" : "=r"(returnAddress)); asm volatile("sub %0, lr, #4" : "=r"(returnAddress));
IRQerrorLog("\r\n***Unexpected prefetch abort @ "); IRQerrorLog("\r\n***Unexpected prefetch abort @ ");
......
...@@ -57,7 +57,7 @@ inline void fastEnableInterrupts() noexcept ...@@ -57,7 +57,7 @@ inline void fastEnableInterrupts() noexcept
inline bool areInterruptsEnabled() noexcept inline bool areInterruptsEnabled() noexcept
{ {
register int i; int i;
asm volatile("mrs %0, primask \n\t":"=r"(i)); asm volatile("mrs %0, primask \n\t":"=r"(i));
if(i!=0) return false; if(i!=0) return false;
return true; return true;
......
...@@ -57,7 +57,7 @@ inline void fastEnableInterrupts() noexcept ...@@ -57,7 +57,7 @@ inline void fastEnableInterrupts() noexcept
inline bool areInterruptsEnabled() noexcept inline bool areInterruptsEnabled() noexcept
{ {
register int i; int i;
asm volatile("mrs %0, primask \n\t":"=r"(i)); asm volatile("mrs %0, primask \n\t":"=r"(i));
if(i!=0) return false; if(i!=0) return false;
return true; return true;
......
...@@ -107,7 +107,7 @@ unsigned int MemoryProfiling::getAbsoluteFreeStack() ...@@ -107,7 +107,7 @@ unsigned int MemoryProfiling::getAbsoluteFreeStack()
unsigned int MemoryProfiling::getCurrentFreeStack() unsigned int MemoryProfiling::getCurrentFreeStack()
{ {
unsigned int stackOccupiedByCtxsave=sysconf(ctxsaveOnStack); unsigned int stackOccupiedByCtxsave=sysconf(ctxsaveOnStack);
register int *stack_ptr asm("sp"); int *stack_ptr asm("sp");
const unsigned int *walk=getStackBottom(); const unsigned int *walk=getStackBottom();
unsigned int freeStack=(reinterpret_cast<unsigned int>(stack_ptr) unsigned int freeStack=(reinterpret_cast<unsigned int>(stack_ptr)
- reinterpret_cast<unsigned int>(walk)); - reinterpret_cast<unsigned int>(walk));
......
...@@ -94,7 +94,7 @@ unsigned int MemoryProfiling::getAbsoluteFreeStack() ...@@ -94,7 +94,7 @@ unsigned int MemoryProfiling::getAbsoluteFreeStack()
unsigned int MemoryProfiling::getCurrentFreeStack() unsigned int MemoryProfiling::getCurrentFreeStack()
{ {
register int *stack_ptr asm("sp"); int *stack_ptr;
const unsigned int *walk=Thread::getStackBottom(); const unsigned int *walk=Thread::getStackBottom();
unsigned int freeStack=(reinterpret_cast<unsigned int>(stack_ptr) unsigned int freeStack=(reinterpret_cast<unsigned int>(stack_ptr)
- reinterpret_cast<unsigned int>(walk)); - reinterpret_cast<unsigned int>(walk));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment