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

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

[avr-libc-dev] [bug #34423] util/crc16.h: with -Os option inline functio


From: Karol Grzybowski
Subject: [avr-libc-dev] [bug #34423] util/crc16.h: with -Os option inline functions are called causing registers value loss
Date: Wed, 28 Sep 2011 20:33:30 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1

URL:
  <http://savannah.nongnu.org/bugs/?34423>

                 Summary: util/crc16.h: with -Os option inline functions are
called causing registers value loss
                 Project: AVR C Runtime Library
            Submitted by: karol_grzybowski
            Submitted on: Wed 28 Sep 2011 08:33:29 PM GMT
                Category: Header
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: libc code
                  Status: None
        Percent Complete: 0%
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 1.7.1
           Fixed Release: None

    _______________________________________________________

Details:

gcc 4.5.1, AVR_8_bit_GNU_Toolchain_3.2.3_315
gcc options: -funsigned-char -funsigned-bitfields -Os -fpack-struct
-fshort-enums -Wall -c -std=gnu99  -mmcu=atmega16 

function:
static __inline__ uint8_t
_crc_ibutton_update(uint8_t __crc, uint8_t __data)
{
        uint8_t __i, __pattern;
        __asm__ __volatile__ (
                "       eor     %0, %4" "\n\t"
                "       ldi     %1, 8" "\n\t"
                "       ldi     %2, 0x8C" "\n\t"
                "1:     lsr     %0" "\n\t"
                "       brcc    2f" "\n\t"
                "       eor     %0, %2" "\n\t"
                "2:     dec     %1" "\n\t"
                "       brne    1b" "\n\t"
                : "=r" (__crc), "=d" (__i), "=d" (__pattern)
                : "0" (__crc), "r" (__data));
        return __crc;
}

should be always inlined. In my code reading DS18B20 temperature:
        // LSB of temp
        data = ds_read_byte();
        temp = (int16_t)data;
        crc = _crc_ibutton_update(0, data);
        // MSB of temp
        data = ds_read_byte();
        temp |= (int16_t)(data) << 8;
        crc = _crc_ibutton_update(crc, data);
doesn't and that's why the MSB of temp is lost:
0e 94 44 00     call    0x88    ; 0x88 <_crc_ibutton_update>

Adding fallowing line to header seems to be the simplest solution  of this
issue:
static __inline__ uint8_t _crc_ibutton_update(uint8_t __crc, uint8_t __data)
__attribute__((always_inline));

Probably the same problem may occur with others inline Assembly.





    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?34423>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/




reply via email to

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