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

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

Re: [avr-gcc-list] structure packing


From: David Gay
Subject: Re: [avr-gcc-list] structure packing
Date: Wed, 04 Jun 2003 15:50:52 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030314

address@hidden wrote:
Does not the AVR port alway pack to the byte anyway?

Ralph



No, not to my knowledge. Hence, the compiler switches.

A little testing with the following program reveals that all alignments in avr-gcc are 1, so all structures are byte packed (I *think* old versions may not have done this - I definitely thought that data structure alignment was greater than 1 at some point...).

The program:

struct fun {
  double x;
  int a;
};

int f1(void) {
  return __alignof__(struct fun);
}

int f2(void) {
  return __alignof__(char);
}

int f3(void) {
  return __alignof__(short);
}

int f4(void) {
  return __alignof__(int);
}

int f5(void) {
  return __alignof__(long);
}

int f6(void) {
  return __alignof__(float);
}

int f7(void) {
  return __alignof__(double);
}

Compile it to assembly:
$ avr-gcc -v
Reading specs from /usr/lib/gcc-lib/avr/3.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,c++ --disable-nls --target=avr i386-redhat-linux
Thread model: single
gcc version 3.3 20030512 (prerelease)
$ avr-gcc -O2 align.c -S
$ cat align.s | grep -v logue
        .file   "align.c"
        .arch avr2
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
        .global __do_copy_data
        .global __do_clear_bss
        .text
.global f1
        .type   f1, @function
f1:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret
/* function f1 size 3 (2) */
        .size   f1, .-f1
.global f2
        .type   f2, @function
f2:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret
/* function f2 size 3 (2) */
        .size   f2, .-f2
.global f3
        .type   f3, @function
f3:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret
/* function f3 size 3 (2) */
        .size   f3, .-f3
.global f4
        .type   f4, @function
f4:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret
/* function f4 size 3 (2) */
        .size   f4, .-f4
.global f5
        .type   f5, @function
f5:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret
/* function f5 size 3 (2) */
        .size   f5, .-f5
.global f6
        .type   f6, @function
f6:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret
/* function f6 size 3 (2) */
        .size   f6, .-f6
.global f7
        .type   f7, @function
f7:
        ldi r24,lo8(1)
        ldi r25,hi8(1)
        ret
/* function f7 size 3 (2) */
        .size   f7, .-f7

Yep, all functions return 1...

David Gay
address@hidden



reply via email to

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