Hello,
Modern compilers (including those used for MPC57xx, like GCC or Green Hills) automatically optimize register usage. You cannot force a variable into a register using standard C/C++ syntax. Even the register keyword is only a hint, and compilers may ignore it if register pressure is high or if the variable doesn't benefit from being in a register.
Use inline assembly:
This gives you direct control over register usage, but sacrifices portability and maintainability.
asm volatile (
"li r3, 0\n\t" // Load immediate into register r3
"loop:\n\t"
"addi r3, r3, 1\n\t"
"cmpwi r3, 1000\n\t"
"blt loop\n\t"
for (register int i = 0; i < N; i++) {
// loop logic
}
You can also check your compiler optimizations and settings, perform aggressive register allocation and loop unrolling.
In past it was common to simply use assembly code. It was optimized to max and did exactly what was told.
Best regards,
Peter
Hello,
Modern compilers (including those used for MPC57xx, like GCC or Green Hills) automatically optimize register usage. You cannot force a variable into a register using standard C/C++ syntax. Even the register keyword is only a hint, and compilers may ignore it if register pressure is high or if the variable doesn't benefit from being in a register.
Use inline assembly:
This gives you direct control over register usage, but sacrifices portability and maintainability.
asm volatile (
"li r3, 0\n\t" // Load immediate into register r3
"loop:\n\t"
"addi r3, r3, 1\n\t"
"cmpwi r3, 1000\n\t"
"blt loop\n\t"
for (register int i = 0; i < N; i++) {
// loop logic
}
You can also check your compiler optimizations and settings, perform aggressive register allocation and loop unrolling.
In past it was common to simply use assembly code. It was optimized to max and did exactly what was told.
Best regards,
Peter