Created
January 5, 2022 22:24
-
-
Save Lanius-collaris/5d8a618c68a0d16a3aac85fd4fac2060 to your computer and use it in GitHub Desktop.
loongarch64_linuxsampler_patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/src/common/RTMath.cpp 2021-12-25 18:37:48.733719298 +0800 | |
+++ b/src/common/RTMath.cpp 2021-12-25 21:54:21.914927577 +0800 | |
@@ -73,6 +73,10 @@ | |
return t; | |
#elif defined(__APPLE__) | |
return (time_stamp_t) mach_absolute_time(); | |
+ #elif defined(__loongarch64) | |
+ uint64_t t; | |
+ __asm__ __volatile__ ("rdtime.d %0, $zero":"=r"(t)); | |
+ return time_stamp_t(t>>8); | |
#else // we don't want to use a slow generic solution | |
# error "Sorry, LinuxSampler lacks time stamp code for your system." | |
# error "Please report this error and the CPU you are using to the LinuxSampler developers mailing list!" | |
--- a/linuxsampler/src/common/atomic.h 2021-12-29 04:22:34.535260312 +0800 | |
+++ b/linuxsampler/src/common/atomic.h 2021-12-29 03:43:41.403752006 +0800 | |
@@ -1186,6 +1186,63 @@ | |
#endif /* __ARCH_M68K_ATOMIC __ */ | |
#else | |
+#ifdef __loongarch64 | |
+ | |
+typedef struct { volatile int counter; } atomic_t; | |
+#define ATOMIC_INIT(i) { (i) } | |
+ | |
+#define atomic_read(v) ((v)->counter) | |
+#define atomic_set(v,i) (((v)->counter) = (i)) | |
+ | |
+static __inline__ void atomic_add(int i, volatile atomic_t *v) | |
+{ | |
+ __asm__ __volatile__( | |
+ "amadd_db.w $zero, %1, %0" | |
+ :"+ZB" (v->counter) | |
+ :"r"(i) | |
+ :"memory"); | |
+} | |
+ | |
+static __inline__ void atomic_sub(int i, volatile atomic_t *v) | |
+{ | |
+ __asm__ __volatile__( | |
+ "amadd_db.w $zero, %1, %0" | |
+ :"+ZB" (v->counter) | |
+ :"r"(-i) | |
+ :"memory"); | |
+} | |
+ | |
+#define atomic_inc(v) (atomic_add(1, (v))) | |
+#define atomic_dec(v) (atomic_sub(1, (v))) | |
+ | |
+static __inline__ int haha(int i, volatile atomic_t *v) | |
+{ | |
+ int result; | |
+ __asm__ __volatile__( | |
+ "amadd_db.w %1, %2, %0" | |
+ :"+ZB"(v->counter),"=&r"(result) | |
+ :"r"(-i) | |
+ :"memory"); | |
+ return (result-i)==0; | |
+} | |
+#define atomic_dec_and_test(v) haha(1,(v)) | |
+ | |
+static inline int atomic_add_negative(int i, volatile atomic_t *v) | |
+{ | |
+ int result; | |
+ __asm__ __volatile__( | |
+ "amadd_db.w %1, %2, %0" | |
+ :"+ZB"(v->counter),"=&r"(result) | |
+ :"r"(i) | |
+ :"memory"); | |
+ return (result+i)<0; | |
+} | |
+ | |
+#define mb() __asm__ __volatile__("dbar 0" : : : "memory") | |
+#define rmb() mb() | |
+#define wmb() mb() | |
+ | |
+#else | |
#warning libs/pbd has no implementation of strictly atomic operations for your hardware. | |
@@ -1231,6 +1288,7 @@ | |
} | |
# endif /* __NO_STRICT_ATOMIC */ | |
+# endif /* loongarch64 */ | |
# endif /* m68k */ | |
# endif /* mips */ | |
# endif /* s390 */ | |
@@ -1288,3 +1346,4 @@ | |
#endif /* linux */ | |
#endif /* __linuxsampler_atomic_h__ */ | |
+ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment