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

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

[avr-libc-commit] [2223] 2011-02-23 Eric B.


From: Eric Weddington
Subject: [avr-libc-commit] [2223] 2011-02-23 Eric B.
Date: Wed, 23 Feb 2011 18:15:07 +0000

Revision: 2223
          http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2223
Author:   arcanum
Date:     2011-02-23 18:15:04 +0000 (Wed, 23 Feb 2011)
Log Message:
-----------
2011-02-23  Eric B. Weddington  <address@hidden>

        Partial fix for bug #28058, comment #2.
        Thanks to Jan Waclawek for the code.
        * include/avr/pgmspace.h: Add new strlen_P inline function.
        * libc/pmstring/strlen_P.S: Rename function to __strlen_P.
        * NEWS: Add item.

Ticket Links:
:-----------
    http://savannah.gnu.org/bugs/?28058

Modified Paths:
--------------
    trunk/avr-libc/ChangeLog
    trunk/avr-libc/NEWS
    trunk/avr-libc/include/avr/pgmspace.h
    trunk/avr-libc/libc/pmstring/strlen_P.S

Modified: trunk/avr-libc/ChangeLog
===================================================================
--- trunk/avr-libc/ChangeLog    2011-02-23 16:34:29 UTC (rev 2222)
+++ trunk/avr-libc/ChangeLog    2011-02-23 18:15:04 UTC (rev 2223)
@@ -1,5 +1,13 @@
 2011-02-23  Eric B. Weddington  <address@hidden>
 
+       Partial fix for bug #28058, comment #2.
+       Thanks to Jan Waclawek for the code.
+       * include/avr/pgmspace.h: Add new strlen_P inline function.
+       * libc/pmstring/strlen_P.S: Rename function to __strlen_P.
+       * NEWS: Add item.
+
+2011-02-23  Eric B. Weddington  <address@hidden>
+
        Fix for bug #17815.
        * doc/api/Makefile.am (install-dox-man): Rewrite to fix install
        location to use mandir configuration option.
@@ -7,8 +15,8 @@
 
 2011-02-22  Eric B. Weddington  <address@hidden>
 
-    * doc/api/tools-install.dox: Partial documentation changes
-    for building avr-libc for MinGW/Windows.
+       * doc/api/tools-install.dox: Partial documentation changes
+       for building avr-libc for MinGW/Windows.
 
 2011-02-22  Eric B. Weddington  <address@hidden>
 

Modified: trunk/avr-libc/NEWS
===================================================================
--- trunk/avr-libc/NEWS 2011-02-23 16:34:29 UTC (rev 2222)
+++ trunk/avr-libc/NEWS 2011-02-23 18:15:04 UTC (rev 2223)
@@ -13,7 +13,12 @@
 
 * Other changes:
 
+  - Optimized strlen_P, thanks to Jan Waclawek. Rename strlen_P to be 
__strlen_P
+  and add new strlen_P inline function in header file that checks if value is a
+  constant and known at compile time. If not, then the new inline function 
calls
+  __strlen_P as normal.
 
+
 *** Changes in avr-libc-1.7.1:
 
 * Bugs fixed:

Modified: trunk/avr-libc/include/avr/pgmspace.h
===================================================================
--- trunk/avr-libc/include/avr/pgmspace.h       2011-02-23 16:34:29 UTC (rev 
2222)
+++ trunk/avr-libc/include/avr/pgmspace.h       2011-02-23 18:15:04 UTC (rev 
2223)
@@ -904,6 +904,15 @@
 })
 
 
+
+__attribute__((__always_inline__)) static inline size_t strlen_P(PGM_P s);
+static inline size_t strlen_P(PGM_P s) {
+  return __builtin_constant_p(__builtin_strlen(s))
+     ? __builtin_strlen(s) : __strlen_P(s);
+} 
+
+
+
 extern PGM_VOID_P memchr_P(PGM_VOID_P, int __val, size_t __len) __ATTR_CONST__;
 extern int memcmp_P(const void *, PGM_VOID_P, size_t) __ATTR_PURE__;
 extern void *memccpy_P(void *, PGM_VOID_P, int __val, size_t);
@@ -920,7 +929,7 @@
 extern size_t strcspn_P(const char *__s, PGM_P __reject) __ATTR_PURE__;
 extern size_t strlcat_P (char *, PGM_P, size_t );
 extern size_t strlcpy_P (char *, PGM_P, size_t );
-extern size_t strlen_P(PGM_P) __ATTR_CONST__; /* program memory can't change */
+extern size_t __strlen_P(PGM_P) __ATTR_CONST__;  /* program memory can't 
change */
 extern size_t strnlen_P(PGM_P, size_t) __ATTR_CONST__; /* program memory can't 
change */
 extern int strncmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;
 extern int strncasecmp_P(const char *, PGM_P, size_t) __ATTR_PURE__;

Modified: trunk/avr-libc/libc/pmstring/strlen_P.S
===================================================================
--- trunk/avr-libc/libc/pmstring/strlen_P.S     2011-02-23 16:34:29 UTC (rev 
2222)
+++ trunk/avr-libc/libc/pmstring/strlen_P.S     2011-02-23 18:15:04 UTC (rev 
2223)
@@ -35,7 +35,14 @@
     The strlen_P() function is similar to strlen(), except that src is a
     pointer to a string in program space.
 
-    \returns The strlen() function returns the number of characters in src. */
+    \returns The strlen() function returns the number of characters in src.
+    
+    \note strlen_P() is implemented as an inline function in the avr/pgmspace.h
+    header file, which will check if the length of the string is a constant
+    and known at compile time. If it is not known at compile time, the macro
+    will issue a call to __strlen_P() which will then calculate the length
+    of the string as normal.
+*/
 
 #if !defined(__AVR_TINY__)
 
@@ -46,12 +53,12 @@
 #define src_hi r25
 #define src_lo r24
 
-; 11 words, (14 + strlen_P(src) * 8) cycles
+; 11 words, (14 + __strlen_P(src) * 8) cycles
 
        ASSEMBLY_CLIB_SECTION
-       .global _U(strlen_P)
-       .type   _U(strlen_P), @function
-_U(strlen_P):
+       .global _U(__strlen_P)
+       .type   _U(__strlen_P), @function
+_U(__strlen_P):
        X_movw  ZL, src_lo
 .L_strlen_P_loop:
        X_lpm   r0, Z+
@@ -64,7 +71,7 @@
        adc     src_hi, ZH
        ret
 .L_strlen_P_end:
-       .size   _U(strlen_P), .L_strlen_P_end - _U(strlen_P)
+       .size   _U(__strlen_P), .L_strlen_P_end - _U(__strlen_P)
 
 #endif /* not __DOXYGEN__ */
 




reply via email to

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