avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] inline functions pgm_read_*() decrease Butterfly


From: Dmitry K.
Subject: [avr-gcc-list] inline functions pgm_read_*() decrease Butterfly
Date: Tue, 13 Jan 2004 10:04:13 +1000
User-agent: KMail/1.5

Hi all.

I try to replace pgm_read macros to inline functions.
This decrease Butterfly code from:
   section     size      addr
   .data         94   8388864
   .text      14092         0
to:
   section     size      addr
   .data         94   8388864
   .text      14034         0
Thus there is no necessity for manual elimination of
repeated pgm_read_*().

Compiler:  avr-gcc (GCC) 3.3.2
Libc:      avr-libc 1.0.1

To do:
   many warnings about "makes integer from pointer without a cast"

Patch (diff -Naur pgmspace.h.orig pgmspace.h):
--------------------------------------------------------------------------
--- pgmspace.h.orig     2003-10-28 14:58:48.000000000 +1000
+++ pgmspace.h  2004-01-13 09:52:45.000000000 +1000
@@ -316,7 +316,12 @@
     \note The address is a byte address.
     The address is in the program space. */

-#define pgm_read_byte(address_short)    pgm_read_byte_near(address_short)
+/*#define pgm_read_byte(address_short)    pgm_read_byte_near(address_short)*/
+__attribute__((always_inline, const))
+static inline uint8_t pgm_read_byte (uint16_t addr)
+{
+    return pgm_read_byte_near(addr);
+}

 /** \ingroup avr_pgmspace
     \def pgm_read_word(address_short)
@@ -325,7 +330,12 @@
     \note The address is a byte address.
     The address is in the program space. */

-#define pgm_read_word(address_short)    pgm_read_word_near(address_short)
+/*#define pgm_read_word(address_short)    pgm_read_word_near(address_short)*/
+__attribute__((always_inline, const))
+static inline uint16_t pgm_read_word (uint16_t addr)
+{
+    return pgm_read_word_near(addr);
+}

 /** \ingroup avr_pgmspace
     \def PGM_P
-----------------------------------------------------------------------------


reply via email to

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