[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-commit] [2103] Probe the compiler for the availability of the
From: |
Joerg Wunsch |
Subject: |
[avr-libc-commit] [2103] Probe the compiler for the availability of the |
Date: |
Wed, 17 Mar 2010 05:16:11 +0000 |
Revision: 2103
http://svn.sv.gnu.org/viewvc/?view=rev&root=avr-libc&revision=2103
Author: joerg_wunsch
Date: 2010-03-17 05:16:10 +0000 (Wed, 17 Mar 2010)
Log Message:
-----------
Probe the compiler for the availability of the
__builtin_avr_delay_cycles() function, and modify the header files
<util/delay.h> and <avr/builtins.h> appropriately. Note that the
modification is done by setting __HAS_DELAY_CYCLES on top of those
files, which has been left overridable from the compiler environment
(i.e., commandline -D option) on purpose. Note also that _delay_us()
and _delay_ms() can only use __builtin_avr_delay_cycles() if
optimization is enabled as they'd otherwise try to pass a
floating-point argument to it which is not allowed. (The compiler
does not seem to be able to convert it into an unsigned long
internally, not even with a type cast.) However, not enabling
optimization for them yields garbage timing anyway, due to moving the
compile-time constant floating-point calculations from the compiler
into the AVR.
Modified Paths:
--------------
trunk/avr-libc/configure.ac
trunk/avr-libc/include/avr/Makefile.am
trunk/avr-libc/include/util/Makefile.am
Added Paths:
-----------
trunk/avr-libc/include/avr/builtins.h.in
trunk/avr-libc/include/util/delay.h.in
Removed Paths:
-------------
trunk/avr-libc/include/util/delay.h
Modified: trunk/avr-libc/configure.ac
===================================================================
--- trunk/avr-libc/configure.ac 2010-03-16 22:52:39 UTC (rev 2102)
+++ trunk/avr-libc/configure.ac 2010-03-17 05:16:10 UTC (rev 2103)
@@ -44,13 +44,8 @@
dnl end of library versioning data
dnl odd minor number marks a development branch, append date to version there
-m4_if(m4_eval(avr_libc_minor % 2 == 1), [0], [dnl
- m4_define([avr_libc_version],
- avr_libc_major.avr_libc_minor.avr_libc_revision)dnl
- ],[dnl
- m4_define([avr_libc_version],
-
avr_libc_major.avr_libc_minor.avr_libc_revision.avr_libc_reldate)dnl
- ])dnl
+m4_define([avr_libc_version],
+ avr_libc_major.avr_libc_minor.avr_libc_revision)dnl
m4_define([avr_libc_version_numeric],
m4_eval(10000 * avr_libc_major + dnl
100 * avr_libc_minor + dnl
@@ -326,6 +321,9 @@
FNO_JUMP_TABLES=""
AC_SUBST(FNO_JUMP_TABLES)
+HAS_DELAY_CYCLES=0
+AC_SUBST(HAS_DELAY_CYCLES)
+
AC_DEFUN(
CHECK_MNO_TABLEJUMP,
[
@@ -372,8 +370,29 @@
]
)
+AC_DEFUN(
+ CHECK_BUILTIN_DELAY_CYCLES,
+ [
+ CC=`echo "${CC}" | sed 's/-mmcu=avr.//'`
+ AC_MSG_CHECKING(whether ${CC} supports __builtin_avr_delay_cycles)
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([extern void __builtin_avr_delay_cycles(unsigned
long);],
+ [__builtin_avr_delay_cycles(42);])],
+ [has_delay_cycles=yes],
+ [has_delay_cycles=no]
+ )
+ if test "x$has_delay_cycles" = "xyes"
+ then
+ HAS_DELAY_CYCLES=1
+ fi
+ AC_MSG_RESULT($has_delay_cycles)
+ CC=${old_CC}
+ ]
+)
+
CHECK_MNO_TABLEJUMP
CHECK_FNO_JUMP_TABLES
+CHECK_BUILTIN_DELAY_CYCLES
dnl Some devices are only handled by newer version of gcc. This macro lets us
dnl probe to see if the installed avr-gcc supports a questionable device.
@@ -943,8 +962,10 @@
doc/examples/Makefile
include/Makefile
include/avr/Makefile
+ include/avr/builtins.h
include/compat/Makefile
include/util/Makefile
+ include/util/delay.h
libc/Makefile
libc/misc/Makefile
libc/pmstring/Makefile
Modified: trunk/avr-libc/include/avr/Makefile.am
===================================================================
--- trunk/avr-libc/include/avr/Makefile.am 2010-03-16 22:52:39 UTC (rev
2102)
+++ trunk/avr-libc/include/avr/Makefile.am 2010-03-17 05:16:10 UTC (rev
2103)
@@ -206,7 +206,11 @@
version.h \
wdt.h
+nodist_avr_HEADERS = \
+ builtins.h
+
EXTRA_DIST = \
+ builtins.h.in \
version.h.in
do_subst = sed \
Added: trunk/avr-libc/include/avr/builtins.h.in
===================================================================
--- trunk/avr-libc/include/avr/builtins.h.in (rev 0)
+++ trunk/avr-libc/include/avr/builtins.h.in 2010-03-17 05:16:10 UTC (rev
2103)
@@ -0,0 +1,113 @@
+/* Copyright (c) 2008 Anatoly Sokolov
+ Copyright (c) 2010 Joerg Wunsch
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+/*
+ avr/builtins.h - Intrinsic functions built into the compiler
+ */
+
+#ifndef _AVR_BUILTINS_H_
+#define _AVR_BUILTINS_H_
+
+#ifndef __HAS_DELAY_CYCLES
+#define __HAS_DELAY_CYCLES @HAS_DELAY_CYCLES@
+#endif
+
+/** \file */
+/** \defgroup avr_builtins <avr/builtins.h>: GCC builtins
+ \code #include <avr/builtins.h> \endcode
+
+ This header file declares AVR builtins.
+ All the functions documented here are built into the
+ compiler, and cause it to emit the corresponding assembly
+ code instructions.
+*/
+
+/**
+ \ingroup avr_builtins
+
+ Enables interrupts by setting the global interrupt mask. */
+extern void __builtin_avr_sei(void);
+
+/**
+ \ingroup avr_builtins
+
+ Disables all interrupts by clearing the global interrupt mask. */
+extern void __builtin_avr_cli(void);
+
+/**
+ \ingroup avr_builtins
+
+ Emits a \c SLEEP instruction. */
+
+extern void __builtin_avr_sleep(void);
+
+/**
+ \ingroup avr_builtins
+
+ Emits a WDR (watchdog reset) instruction. */
+extern void __builtin_avr_wdr(void);
+
+/**
+ \ingroup avr_builtins
+
+ Emits a SWAP (nibble swap) instruction on __b. */
+extern unsigned char __builtin_avr_swap(unsigned char __b);
+
+/**
+ \ingroup avr_builtins
+
+ Emits an FMUL (fractional multiply unsigned) instruction. */
+extern unsigned int __builtin_avr_fmul(unsigned char __a, unsigned char __b);
+
+/**
+ \ingroup avr_builtins
+
+ Emits an FMUL (fractional multiply signed) instruction. */
+extern int __builtin_avr_fmuls(char __a, char __b);
+
+/**
+ \ingroup avr_builtins
+
+ Emits an FMUL (fractional multiply signed with unsigned) instruction. */
+extern int __builtin_avr_fmulsu(char __a, unsigned char __b);
+
+#if __HAS_DELAY_CYCLES || defined(__DOXYGEN__)
+/**
+ \ingroup avr_builtins
+
+ Emits a sequence of instructions causing the CPU to spend
+ \c __n cycles on it. */
+extern void __builtin_avr_delay_cycles(unsigned long __n);
+#endif
+
+#endif /* _AVR_BUILTINS_H_ */
Property changes on: trunk/avr-libc/include/avr/builtins.h.in
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Id Date
Added: svn:eol-style
+ native
Modified: trunk/avr-libc/include/util/Makefile.am
===================================================================
--- trunk/avr-libc/include/util/Makefile.am 2010-03-16 22:52:39 UTC (rev
2102)
+++ trunk/avr-libc/include/util/Makefile.am 2010-03-17 05:16:10 UTC (rev
2103)
@@ -33,8 +33,13 @@
avr_HEADERS = \
atomic.h \
crc16.h \
- delay.h \
delay_basic.h \
setbaud.h \
parity.h \
twi.h
+
+nodist_avr_HEADERS = \
+ delay.h
+
+EXTRA_DIST = \
+ delay.h.in
Deleted: trunk/avr-libc/include/util/delay.h
===================================================================
--- trunk/avr-libc/include/util/delay.h 2010-03-16 22:52:39 UTC (rev 2102)
+++ trunk/avr-libc/include/util/delay.h 2010-03-17 05:16:10 UTC (rev 2103)
@@ -1,165 +0,0 @@
-/* Copyright (c) 2002, Marek Michalkiewicz
- Copyright (c) 2004,2005,2007 Joerg Wunsch
- Copyright (c) 2007 Florin-Viorel Petrov
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
- * Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-
- * Neither the name of the copyright holders nor the names of
- contributors may be used to endorse or promote products derived
- from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE. */
-
-/* $Id$ */
-
-#ifndef _UTIL_DELAY_H_
-#define _UTIL_DELAY_H_ 1
-
-#include <inttypes.h>
-#include <util/delay_basic.h>
-
-/** \file */
-/** \defgroup util_delay <util/delay.h>: Convenience functions for busy-wait
delay loops
- \code
- #define F_CPU 1000000UL // 1 MHz
- //#define F_CPU 14.7456E6
- #include <util/delay.h>
- \endcode
-
- \note As an alternative method, it is possible to pass the
- F_CPU macro down to the compiler from the Makefile.
- Obviously, in that case, no \c \#define statement should be
- used.
-
- The functions in this header file are wrappers around the basic
- busy-wait functions from <util/delay_basic.h>. They are meant as
- convenience functions where actual time values can be specified
- rather than a number of cycles to wait for. The idea behind is
- that compile-time constant expressions will be eliminated by
- compiler optimization so floating-point expressions can be used
- to calculate the number of delay cycles needed based on the CPU
- frequency passed by the macro F_CPU.
-
- \note In order for these functions to work as intended, compiler
- optimizations <em>must</em> be enabled, and the delay time
- <em>must</em> be an expression that is a known constant at
- compile-time. If these requirements are not met, the resulting
- delay will be much longer (and basically unpredictable), and
- applications that otherwise do not use floating-point calculations
- will experience severe code bloat by the floating-point library
- routines linked into the application.
-
- The functions available allow the specification of microsecond, and
- millisecond delays directly, using the application-supplied macro
- F_CPU as the CPU clock frequency (in Hertz).
-
-*/
-
-#if !defined(__DOXYGEN__)
-static inline void _delay_us(double __us) __attribute__((always_inline));
-static inline void _delay_ms(double __ms) __attribute__((always_inline));
-#endif
-
-#ifndef F_CPU
-/* prevent compiler error by supplying a default */
-# warning "F_CPU not defined for <util/delay.h>"
-# define F_CPU 1000000UL
-#endif
-
-#ifndef __OPTIMIZE__
-# warning "Compiler optimizations disabled; functions from <util/delay.h>
won't work as designed"
-#endif
-
-/**
- \ingroup util_delay
-
- Perform a delay of \c __ms milliseconds, using _delay_loop_2().
-
- The macro F_CPU is supposed to be defined to a
- constant defining the CPU clock frequency (in Hertz).
-
- The maximal possible delay is 262.14 ms / F_CPU in MHz.
-
- When the user request delay which exceed the maximum possible one,
- _delay_ms() provides a decreased resolution functionality. In this
- mode _delay_ms() will work with a resolution of 1/10 ms, providing
- delays up to 6.5535 seconds (independent from CPU frequency). The
- user will not be informed about decreased resolution.
- */
-void
-_delay_ms(double __ms)
-{
- uint16_t __ticks;
- double __tmp = ((F_CPU) / 4e3) * __ms;
- if (__tmp < 1.0)
- __ticks = 1;
- else if (__tmp > 65535)
- {
- // __ticks = requested delay in 1/10 ms
- __ticks = (uint16_t) (__ms * 10.0);
- while(__ticks)
- {
- // wait 1/10 ms
- _delay_loop_2(((F_CPU) / 4e3) / 10);
- __ticks --;
- }
- return;
- }
- else
- __ticks = (uint16_t)__tmp;
- _delay_loop_2(__ticks);
-}
-
-/**
- \ingroup util_delay
-
- Perform a delay of \c __us microseconds, using _delay_loop_1().
-
- The macro F_CPU is supposed to be defined to a
- constant defining the CPU clock frequency (in Hertz).
-
- The maximal possible delay is 768 us / F_CPU in MHz.
-
- If the user requests a delay greater than the maximal possible one,
- _delay_us() will automatically call _delay_ms() instead. The user
- will not be informed about this case.
- */
-void
-_delay_us(double __us)
-{
- uint8_t __ticks;
- double __tmp = ((F_CPU) / 3e6) * __us;
- if (__tmp < 1.0)
- __ticks = 1;
- else if (__tmp > 255)
- {
- _delay_ms(__us / 1000.0);
- return;
- }
- else
- __ticks = (uint8_t)__tmp;
- _delay_loop_1(__ticks);
-}
-
-
-#endif /* _UTIL_DELAY_H_ */
Copied: trunk/avr-libc/include/util/delay.h.in (from rev 2102,
trunk/avr-libc/include/util/delay.h)
===================================================================
--- trunk/avr-libc/include/util/delay.h.in (rev 0)
+++ trunk/avr-libc/include/util/delay.h.in 2010-03-17 05:16:10 UTC (rev
2103)
@@ -0,0 +1,179 @@
+/* Copyright (c) 2002, Marek Michalkiewicz
+ Copyright (c) 2004,2005,2007 Joerg Wunsch
+ Copyright (c) 2007 Florin-Viorel Petrov
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ * Neither the name of the copyright holders nor the names of
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE. */
+
+/* $Id$ */
+
+#ifndef _UTIL_DELAY_H_
+#define _UTIL_DELAY_H_ 1
+
+#ifndef __HAS_DELAY_CYCLES
+#define __HAS_DELAY_CYCLES @HAS_DELAY_CYCLES@
+#endif
+
+#include <inttypes.h>
+#include <util/delay_basic.h>
+
+/** \file */
+/** \defgroup util_delay <util/delay.h>: Convenience functions for busy-wait
delay loops
+ \code
+ #define F_CPU 1000000UL // 1 MHz
+ //#define F_CPU 14.7456E6
+ #include <util/delay.h>
+ \endcode
+
+ \note As an alternative method, it is possible to pass the
+ F_CPU macro down to the compiler from the Makefile.
+ Obviously, in that case, no \c \#define statement should be
+ used.
+
+ The functions in this header file are wrappers around the basic
+ busy-wait functions from <util/delay_basic.h>. They are meant as
+ convenience functions where actual time values can be specified
+ rather than a number of cycles to wait for. The idea behind is
+ that compile-time constant expressions will be eliminated by
+ compiler optimization so floating-point expressions can be used
+ to calculate the number of delay cycles needed based on the CPU
+ frequency passed by the macro F_CPU.
+
+ \note In order for these functions to work as intended, compiler
+ optimizations <em>must</em> be enabled, and the delay time
+ <em>must</em> be an expression that is a known constant at
+ compile-time. If these requirements are not met, the resulting
+ delay will be much longer (and basically unpredictable), and
+ applications that otherwise do not use floating-point calculations
+ will experience severe code bloat by the floating-point library
+ routines linked into the application.
+
+ The functions available allow the specification of microsecond, and
+ millisecond delays directly, using the application-supplied macro
+ F_CPU as the CPU clock frequency (in Hertz).
+
+*/
+
+#if !defined(__DOXYGEN__)
+static inline void _delay_us(double __us) __attribute__((always_inline));
+static inline void _delay_ms(double __ms) __attribute__((always_inline));
+#endif
+
+#ifndef F_CPU
+/* prevent compiler error by supplying a default */
+# warning "F_CPU not defined for <util/delay.h>"
+# define F_CPU 1000000UL
+#endif
+
+#ifndef __OPTIMIZE__
+# warning "Compiler optimizations disabled; functions from <util/delay.h>
won't work as designed"
+#endif
+
+/**
+ \ingroup util_delay
+
+ Perform a delay of \c __ms milliseconds, using _delay_loop_2().
+
+ The macro F_CPU is supposed to be defined to a
+ constant defining the CPU clock frequency (in Hertz).
+
+ The maximal possible delay is 262.14 ms / F_CPU in MHz.
+
+ When the user request delay which exceed the maximum possible one,
+ _delay_ms() provides a decreased resolution functionality. In this
+ mode _delay_ms() will work with a resolution of 1/10 ms, providing
+ delays up to 6.5535 seconds (independent from CPU frequency). The
+ user will not be informed about decreased resolution.
+ */
+void
+_delay_ms(double __ms)
+{
+ uint16_t __ticks;
+ double __tmp = ((F_CPU) / 4e3) * __ms;
+#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__)
+ extern void __builtin_avr_delay_cycles(unsigned long);
+ __builtin_avr_delay_cycles(__tmp);
+#else
+ if (__tmp < 1.0)
+ __ticks = 1;
+ else if (__tmp > 65535)
+ {
+ // __ticks = requested delay in 1/10 ms
+ __ticks = (uint16_t) (__ms * 10.0);
+ while(__ticks)
+ {
+ // wait 1/10 ms
+ _delay_loop_2(((F_CPU) / 4e3) / 10);
+ __ticks --;
+ }
+ return;
+ }
+ else
+ __ticks = (uint16_t)__tmp;
+ _delay_loop_2(__ticks);
+#endif
+}
+
+/**
+ \ingroup util_delay
+
+ Perform a delay of \c __us microseconds, using _delay_loop_1().
+
+ The macro F_CPU is supposed to be defined to a
+ constant defining the CPU clock frequency (in Hertz).
+
+ The maximal possible delay is 768 us / F_CPU in MHz.
+
+ If the user requests a delay greater than the maximal possible one,
+ _delay_us() will automatically call _delay_ms() instead. The user
+ will not be informed about this case.
+ */
+void
+_delay_us(double __us)
+{
+ uint8_t __ticks;
+ double __tmp = ((F_CPU) / 3e6) * __us;
+#if __HAS_DELAY_CYCLES && defined(__OPTIMIZE__)
+ extern void __builtin_avr_delay_cycles(unsigned long);
+ __builtin_avr_delay_cycles(__tmp);
+#else
+ if (__tmp < 1.0)
+ __ticks = 1;
+ else if (__tmp > 255)
+ {
+ _delay_ms(__us / 1000.0);
+ return;
+ }
+ else
+ __ticks = (uint8_t)__tmp;
+ _delay_loop_1(__ticks);
+#endif
+}
+
+
+#endif /* _UTIL_DELAY_H_ */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-commit] [2103] Probe the compiler for the availability of the,
Joerg Wunsch <=