Skip to contentSkip to conversation

Usage of __attribute__?

parisc-linux John Marvin 3 participants 3 messages Jan 27, 2001 – Jan 28, 2001

lore
Share & tools
lore
#0 lore raw

As part of my effort to fix the alignment problems in libpthread, I am creating a type with the aligned attribute. However, I discovered something strange, which I don't know if it is a bug, or is the expected behaviour (i.e. I am doing something wrong/don't understand how __attribute__ works).

If I directly declare the type as follows:

    typedef int _lt_spinlock_t __attribute__((aligned(16)));

then EVERY int that follows has the aligned 16 attribute, e.g. just declaring "int tmp;" gives tmp a 16 byte alignment. So, is that what you would expect from my above declaration?

I worked around the problem by declaring the type in two steps:

    typedef int _spin16;
    typedef _spin16 _lt_spinlock_t __attribute__((aligned(16)));

Is there a way of combining the above two into one declaration, without having the undesired side effect of making every int aligned to a 16 byte boundary?

John Marvin
[email protected]

#1 lore raw

John,

I think you should forward this question to [email protected].

Quoted 32 lines

As part of my effort to fix the alignment problems in libpthread, I am creating a type with the aligned attribute. However, I discovered something strange, which I don't know if it is a bug, or is the expected behaviour (i.e. I am doing something wrong/don't understand how __attribute__ works).

If I directly declare the type as follows:

    typedef int _lt_spinlock_t __attribute__((aligned(16)));

then EVERY int that follows has the aligned 16 attribute, e.g. just declaring "int tmp;" gives tmp a 16 byte alignment. So, is that what you would expect from my above declaration?

I worked around the problem by declaring the type in two steps:

    typedef int _spin16;
    typedef _spin16 _lt_spinlock_t __attribute__((aligned(16)));

Is there a way of combining the above two into one declaration, without having the undesired side effect of making every int aligned to a 16 byte boundary?

John Marvin
[email protected]

---------------------------------------------------------------------------
To unsubscribe: send e-mail to [email protected] with `unsubscribe' as the subject.

Signature · 2 lines
J. David Anglin                                  [email protected]
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)
#2 lore raw
In reply to John Marvin
Quoted 7 lines · John Marvin

If I directly declare the type as follows:

    typedef int _lt_spinlock_t __attribute__((aligned(16)));

then EVERY int that follows has the aligned 16 attribute, e.g. just declaring "int tmp;" gives tmp a 16 byte alignment. So, is that what you would expect from my above declaration?

Hi John,
I don't see this behaviour. I tried

typedef int _lt_spinlock_t __attribute__ ((aligned (16))); int a;
int b;
_lt_spinlock_t c;
int d;

and got

	.comm	a,4,4
	.comm	b,4,4
	.comm	c,4,16
	.comm	d,4,4

ie. as expected. Can you post a testcase and version of gcc you used?

Alan Modra

Signature · 1 line
Linuxcare.  Support for the Revolution.