bugAVR C Runtime Library - Bugs: bug #41435, math library functions in...

 
 

bug #41435: math library functions in uril/delay.h

Submitted by:  Jaakko Kantojärvi <raphendyr>
Submitted on:  Sun 02 Feb 2014 04:13:34 PM UTC  
 
Category: HeaderSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Header files
Status: NonePercent Complete: 0%
Assigned to: NoneOpen/Closed: Open
Release: UnknownFixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 05 Jul 2017 08:52:03 PM UTC, comment #3:

My mistake. In trying to fix #36611 for myself, I accidently screwed with my delay_basic.h and forgot I had done so. That had the erroneous "A" that was causing my problems.

Cameron Tacklind <cinderblock>
Wed 05 Jul 2017 08:35:00 PM UTC, comment #2:

By no means I can see how __STC_HOSTED__ could get you in "A" after "r24". The revision logs of delay_basic.h and delay.h[.in] don't mention such a bug, and my builds of 4.9.2 from around that time also look sane. Also I never came across a GCC bug which added additional "A" junk to operands.

The only issue with this is vor AVR_TINY where register class "w" is empty.

Georg-Johann Lay <gjlayde>
Tue 04 Jul 2017 09:14:28 PM UTC, comment #1:

This caused a bunch of confusion for me until I realized that ffreestanding was causing _delay_ms to fail to compile for a ATmega32u4 device.

For reference, here are the errors I saw. It took a while to figure out that STDC_HOSTED, set by ffreestanding, was making _delay_ms use old incompatible assembly.

The above was gcc error output from compiling this simple file:

For reference, this is the output if I tell g++ to just compile to assembly:

Cameron Tacklind <cinderblock>
Sun 02 Feb 2014 04:13:34 PM UTC, original submission:

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)));

__builtin_avr_delay_cycles(ticks_dc);
}
```

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.

Jaakko Kantojärvi <raphendyr>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by gjlayde (Posted a comment)
  • -unavailable- added by cinderblock (Posted a comment)
  • -unavailable- added by raphendyr (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup1