From 89bb526e1467cc53109eee884c5b6b1cffc7b3fc Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Mon, 2 Oct 2023 17:59:38 -0700 Subject: 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> --- src/bun.js/bindings/c-bindings.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/bun.js/bindings/c-bindings.cpp') 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 #include #include @@ -6,6 +7,32 @@ #include #include +#if CPU(X86_64) +#include +#include + +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 +} -- cgit v1.2.3