aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-10-02 17:59:38 -0700
committerGravatar GitHub <noreply@github.com> 2023-10-02 17:59:38 -0700
commit89bb526e1467cc53109eee884c5b6b1cffc7b3fc (patch)
tree7a5101ce80a388d5290a19365ea73bf5fc85b3d6 /src/bun.js
parent63a00791faac5636394f38f540f79d2e452b6b65 (diff)
downloadbun-89bb526e1467cc53109eee884c5b6b1cffc7b3fc.tar.gz
bun-89bb526e1467cc53109eee884c5b6b1cffc7b3fc.tar.zst
bun-89bb526e1467cc53109eee884c5b6b1cffc7b3fc.zip
Warn at start when using AVX build of Bun without AVX support (#6242)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/bindings/c-bindings.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp
index ff4c8c4e7..f53ff52cc 100644
--- a/src/bun.js/bindings/c-bindings.cpp
+++ b/src/bun.js/bindings/c-bindings.cpp
@@ -1,4 +1,5 @@
// when we don't want to use @cInclude, we can just stick wrapper functions here
+#include "root.h"
#include <sys/resource.h>
#include <cstdint>
#include <unistd.h>
@@ -6,6 +7,32 @@
#include <sys/stat.h>
#include <sys/signal.h>
+#if CPU(X86_64)
+#include <cstring>
+#include <cpuid.h>
+
+extern "C" void bun_warn_avx_missing(const char* url)
+{
+ __builtin_cpu_init();
+ if (__builtin_cpu_supports("avx")) {
+ return;
+ }
+
+ static constexpr const char* str = "warn: CPU lacks AVX support, strange crashes may occur. Reinstall Bun or use *-baseline build:\n ";
+ const size_t len = strlen(str);
+
+ char buf[512];
+ strcpy(buf, str);
+ strcpy(buf + len, url);
+ strcpy(buf + len + strlen(url), "\n\0");
+ write(STDERR_FILENO, buf, strlen(buf));
+}
+#else
+extern "C" void bun_warn_avx_missing(char* url)
+{
+}
+#endif
+
extern "C" int32_t get_process_priority(uint32_t pid)
{
return getpriority(PRIO_PROCESS, pid);
@@ -48,4 +75,4 @@ extern "C" ssize_t bun_sysconf__SC_CLK_TCK()
#else
return 0;
#endif
-} \ No newline at end of file
+}