Skip to content

cmd/compile: make 64-bit fields 64-bit aligned on 32-bit systems #599

Closed

Description

@rsc
Even though the 386 has a 4-byte word size, some instructions move 
data in larger chunks.  In particular float64 loads move 8 bytes and
some SSE2 operations (as yet unused) move even larger amounts.
A float64 load from an only-4-byte-aligned address is significantly
more expensive than one from a 8-byte-aligned address.  The same
is probably true of SSE2 too.

We should make sure that data symbols >32 bits (e.g., float64 constants)
are aligned on 8-byte boundaries in the data segment.  (Fairly easy.)

We should also make sure that the stack pointer can be relied upon to be
8-byte aligned (harder), by making stack frame sizes = -4 mod 8 
(the caller PC will add 4 more) and starting new goroutines with a
properly aligned stack pointer.

It might be worth using 16 bytes for the stack alignment.  OS X requires
that for their own ABI, presumably because it matters for SSE2.

Activity

  1. rsc commented on Dec 9, 2011

    @rsc
    ContributorAuthor

    Comment 1:

    Labels changed: added priority-someday.

  2. rsc commented on Sep 12, 2012

    @rsc
    ContributorAuthor

    Comment 2:

    Issue #3799 has been merged into this issue.

  3. rsc commented on Sep 12, 2012

    @rsc
    ContributorAuthor

    Comment 3:

    This is necessary for atomics to work correctly.
  4. rsc commented on Sep 12, 2012

    @rsc
    ContributorAuthor

    Comment 4:

    Labels changed: added priority-soon, removed priority-someday.

    Status changed to Accepted.

  5. rsc commented on Sep 12, 2012

    @rsc
    ContributorAuthor

    Comment 5:

    Labels changed: added go1.1.

  6. rsc commented on Dec 10, 2012

    @rsc
    ContributorAuthor

    Comment 7:

    Labels changed: added size-l.

  7. rsc commented on Dec 22, 2012

    @rsc
    ContributorAuthor

    Comment 8:

    Too hard. I tried a few different things and failed miserably. The gc toolchain expects
    that the struct and function argument frame alignments match. The stack frame 
    barely matters, since we don't take pointers of stack variables anymore, but that's
    hard too.
    This only really matters for atomics, and we do guarantee 64-bit alignment for the
    base of an allocated struct or slice, so that will have to be good enough for now.

    Labels changed: added priority-someday, removed priority-soon, go1.1.

  8. rsc commented on Dec 22, 2012

    @rsc
    ContributorAuthor

    Comment 9:

    Labels changed: added size-xl, removed size-l.

  9. rsc commented on Jul 30, 2013

    @rsc
    ContributorAuthor

    Comment 10:

    Labels changed: added go1.3maybe.

  10. robpike commented on Aug 20, 2013

    @robpike
    Contributor

    Comment 11:

    Labels changed: removed go1.3maybe.

  11. rsc commented on Oct 29, 2013

    @rsc
    ContributorAuthor

    Comment 13:

    I have had an opportunity to revisit this problem recently in a different context. I
    think we can do it for Go 1.3.

    Labels changed: added go1.3.

  12. rsc commented on Dec 4, 2013

    @rsc
    ContributorAuthor

    Comment 14:

    Labels changed: added release-go1.3.

  13. rsc commented on Dec 4, 2013

    @rsc
    ContributorAuthor

    Comment 15:

    Labels changed: removed go1.3.

  14. rsc commented on Dec 4, 2013

    @rsc
    ContributorAuthor

    Comment 16:

    Labels changed: added repo-main.

  15. rsc commented on Apr 3, 2014

    @rsc
    ContributorAuthor

    Comment 17:

    We didn't do it for 1.3. My guess is that in comment 13 I was referring to NaCl having
    unusual alignment requirements, so perhaps that would pave the way.

    Labels changed: added release-go1.4, removed release-go1.3.

  16. 63 remaining items

  17. rsc commented on Oct 7, 2020

    @rsc
    ContributorAuthor

    Duplicate of #36606.

  18. added a commit that references this issue on Jan 28, 2021
  19. added a commit that references this issue on Apr 14, 2021
  20. added a commit that references this issue on Sep 1, 2021
  21. added a commit that references this issue on Sep 2, 2021
  22. locked and limited conversation to collaborators on Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址