From: Christian S. <sch...@li...> - 2025-08-16 13:37:52
|
On Monday, August 11, 2025 5:22:08 PM CEST Ilya Sorochan wrote: > Hi, Hi Ilya, > I was able to build linuxsampler on loongarch64 with some minor tweaks and > would like to share them and possibly merge into linuxsampler. > I also successfully ran `make check` with those changes. > All patches applied against 2.4.0 > > 1. Add CreateTimeStamp() implementation for loongarch64 > > --- a/src/common/RTMath.cpp > +++ b/src/common/RTMath.cpp > @@ -85,6 +85,10 @@ RTMathBase::time_stamp_t RTMathBase::CreateTimeStamp() { > uint32_t t; > asm volatile ("mrc p15, 0, %0, c15, c12, 1" : "=r" (t)); > return t; > + #elif defined(__loongarch__) && __loongarch_grlen == 64 > + uint64_t t; > + asm volatile ("rdtime.d %0, $zero" : "=r" (t)); > + return t; Could easily be extended for 32-bit, but probably nobody cares for 32-bit anymore. So that hunk looks fine. > #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!" > > > 2. Add generic atomic_sub implementation > > --- a/src/common/atomic.h > +++ b/src/common/atomic.h > @@ -1473,6 +1473,11 @@ static __inline__ void atomic_dec(atomic_t *v) > v->counter--; > } > > +static __inline__ void atomic_sub(int i, atomic_t *v) > +{ > + v->counter -= i; > +} > + > static __inline__ int atomic_dec_and_test(atomic_t *v) > { > int res; > > > For the second patch I don't know if generic implementation should have > atomic_sub but it does not compile without it. Also I guess that it is > better to have loongarch64 specific atomic but I'm not sure if I'll be able > to work it out on my own. Well, yes, I mean it would compile that way, but it wouldn't really be doing what it should, because all these operations would not be atomic at all. It's probably not worth bothering writing atomic asm code for loongarch. This header file is pretty old. What about replacing this fallback section (which was intended for architectures where we didn't had atomic asm implementations) by using nowadays compilers' builtin <stdatomic.h> stuff? /Christian |