Skip to content

Commit 0668eed

Browse files
committed
fix alignment of xmm register storage
1 parent e24d1dd commit 0668eed

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/rt/arch/x86_64/_context.S

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ swap_registers:
5555

5656
// Save instruction pointer:
5757
pop %rax
58-
mov %rax, 104(%rdi)
58+
mov %rax, 56(%rdi)
5959

6060
// Save non-volatile integer registers:
6161
// (including RSP)
@@ -68,12 +68,12 @@ swap_registers:
6868
mov %r15, 48(%rdi)
6969

7070
// Save non-volatile XMM registers:
71-
movapd %xmm0, 56(%rdi)
72-
movapd %xmm1, 64(%rdi)
73-
movapd %xmm2, 72(%rdi)
74-
movapd %xmm3, 80(%rdi)
75-
movapd %xmm4, 88(%rdi)
76-
movapd %xmm5, 96(%rdi)
71+
movapd %xmm0, 64(%rdi)
72+
movapd %xmm1, 80(%rdi)
73+
movapd %xmm2, 96(%rdi)
74+
movapd %xmm3, 112(%rdi)
75+
movapd %xmm4, 128(%rdi)
76+
movapd %xmm5, 144(%rdi)
7777

7878
// Restore non-volatile integer registers:
7979
// (including RSP)
@@ -86,14 +86,14 @@ swap_registers:
8686
mov 48(%rsi), %r15
8787

8888
// Restore non-volatile XMM registers:
89-
movapd 56(%rsi), %xmm0
90-
movapd 64(%rsi), %xmm1
91-
movapd 72(%rsi), %xmm2
92-
movapd 80(%rsi), %xmm3
93-
movapd 88(%rsi), %xmm4
94-
movapd 96(%rsi), %xmm5
89+
movapd 64(%rsi), %xmm0
90+
movapd 80(%rsi), %xmm1
91+
movapd 96(%rsi), %xmm2
92+
movapd 112(%rsi), %xmm3
93+
movapd 128(%rsi), %xmm4
94+
movapd 144(%rsi), %xmm5
9595

9696
// Jump to the instruction pointer
9797
// found in regs:
98-
jmp *104(%rsi)
98+
jmp *56(%rsi)
9999

src/rt/arch/x86_64/context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ context::context()
1717

1818
void context::swap(context &out)
1919
{
20-
swap_registers(&out.regs, &regs);
20+
swap_registers(&out.regs, &regs);
2121
}
2222

2323
void context::call(void *f, void *arg, void *stack) {

src/rt/arch/x86_64/context.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <cstdlib>
77
#include <inttypes.h>
88
#include <stdint.h>
9+
#include <xmmintrin.h>
910

1011
#ifdef HAVE_VALGRIND
1112
#include <valgrind/memcheck.h>
@@ -20,9 +21,11 @@ T align_down(T sp)
2021
}
2122

2223
struct registers_t {
23-
uint64_t regs[7]; // Space for the volatile regs: rbx, rsp, rbp, r12:r15
24-
uint64_t xmms[6]; // Space for the volatile regs: xmm0:xmm5
24+
uint64_t regs[7]; // Space for the volatile regs: rbx, rsp, rbp, r12:r15
2525
uint64_t ip;
26+
27+
// n.b.: These must be 16-byte aligned or movapd is unhappy.
28+
__m128 xmms[6]; // Space for the volatile regs: xmm0:xmm5
2629
};
2730

2831
class context {

0 commit comments

Comments
 (0)