Ticket #364 (assigned bug) — at Version 2

Opened 13 years ago

Last modified 12 years ago

ptr_alignment 8 not honored, sparc 64bit broken

Reported by: rurban Owned by: rurban
Priority: blocker Milestone:
Component: core Version: trunk
Severity: release Keywords:
Cc: doughera, rg@… Language:
Patch status: Platform: other

Description (last modified by rurban) (diff)

A strict 64bit cpu with a ptr_alignment=8 will break when reading pbc's or just frozen pmc's because our alignment when writing our bytecode is 16/ptrsize and not 16.

Any 64bit big-endian cpu with strict alignment is broken without -xmemalign=2i (the immediate workaround)

The goal should be to allow fast aligned code and to align as advertised to 16, not 2 on 64-bit.

 * First we should align to the foreign pbc ptrsize, not to the native ptrsize.
 * /sizeof (opcode_t) => /header->wordsize
 * Then we should get rid of the "/" at all, and align absolutely to 16, and not
 * to 16/4 = 4 or 16/8 = 2.
 * It is also broken in strict alignment 64bit CPU's. See http://nopaste.snit.ch/15684
 * 0x100000dec is an illegal alignment.
#define ROUND_16(val) (((val) & 0xf) ? 16 - ((val) & 0xf) : 0)
#define ALIGN_16(st, cursor) \
    (cursor) += ROUND_16((const char *)(cursor) - (const char *)(st))/sizeof (opcode_t)

This requires a rewrite of all pbc writer alignment code (no macro used, bad), and also of the pbc reader code which is much simplier to fix.

t@1 (l@1) stopped in PF_fetch_integer at line 1076 in file "pf_items.c"
 1076       ASSERT_ARGS(PF_fetch_integer)
(dbx) step
t@1 (l@1) stopped in PF_fetch_integer at line 1078 in file "pf_items.c"
 1078       if (!pf || pf->fetch_iv == NULL)
(dbx) print *(*stream)
**stream = 4
(dbx) step
t@1 (l@1) stopped in PF_fetch_integer at line 1079 in file "pf_items.c"
 1079           return *(*stream)++;
(dbx) print *(*stream) 
**stream = 4
(dbx) step
t@1 (l@1) signal BUS (invalid address alignment) in PF_fetch_integer at line 1079 in file "pf_items.c"
 1079           return *(*stream)++;
(dbx) print *(*stream) 
**stream = 35
(dbx) print *stream
*stream = 0x100000dec

0x100000dec is not properly aligned. It must be 0x100000df0.

Sparc cc manpage: -xmemalign[=<a><b>] Controls memory alignment, <a>={1|2|4|8|16}, b={f|i|s}.
Accepted values for b are: i Interpret access and continue execution. s Raise signal SIGBUS. f For variants of -xarch=v9 only. [reduced i]

Change History

Changed 13 years ago by rurban

  • status changed from new to assigned
  • owner set to rurban
  • description modified (diff)

Changed 13 years ago by rurban

  • description modified (diff)
Note: See TracTickets for help on using tickets.