avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-libc-dev] volatile in pgmspace.h ?


From: Dmitry K.
Subject: [avr-libc-dev] volatile in pgmspace.h ?
Date: Sat, 14 Jun 2003 16:36:32 +1100
User-agent: KMail/1.5

Good day!

I have subscribed on "avr-libc-dev" only a few days back and,
probably, not I know all circumstances of this decision.

In my opinion, there is no necessity to include "volatile" in макро "__LPM" 
and other. The result of reading (the second argument asm), instead of the 
fact of presence of a code "lpm" in the given place is important only.

Presence "volatile" does not enable to lead quite justified optimization.
Look at an example: in function "fast()" the compiler has taken out reading 
the ROM for frameworks of a cycle, and in function "slow()" it is impossible.

Example:

#define __LPM_classic__(addr) ({                \
        unsigned short __addr16 = (unsigned short)(addr); \
        unsigned char __result;                 \
        __asm__ (                               \
                "lpm" "\n\t"                    \
                "mov %0, r0"                    \
                : "=r" (__result)               \
                : "z" (__addr16)                \
                : "r0"                          \
        );                                      \
        __result;                               \
 })

#define volat__LPM_classic__(addr) ({                \
        unsigned short __addr16 = (unsigned short)(addr); \
        unsigned char __result;                 \
        __asm__ __volatile__ (                               \
                "lpm" "\n\t"                    \
                "mov %0, r0"                    \
                : "=r" (__result)               \
                : "z" (__addr16)                \
                : "r0"                          \
        );                                      \
        __result;                               \
 })

void f (unsigned char);

void fast (void)
{
    while (1) f(__LPM_classic__(0));
}

void slow (void)
{
    while (1) f(volat__LPM_classic__(0));
}

/* --------------------------------------------------------- */

Result (-O1):

        .file   "lpm.c"
        .arch avr2
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
        .global __do_copy_data
        .global __do_clear_bss
        .text
.global fast
        .type   fast, @function
fast:
/* prologue: frame size=0 */
        push r28
/* prologue end (size=1) */
        ldi r30,lo8(0)
        ldi r31,hi8(0)
/* #APP */
        lpm
        mov r28, r0
/* #NOAPP */
.L5:
        mov r24,r28
        rcall f
        rjmp .L5
/* epilogue: frame size=0 */
/* epilogue: noreturn */
/* epilogue end (size=0) */
/* function fast size 10 (9) */
        .size   fast, .-fast
.global slow
        .type   slow, @function
slow:
/* prologue: frame size=0 */
        push r28
        push r29
/* prologue end (size=2) */
        ldi r28,lo8(0)
        ldi r29,hi8(0)
.L10:
        mov r31,r29
        mov r30,r28
/* #APP */
        lpm
        mov r24, r0
/* #NOAPP */
        rcall f
        rjmp .L10
/* epilogue: frame size=0 */
/* epilogue: noreturn */
/* epilogue end (size=0) */
/* function slow size 12 (10) */
        .size   slow, .-slow
/* File "lpm.c": code   22 = 0x0016 (  19), prologues   3, epilogues   0 */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]