From 229223f5c2e1a315a4b4b8089104df74cc1de7bf Mon Sep 17 00:00:00 2001 From: panchenbo Date: Sat, 12 Aug 2023 13:49:42 +0800 Subject: [PATCH] add loongarch64 and sw_64 support (cherry picked from commit 011c35325e6b406896d452c209d34a4b66b25c2d) --- 3000-add-loongarch64-support.patch | 65 ++++++++++++++++++++++++++++++ 3001-add-sw_64-support.patch | 62 ++++++++++++++++++++++++++++ python-greenlet.spec | 7 +++- 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 3000-add-loongarch64-support.patch create mode 100644 3001-add-sw_64-support.patch diff --git a/3000-add-loongarch64-support.patch b/3000-add-loongarch64-support.patch new file mode 100644 index 0000000..4f8dace --- /dev/null +++ b/3000-add-loongarch64-support.patch @@ -0,0 +1,65 @@ +From 5bad26bce4675cd6b590a2e990e69ff7a6c187b5 Mon Sep 17 00:00:00 2001 +From: wang--ge +Date: Sat, 7 May 2022 14:39:18 +0800 +Subject: [PATCH] add loongarch64 architecture support + +--- + .../platform/switch_loongarch64_linux.h | 31 +++++++++++++++++++ + src/greenlet/slp_platformselect.h | 2 ++ + 2 files changed, 33 insertions(+) + create mode 100644 src/greenlet/platform/switch_loongarch64_linux.h + +diff --git a/src/greenlet/platform/switch_loongarch64_linux.h b/src/greenlet/platform/switch_loongarch64_linux.h +new file mode 100644 +index 0000000..4252561 +--- /dev/null ++++ b/src/greenlet/platform/switch_loongarch64_linux.h +@@ -0,0 +1,31 @@ ++#define STACK_REFPLUS 1 ++ ++#ifdef SLP_EVAL ++#define STACK_MAGIC 0 ++ ++#define REGS_TO_SAVE "s0", "s1", "s2", "s3", "s4", "s5", \ ++ "s6", "s7", "s8", "fp", \ ++ "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31" ++ ++static int ++slp_switch(void) ++{ ++ register int ret; ++ register long *stackref, stsizediff; ++ __asm__ volatile ("" : : : REGS_TO_SAVE); ++ __asm__ volatile ("move %0, $sp" : "=r" (stackref) : ); ++ { ++ SLP_SAVE_STATE(stackref, stsizediff); ++ __asm__ volatile ( ++ "add.d $sp, $sp, %0\n\t" ++ : /* no outputs */ ++ : "r" (stsizediff) ++ ); ++ SLP_RESTORE_STATE(); ++ } ++ __asm__ volatile ("" : : : REGS_TO_SAVE); ++ __asm__ volatile ("move %0, $zero" : "=r" (ret) : ); ++ return ret; ++} ++ ++#endif +\ No newline at end of file +diff --git a/src/greenlet/slp_platformselect.h b/src/greenlet/slp_platformselect.h +index b5e8eb6..1766e16 100644 +--- a/src/greenlet/slp_platformselect.h ++++ b/src/greenlet/slp_platformselect.h +@@ -45,6 +45,8 @@ + #endif + #elif defined(__GNUC__) && defined(__mips__) && defined(__linux__) + #include "platform/switch_mips_unix.h" /* Linux/MIPS */ ++#elif defined(__GNUC__) && defined(__loongarch64) && defined(__linux__) ++#include "platform/switch_loongarch64_linux.h" /* Linux/LoongArch64 */ + #elif defined(__GNUC__) && defined(__aarch64__) + #include "platform/switch_aarch64_gcc.h" /* Aarch64 ABI */ + #elif defined(__GNUC__) && defined(__mc68000__) +-- +2.27.0 + diff --git a/3001-add-sw_64-support.patch b/3001-add-sw_64-support.patch new file mode 100644 index 0000000..1b85a27 --- /dev/null +++ b/3001-add-sw_64-support.patch @@ -0,0 +1,62 @@ +diff -Naur greenlet-1.0.0.org/src/greenlet/platform/switch_sw_64_unix.h greenlet-1.0.0.sw/src/greenlet/platform/switch_sw_64_unix.h +--- greenlet-1.0.0.org/src/greenlet/platform/switch_sw_64_unix.h 1970-01-01 00:00:00.000000000 +0000 ++++ greenlet-1.0.0.sw/src/greenlet/platform/switch_sw_64_unix.h 2021-11-30 11:03:50.760000000 +0000 +@@ -0,0 +1,30 @@ ++#define STACK_REFPLUS 1 ++ ++#ifdef SLP_EVAL ++#define STACK_MAGIC 0 ++ ++#define REGS_TO_SAVE "$9", "$10", "$11", "$12", "$13", "$14", "$15", \ ++ "$f2", "$f3", "$f4", "$f5", "$f6", "$f7", "$f8", "$f9" ++ ++static int ++slp_switch(void) ++{ ++ register int ret; ++ register long *stackref, stsizediff; ++ __asm__ volatile ("" : : : REGS_TO_SAVE); ++ __asm__ volatile ("mov $30, %0" : "=r" (stackref) : ); ++ { ++ SLP_SAVE_STATE(stackref, stsizediff); ++ __asm__ volatile ( ++ "addl $30, %0, $30\n\t" ++ : /* no outputs */ ++ : "r" (stsizediff) ++ ); ++ SLP_RESTORE_STATE(); ++ } ++ __asm__ volatile ("" : : : REGS_TO_SAVE); ++ __asm__ volatile ("mov $31, %0" : "=r" (ret) : ); ++ return ret; ++} ++ ++#endif +diff -Naur greenlet-1.0.0.org/src/greenlet/slp_platformselect.h greenlet-1.0.0.sw/src/greenlet/slp_platformselect.h +--- greenlet-1.0.0.org/src/greenlet/slp_platformselect.h 2021-11-30 10:44:51.030000000 +0000 ++++ greenlet-1.0.0.sw/src/greenlet/slp_platformselect.h 2021-11-30 10:45:39.990000000 +0000 +@@ -55,4 +55,6 @@ + #include "platform/switch_riscv_unix.h" /* gcc on RISC-V */ + #elif defined(__GNUC__) && defined(__alpha__) + #include "platform/switch_alpha_unix.h" /* gcc on DEC Alpha */ ++#elif defined(__GNUC__) && defined(__sw_64__) ++#include "platform/switch_sw_64_unix.h" /* gcc on DEC Sw_64 */ + #endif +diff -Naur greenlet-1.0.0.org/src/greenlet.egg-info/SOURCES.txt greenlet-1.0.0.sw/src/greenlet.egg-info/SOURCES.txt +--- greenlet-1.0.0.org/src/greenlet.egg-info/SOURCES.txt 2021-11-30 10:44:51.030000000 +0000 ++++ greenlet-1.0.0.sw/src/greenlet.egg-info/SOURCES.txt 2021-11-30 10:46:37.890000000 +0000 +@@ -47,6 +47,7 @@ + src/greenlet/platform/setup_switch_x64_masm.cmd + src/greenlet/platform/switch_aarch64_gcc.h + src/greenlet/platform/switch_alpha_unix.h ++src/greenlet/platform/switch_sw_64_unix.h + src/greenlet/platform/switch_amd64_unix.h + src/greenlet/platform/switch_arm32_gcc.h + src/greenlet/platform/switch_arm32_ios.h +@@ -83,4 +84,4 @@ + src/greenlet/tests/test_throw.py + src/greenlet/tests/test_tracing.py + src/greenlet/tests/test_version.py +-src/greenlet/tests/test_weakref.py +\ No newline at end of file ++src/greenlet/tests/test_weakref.py diff --git a/python-greenlet.spec b/python-greenlet.spec index 7501b64..a1b671a 100644 --- a/python-greenlet.spec +++ b/python-greenlet.spec @@ -1,10 +1,12 @@ Name: python-greenlet Version: 1.1.2 -Release: 1 +Release: 2 Summary: lightweight coroutines for in-process concurrent programming License: Python-2.0 and MIT URL: https://github.com/python-greenlet/greenlet Source0: https://files.pythonhosted.org/packages/0c/10/754e21b5bea89d0e73f99d60c83754df7cc64db74f47d98ab187669ce341/greenlet-1.1.2.tar.gz +Patch3000: 3000-add-loongarch64-support.patch +Patch3001: 3001-add-sw_64-support.patch %description The greenlet package is a spin-off of Stackless, a version of CPython that supports micro-threads called "tasklets". Tasklets run pseudo-concurrently @@ -59,6 +61,9 @@ that use python3-greenlet. %{_includedir}/python%{python3_version}*/greenlet/ %changelog +* Sat Aug 12 2023 panchenbo - 1.1.2-2 +- add loongarch64 and sw_64 support + * Mon Oct 24 2022 Ge Wang - 1.1.2-1 - update to 1.1.2 -- Gitee