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

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

RE: [avr-gcc-list] I/O register optimizations.


From: Rune Christensen
Subject: RE: [avr-gcc-list] I/O register optimizations.
Date: Fri, 21 Nov 2003 15:17:41 +0100

Hi Bill

Yes it's possible to get avr-gcc to create the sbi instruction.

I have created a small c program

#include <avr/io.h>

int main(void)
{
  PORTB |= 1;
  PORTB |= 4;

  while(1);
}

Here is the output from running

C:\Documents and Settings\Rune
Christensen\Skrivebord>avr-gcc -S -Os -mmcu=at90s8515 test.c -otest.s

        .file   "test.c"
        .arch at90s8515
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
        .global __do_copy_data
        .global __do_clear_bss
        .text
.global main
        .type   main, @function
main:
/* prologue: frame size=0 */
        ldi r28,lo8(__stack - 0)
        ldi r29,hi8(__stack - 0)
        out __SP_H__,r29
        out __SP_L__,r28
/* prologue end (size=4) */
        sbi 56-0x20,0
        sbi 56-0x20,2
.L2:
        rjmp .L2
/* epilogue: frame size=0 */
/* epilogue: noreturn */
/* epilogue end (size=0) */
/* function main size 7 (3) */
        .size   main, .-main
/* File "test.c": code    7 = 0x0007 (   3), prologues   4, epilogues   0 */


But I don't think that

PORTB |= 5;

is equal to

PORTB |= 1;
PORTB |= 4;

because if you need to set the two bits at exactly the same time then it
will a bad optimization.

I think that a optimization like this could break the code :-(

Rune

-----Original Message-----
From: address@hidden
[mailto:address@hidden Behalf Of Bill Somerville
Sent: Friday, November 21, 2003 2:42 PM
To: address@hidden
Subject: [avr-gcc-list] I/O register optimizations.


Hello

A question for the compiler gurus.

Is there a combination of avr-gcc options that would cause:

PORTB |= 5;

to be optimized for space and compiled as:

        sbi     0x18,0
        sbi     0x18,2

which would save one flash word at the cost of a cycle?

I assume not because the volatile in the PORTB definition implies that
both bits must be set in one operation, but would like a confirmation of
this.

--
Bill Somerville

_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list



reply via email to

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