avr-gcc-list
[Top][All Lists]
Advanced

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

AW: [avr-gcc-list] Generating code using sbis, sbic


From: Haase Bjoern (PT-BEU/EMT) *
Subject: AW: [avr-gcc-list] Generating code using sbis, sbic
Date: Thu, 18 Aug 2005 19:17:40 +0200

> David Brown wrote
But the generated code for test2 itself is:
    test2:
        sbis 54-0x20,1
        rjmp .L9
        ldi r24, lo8(1)
        ldi r25, hi8(1)
        ret
    .L9:
        ldi r24, lo8(0)
        ldi r25, hi8(0)
        ret

Hardly optimal (does the result really have to be promoted to an
integer?),
but not bad.  The generated code for test1 is extraordinary:

Unfortunately: This integer promotion is prescribed by the c standard.

If you are using c++ you could overcome it by defining a class uint8_c
and by
Specifying this type as return parameter:


#include <inttypes.h>

class uint8_c {
  public:

  uint8_c (uint8_t initval)
  {
    value = initval; 
  };

  uint8_c
  operator= (uint8_t initval)
  {
    value = initval;
    return *this;
  };

  operator uint8_t (void)
  {
    return value;
  };

  private:
  uint8_t value;
};


uint8_c 
test (void)
{ 
  return 1;
}

uint8_t
Test (void)
{ 
  return 1;
}

Yields:


        .type   _Z4testv, @function
_Z4testv:
        ldi r24,lo8(1)
        ret


        .size   _Z4testv, .-_Z4testv
.global _Z5test2v
        .type   _Z5test2v, @function
_Z5test2v:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret





reply via email to

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