[Top][All Lists]

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

[avr-libc-dev] [bug #41435] math library functions in uril/delay.h

From: Jaakko Kantojärvi
Subject: [avr-libc-dev] [bug #41435] math library functions in uril/delay.h
Date: Sun, 02 Feb 2014 16:13:35 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36


                 Summary: math library functions in uril/delay.h
                 Project: AVR C Runtime Library
            Submitted by: raphendyr
            Submitted on: Sun 02 Feb 2014 04:13:34 PM GMT
                Category: Header
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Header files
                  Status: None
        Percent Complete: 0%
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: Unknown
           Fixed Release: None



New version of _delay_ms (the one using __builtin_avr_delay_cycles) uses math
functions fabs and ceil.

Code expects that when run on hosted and optimized compilation these calls are
optimized away. As this is impossible in freestanding environment there is
macro test (__STDC_HOSTED__) and code fallback to old code.

This is kind of ok, but there is possibility to make this otherwise.

Following code works in freestanding environment:
static void _delay_ms(double ms) __attribute__ ((unused));
static void _delay_ms(double ms) {
    extern void __builtin_avr_delay_cycles(unsigned long);
    extern double __builtin_fabs(double);
    extern double __builtin_ceil(double);

    double tmp = ((F_CPU) / 1e3) * ms;
    uint32_t ticks_dc = (uint32_t)(__builtin_ceil(__builtin_fabs(tmp)));


As we can see from above, we could use __builtin_fabs and __builtin_ceil in
delay.h instead of expecting the compiler to use them.

I think this is better as we already use __buildin_avr_delay_cycles which
requires build time constant argument, thus we can use __builtin_fabs and
__builtin_ceil as we know their arguments are built time constant.


Reply to this item at:


  Message sent via/by Savannah

reply via email to

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