Skip to contentSkip to conversation

sparc64 function alignmnet (4 or 32)?

DISCUSSION Sam Ravnborg 3 participants 4 messages Aug 9, 2015 – Aug 10, 2015

lore
Share & tools
lore
#0 lore raw

When browsing sparc64 assembler I can see most handwritten assembler routines are aligned with ".align 32".

But there is also a bunch of routines that uses "ENTRY(foo) - ENDPROC(foo). They are all aligned with ".align 4,0x90" (see include/linux/linkage.h).

I have tried to find something that mandates the 32 byte alignment - so far no luck. Are there any good reasosn for the use of the 32 bytes alignment?

I also tried to decode 0x90 in the SPARC world - it is NOP in x86. I did not manage to decode it - but then I did not try very hard either.

I would expect that .align 4,0x40 would be a better choice for sparc because 0x40 is sethi 0, %g0 aka nop.
See https://en.wikipedia.org/wiki/NOP
And 4 seems to be the necessary aligmnet for both sparc32 and sparc64.

But I am left with an impression that I am missing something since so many routines uses 32 bytes.

Sam

#1 lore raw
Quoted 18 lines · Sam Ravnborg

When browsing sparc64 assembler I can see most handwritten assembler routines are aligned with ".align 32".

But there is also a bunch of routines that uses "ENTRY(foo) - ENDPROC(foo). They are all aligned with ".align 4,0x90" (see include/linux/linkage.h).

I have tried to find something that mandates the 32 byte alignment - so far no luck.
Are there any good reasosn for the use of the 32 bytes alignment?

I also tried to decode 0x90 in the SPARC world - it is NOP in x86. I did not manage to decode it - but then I did not try very hard either.

I would expect that .align 4,0x40 would be a better choice for sparc because 0x40 is sethi 0, %g0 aka nop.
See https://en.wikipedia.org/wiki/NOP
And 4 seems to be the necessary aligmnet for both sparc32 and sparc64.

Quoted 4 lines

But I am left with an impression that I am missing something since so many routines uses 32 bytes.

Sam

Hi,

I tried to decode 0x90909090 in the V8/V9 manual, and it came back as ORcc %g2, %l0, %o0 (0x90908010). Doesn't make much sense?

I guess aligning with 0x00 would be better as it would generate a illegal instruction trap if executed. If the alignment is executed something is already wrong and the first instructions from the next function might be executed depending alignment of functions in a given compile.

Regards,
Kjetil Oftedal

#2 lore raw
In reply to Sam Ravnborg

From: Sam Ravnborg <[email protected]>
Date: Sun, 9 Aug 2015 21:45:24 +0200

Quoted 2 lines

When browsing sparc64 assembler I can see most handwritten assembler routines are aligned with ".align 32".

The required alignment is 4 bytes.

Some routines are aligned to 32 bytes in order to have them begin at exactly an I-cache line boundary to increase I-cache utilization. This is done especially for "hot" routines like memcpy, memset, etc.

#3 lore raw
In reply to Sam Ravnborg
Quoted 11 lines · David Miller

From: Sam Ravnborg <[email protected]>
Date: Sun, 9 Aug 2015 21:45:24 +0200

Quoted 2 lines

When browsing sparc64 assembler I can see most handwritten assembler routines are aligned with ".align 32".

The required alignment is 4 bytes.

Some routines are aligned to 32 bytes in order to have them begin at exactly an I-cache line boundary to increase I-cache utilization. This is done especially for "hot" routines like memcpy, memset, etc.

Makes perfect sense - thanks.
I may try to dive into this a little to make this a bit more explicit. Something like:

ENTRY(foo) - 4 byte aligned. Use 0x0 as filler. ENTRY_CACHE_ALIGNED - 32 bytes aligned, use 0x0 as filler.

Today ENTRY() uses 0x90 as fille but as Kjetill writes in another mail this is a weird instruction.

Before I can change the filler to 0x0 then I need to audit all uses of ENTRY(), because if anyone uses fallthrough then this would not work.

Let me come up with a patch later then we can judgde if this is worthwhile then.

Sam