Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 34792
Product:  
Component:  
Status: UNCONFIRMED
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: David Brown <david@westcontrol.com>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 34792 depends on: Show dependency tree
Show dependency graph
Bug 34792 blocks:

Additional Comments:






Mark bug as waiting for feedback



    

    

View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2008-01-15 09:03
As noted in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34791 , it is important
on the avr to use 8-bit logic whenever possible.  In some cases, the c++
compiler will produce worse code than the c compiler for exactly the same
source:

extern uint8_t data[64];

uint8_t bar2(uint8_t x, uint8_t y) {
        return data[(y ^ x) & 0x0f];
}

Compiled as c, this gives:

  61                    bar2:
  62                    /* prologue: frame size=0 */
  63                    /* prologue end (size=0) */
  64 0018 E62F                  mov r30,r22      ;  y, y
  65 001a E827                  eor r30,r24      ;  y, x
  66 001c F0E0                  ldi r31,lo8(0)   ; ,
  67 001e EF70                  andi r30,lo8(15)         ;  tmp46,
  68 0020 F070                  andi r31,hi8(15)         ;  tmp46,
  69 0022 E050                  subi r30,lo8(-(data))    ;  tmp46,
  70 0024 F040                  sbci r31,hi8(-(data))    ;  tmp46,
  71 0026 8081                  ld r24,Z         ;  tmp50, data
  72 0028 90E0                  ldi r25,lo8(0)   ;  <result>,
  73                    /* epilogue: frame size=0 */
  74 002a 0895                  ret
  75                    /* epilogue end (size=1) */
  76                    /* function bar2 size 10 (9) */

Here there is only one extra instruction, the "andi r31, hi8(15)".  But
compiling as c++, using the same -Os option, gives:


  61                    _Z4bar2hh:
  62                    /* prologue: frame size=0 */
  63                    /* prologue end (size=0) */
  64 0018 E62F                  mov r30,r22      ;  y, y
  65 001a F0E0                  ldi r31,lo8(0)   ;  y,
  66 001c 90E0                  ldi r25,lo8(0)   ;  x,
  67 001e E827                  eor r30,r24      ;  y, x
  68 0020 F927                  eor r31,r25      ;  y, x
  69 0022 EF70                  andi r30,lo8(15)         ;  y,
  70 0024 F070                  andi r31,hi8(15)         ;  y,
  71 0026 E050                  subi r30,lo8(-(data))    ;  y,
  72 0028 F040                  sbci r31,hi8(-(data))    ;  y,
  73 002a 8081                  ld r24,Z         ;  tmp51, data
  74 002c 90E0                  ldi r25,lo8(0)   ;  <result>,
  75                    /* epilogue: frame size=0 */
  76 002e 0895                  ret
  77                    /* epilogue end (size=1) */
  78                    /* function uint8_t bar2(uint8_t, uint8_t) size 12 (11)
*/

This time, the compiler has clearly missed several opportunities to use 8-bit
logic instead of 16-bit logic.

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug