[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] pgmspace.h: "inline" versus "expression substitution"
From: |
Dmitry K. |
Subject: |
[avr-libc-dev] pgmspace.h: "inline" versus "expression substitution" |
Date: |
Mon, 12 Jan 2004 07:57:33 +1000 |
User-agent: |
KMail/1.5 |
Hi all.
Program memory reading macros. Enveloping gives more effective code,
supposing a reuse of the received value. It works even at absence of
attribute "const" (?).
Compare two loops (by Butterfly's motif):
-------------------------------------------------------
#include <inttypes.h>
#include <avr/pgmspace.h>
__attribute__((always_inline)) /* without `const': the same */
/* __attribute__((always_inline, const)) */
static inline uint16_t pgm_function (uint16_t addr)
{
return pgm_read_word(addr);
}
extern void foo (uint16_t);
void foo_macro (uint16_t addr)
{
do {
foo(pgm_read_word(addr));
} while (pgm_read_word(addr++));
}
void foo_function (uint16_t addr)
{
do {
foo(pgm_function(addr));
} while (pgm_function(addr++));
}
--------------------------------------------------------
Compiler: avr-gcc (GCC) 3.3.2
Libc: avr-libc 1.0.1
Options: -Os -frename-registers
Result:
foo_macro:
...
.L2:
mov r31,r29
mov r30,r28
/* #APP */
lpm
mov r24, r0
adiw r30, 1
lpm
mov r25, r0
/* #NOAPP */
rcall foo
mov r31,r29
mov r30,r28
adiw r28,1
/* #APP */
lpm
mov r26, r0
adiw r30, 1
lpm
mov r27, r0
/* #NOAPP */
or r26,r27
brne .L2
...
foo_function:
...
.L7:
mov r31,r29
mov r30,r28
/* #APP */
lpm
mov r16, r0
adiw r30, 1
lpm
mov r17, r0
/* #NOAPP */
mov r25,r17
mov r24,r16
rcall foo
adiw r28,1
or r16,r17
brne .L7
...
Regards.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-dev] pgmspace.h: "inline" versus "expression substitution",
Dmitry K. <=