Skip to content

Commit 6a40bdc

Browse files
vpachkovrandall77
authored andcommitted
runtime: check GOAMD64 v4 compatibility on Darwin
Darwin requires a different approach to check AVX512 support. Update golang#45453 Change-Id: Ia3dfecc04b47aab16f472000e92e46d4fc6d596d Reviewed-on: https://go-review.googlesource.com/c/go/+/365395 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Trust: Heschi Kreinick <heschi@google.com>
1 parent a417635 commit 6a40bdc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/runtime/asm_amd64.s

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,20 @@ GLOBL bad_cpu_msg<>(SB), RODATA, $84
136136
#define NEED_EXT_FEATURES_CX V4_EXT_FEATURES_CX
137137
#define NEED_EXT_FEATURES_BX V4_EXT_FEATURES_BX
138138

139-
// Downgrading v4 OS checks on Darwin for now, see CL 285572.
139+
// Darwin requires a different approach to check AVX512 support, see CL 285572.
140140
#ifdef GOOS_darwin
141141
#define NEED_OS_SUPPORT_AX V3_OS_SUPPORT_AX
142+
// These values are from:
143+
// https://github.com/apple/darwin-xnu/blob/xnu-4570.1.46/osfmk/i386/cpu_capabilities.h
144+
#define commpage64_base_address 0x00007fffffe00000
145+
#define commpage64_cpu_capabilities64 (commpage64_base_address+0x010)
146+
#define commpage64_version (commpage64_base_address+0x01E)
147+
#define hasAVX512F 0x0000004000000000
148+
#define hasAVX512CD 0x0000008000000000
149+
#define hasAVX512DQ 0x0000010000000000
150+
#define hasAVX512BW 0x0000020000000000
151+
#define hasAVX512VL 0x0000100000000000
152+
#define NEED_DARWIN_SUPPORT (hasAVX512F | hasAVX512DQ | hasAVX512CD | hasAVX512BW | hasAVX512VL)
142153
#else
143154
#define NEED_OS_SUPPORT_AX V4_OS_SUPPORT_AX
144155
#endif
@@ -311,6 +322,18 @@ ok:
311322
JNE bad_cpu
312323
#endif
313324

325+
#ifdef NEED_DARWIN_SUPPORT
326+
MOVQ $commpage64_version, BX
327+
CMPW (BX), $13 // cpu_capabilities64 undefined in versions < 13
328+
JL bad_cpu
329+
MOVQ $commpage64_cpu_capabilities64, BX
330+
MOVQ (BX), BX
331+
MOVQ $NEED_DARWIN_SUPPORT, CX
332+
ANDQ CX, BX
333+
CMPQ BX, CX
334+
JNE bad_cpu
335+
#endif
336+
314337
CALL runtime·check(SB)
315338

316339
MOVL 24(SP), AX // copy argc

0 commit comments

Comments
 (0)