Skip to content

Commit 2d1a61d

Browse files
committed
explicitly disable avx512 if zig and march not high enough
1 parent f774418 commit 2d1a61d

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/SPC/builder/Extension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use SPC\exception\WrongUsageException;
1111
use SPC\store\Config;
1212
use SPC\store\FileSystem;
13+
use SPC\toolchain\ToolchainManager;
14+
use SPC\toolchain\ZigToolchain;
1315
use SPC\util\SPCConfigUtil;
1416
use SPC\util\SPCTarget;
1517

@@ -427,13 +429,18 @@ public function buildUnixShared(): void
427429
logger()->info("Extension [{$this->getName()}] patched before shared configure");
428430
}
429431

432+
$has_avx512 = str_contains($this->builder->arch_c_flags ?? '', '-mavx512') ||
433+
str_contains($this->builder->arch_c_flags ?? '', '-march=x86-64-v3') ||
434+
str_contains($this->arch_c_flags ?? '', '-march=x86-64-v4') ||
435+
ToolchainManager::getToolchainClass() !== ZigToolchain::class;
436+
430437
shell()->cd($this->source_dir)
431438
->setEnv($env)
432439
->appendEnv($this->getExtraEnv())
433440
->exec(
434441
'./configure ' . $this->getUnixConfigureArg(true) .
435442
' --with-php-config=' . BUILD_BIN_PATH . '/php-config ' .
436-
'--enable-shared --disable-static'
443+
'--enable-shared --disable-static' . (!$has_avx512 ? ' php_cv_have_avx512=no ' : '')
437444
);
438445

439446
if ($this->patchBeforeSharedMake()) {

src/SPC/builder/extension/simdjson.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use SPC\builder\Extension;
88
use SPC\store\FileSystem;
9-
use SPC\toolchain\ToolchainManager;
10-
use SPC\toolchain\ZigToolchain;
119
use SPC\util\CustomExt;
1210

1311
#[CustomExt('simdjson')]
@@ -33,18 +31,4 @@ public function patchBeforeBuildconf(): bool
3331
);
3432
return true;
3533
}
36-
37-
public function getSharedExtensionEnv(): array
38-
{
39-
$env = parent::getSharedExtensionEnv();
40-
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
41-
$extra = getenv('SPC_COMPILER_EXTRA');
42-
if (!str_contains((string) $extra, '-lstdc++')) {
43-
f_putenv('SPC_COMPILER_EXTRA=' . clean_spaces($extra . ' -lstdc++'));
44-
}
45-
$env['CFLAGS'] .= ' -Xclang -target-feature -Xclang +evex512';
46-
$env['CXXFLAGS'] .= ' -Xclang -target-feature -Xclang +evex512';
47-
}
48-
return $env;
49-
}
5034
}

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use SPC\exception\WrongUsageException;
1010
use SPC\store\FileSystem;
1111
use SPC\store\SourcePatcher;
12+
use SPC\toolchain\ToolchainManager;
13+
use SPC\toolchain\ZigToolchain;
1214
use SPC\util\GlobalEnvManager;
1315
use SPC\util\SPCConfigUtil;
1416
use SPC\util\SPCTarget;
@@ -103,6 +105,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
103105
);
104106
}
105107

108+
$has_avx512 = str_contains($this->arch_c_flags, '-mavx512') ||
109+
str_contains($this->arch_c_flags, '-march=x86-64-v3') ||
110+
str_contains($this->arch_c_flags, '-march=x86-64-v4') ||
111+
ToolchainManager::getToolchainClass() !== ZigToolchain::class;
112+
106113
$this->seekPhpSrcLogFileOnException(fn () => shell()->cd(SOURCE_PATH . '/php-src')->exec(
107114
$php_configure_env . ' ' .
108115
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
@@ -116,6 +123,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
116123
$json_74 .
117124
$zts .
118125
$maxExecutionTimers .
126+
(!$has_avx512 ? 'php_cv_have_avx512=no ' : '') .
119127
$this->makeStaticExtensionArgs() . ' '
120128
));
121129

0 commit comments

Comments
 (0)