From 72aea97f4459c22743fccb9a8d38ad12a34eab8d Mon Sep 17 00:00:00 2001
From: yangchenguang <yangchenguang@kylinsec.com.cn>
Date: Tue, 20 Jun 2023 09:42:42 +0800
Subject: [PATCH] Add sw_64 support

Signed-off-by: yangchenguang <yangchenguang@kylinsec.com.cn>
---
 CMakeLists.txt                       |  2 ++
 Source/JavaScriptCore/CMakeLists.txt |  1 +
 Source/WTF/wtf/Platform.h            | 10 ++++++++--
 Source/WTF/wtf/dtoa/utils.h          |  2 +-
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0acb7ba..ee00d2d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -90,6 +90,8 @@ elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
     set(WTF_CPU_S390X 1)
 elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "loongarch64")
     set(WTF_CPU_LOONGARCH64 1)
+elseif (LOWERCASE_CMAKE_SYSTEM_PROCESSOR MATCHES "sw_64")
+    set(WTF_CPU_SW_64 1)
 else ()
     message(FATAL_ERROR "Unknown CPU '${LOWERCASE_CMAKE_SYSTEM_PROCESSOR}'")
 endif ()
diff --git a/Source/JavaScriptCore/CMakeLists.txt b/Source/JavaScriptCore/CMakeLists.txt
index 4d6a72b..22d4cf0 100644
--- a/Source/JavaScriptCore/CMakeLists.txt
+++ b/Source/JavaScriptCore/CMakeLists.txt
@@ -1289,6 +1289,7 @@ elseif (WTF_CPU_MIPS)
 elseif (WTF_CPU_SH4)
 elseif (WTF_CPU_X86)
 elseif (WTF_CPU_LOONGARCH64)
+elseif (WTF_CPU_SW_64)
 elseif (WTF_CPU_X86_64)
     if (MSVC AND ENABLE_JIT)
         add_custom_command(
diff --git a/Source/WTF/wtf/Platform.h b/Source/WTF/wtf/Platform.h
index 76f4262..e784d6c 100644
--- a/Source/WTF/wtf/Platform.h
+++ b/Source/WTF/wtf/Platform.h
@@ -173,6 +173,11 @@
 #define WTF_CPU_LOONGARCH64 1
 #endif
 
+/* CPU(SW_64) - SW64 */
+#if defined(__sw_64__)
+#define WTF_CPU_SW_64 1
+#endif
+
 /* CPU(X86_64) - AMD64 / Intel64 / x86_64 64-bit */
 #if   defined(__x86_64__) \
     || defined(_M_X64)
@@ -353,7 +358,7 @@
 
 #endif /* ARM */
 
-#if CPU(ARM) || CPU(MIPS) || CPU(SH4) || CPU(ALPHA) || CPU(HPPA)
+#if CPU(ARM) || CPU(MIPS) || CPU(SH4) || CPU(ALPHA) || CPU(HPPA) ||  CPU(SW_64)
 #define WTF_CPU_NEEDS_ALIGNED_ACCESS 1
 #endif
 
@@ -712,7 +717,8 @@
     || CPU(MIPS64) \
     || CPU(PPC64) \
     || CPU(PPC64LE) \
-    || CPU(LOONGARCH64)
+    || CPU(LOONGARCH64) \
+    || CPU(SW_64)
 #define USE_JSVALUE64 1
 #else
 #define USE_JSVALUE32_64 1
diff --git a/Source/WTF/wtf/dtoa/utils.h b/Source/WTF/wtf/dtoa/utils.h
index a90287d..97978d6 100644
--- a/Source/WTF/wtf/dtoa/utils.h
+++ b/Source/WTF/wtf/dtoa/utils.h
@@ -49,7 +49,7 @@
 defined(__ARMEL__) || \
 defined(_MIPS_ARCH_MIPS32R2)
 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
-#elif CPU(MIPS) || CPU(MIPS64) || CPU(PPC) || CPU(PPC64) || CPU(PPC64LE) || CPU(SH4) || CPU(S390) || CPU(S390X) || CPU(IA64) || CPU(ALPHA) || CPU(ARM64) || CPU(HPPA) || CPU(LOONGARCH64)
+#elif CPU(MIPS) || CPU(MIPS64) || CPU(PPC) || CPU(PPC64) || CPU(PPC64LE) || CPU(SH4) || CPU(S390) || CPU(S390X) || CPU(IA64) || CPU(ALPHA) || CPU(ARM64) || CPU(HPPA) || CPU(LOONGARCH64) || CPU(SW_64)
 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
 #elif defined(_M_IX86) || defined(__i386__)
 #if defined(_WIN32)
-- 
2.33.0

