From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 25148213F0 for ; Sat, 11 May 2024 03:06:58 +0200 (CEST) Received: (qmail 17495 invoked by uid 550); 11 May 2024 01:06:51 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 16271 invoked from network); 11 May 2024 01:06:50 -0000 To: ticat_fp , musl@lists.openwall.com Cc: huajingyun@loongson.cn, wanghongliang@loongson.cn References: <20240423022619.1253464-1-fanpeng@loongson.cn> From: lixing Message-ID: <9216362a-951e-4c56-b7a3-b865fde49aed@loongson.cn> Date: Sat, 11 May 2024 09:06:34 +0800 User-Agent: Mozilla/5.0 (X11; Linux loongarch64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20240423022619.1253464-1-fanpeng@loongson.cn> Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8CxTN6axD5mtqcZAA--.47887S3 X-CM-SenderInfo: pol0x03j6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBj9fXoW3tw13tryftF1xWF4DZryruFX_yoW8Jw1kXo Z5XayUWw48Cw1Yyry8Zry5XFy2vr1fCFW7Z3y7Z3yUGryrAw45Jryxua15KFyfCrnrW3y5 W3yIgrs5Zws2g3s7l-sFpf9Il3svdjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8wcxFpf 9Il3svdxBIdaVrn0xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3 UjIYCTnIWjp_UUUY77kC6x804xWl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI 8IcIk0rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xG Y2AK021l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14 v26r1j6r4UM28EF7xvwVC2z280aVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r1j6r4UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzV AYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU1CPfJUU UUU== Subject: [musl] Re: [PATCH] math: add LoongArch support for common APIs with inline assembly. Hi, Rich Can you take some time to check these loongarch64 optimization of math functions ? We've verified this patch in alpine system. Thanks. ÔÚ 2024/4/23 ÉÏÎç10:26, ticat_fp дµÀ: > Including: ceil, copysign, fabs, floor, fma, fmax, fmin, llrint, > lrint, rint, sqrt and their f versions. > > --- > src/math/loongarch64/ceil.c | 25 +++++++++++++++++++++++++ > src/math/loongarch64/ceilf.c | 25 +++++++++++++++++++++++++ > src/math/loongarch64/copysign.c | 7 +++++++ > src/math/loongarch64/copysignf.c | 7 +++++++ > src/math/loongarch64/fabs.c | 7 +++++++ > src/math/loongarch64/fabsf.c | 7 +++++++ > src/math/loongarch64/floor.c | 22 ++++++++++++++++++++++ > src/math/loongarch64/floorf.c | 22 ++++++++++++++++++++++ > src/math/loongarch64/fma.c | 7 +++++++ > src/math/loongarch64/fmaf.c | 7 +++++++ > src/math/loongarch64/fmax.c | 7 +++++++ > src/math/loongarch64/fmaxf.c | 7 +++++++ > src/math/loongarch64/fmin.c | 7 +++++++ > src/math/loongarch64/fminf.c | 7 +++++++ > src/math/loongarch64/llrint.c | 17 +++++++++++++++++ > src/math/loongarch64/llrintf.c | 17 +++++++++++++++++ > src/math/loongarch64/lrint.c | 17 +++++++++++++++++ > src/math/loongarch64/lrintf.c | 17 +++++++++++++++++ > src/math/loongarch64/rint.c | 7 +++++++ > src/math/loongarch64/rintf.c | 7 +++++++ > src/math/loongarch64/sqrt.c | 7 +++++++ > src/math/loongarch64/sqrtf.c | 7 +++++++ > 22 files changed, 260 insertions(+) > create mode 100644 src/math/loongarch64/ceil.c > create mode 100644 src/math/loongarch64/ceilf.c > create mode 100644 src/math/loongarch64/copysign.c > create mode 100644 src/math/loongarch64/copysignf.c > create mode 100644 src/math/loongarch64/fabs.c > create mode 100644 src/math/loongarch64/fabsf.c > create mode 100644 src/math/loongarch64/floor.c > create mode 100644 src/math/loongarch64/floorf.c > create mode 100644 src/math/loongarch64/fma.c > create mode 100644 src/math/loongarch64/fmaf.c > create mode 100644 src/math/loongarch64/fmax.c > create mode 100644 src/math/loongarch64/fmaxf.c > create mode 100644 src/math/loongarch64/fmin.c > create mode 100644 src/math/loongarch64/fminf.c > create mode 100644 src/math/loongarch64/llrint.c > create mode 100644 src/math/loongarch64/llrintf.c > create mode 100644 src/math/loongarch64/lrint.c > create mode 100644 src/math/loongarch64/lrintf.c > create mode 100644 src/math/loongarch64/rint.c > create mode 100644 src/math/loongarch64/rintf.c > create mode 100644 src/math/loongarch64/sqrt.c > create mode 100644 src/math/loongarch64/sqrtf.c > > diff --git a/src/math/loongarch64/ceil.c b/src/math/loongarch64/ceil.c > new file mode 100644 > index 00000000..95781f4b > --- /dev/null > +++ b/src/math/loongarch64/ceil.c > @@ -0,0 +1,25 @@ > +#include > +#include > + > +double ceil(double x) > +{ > + int32_t old; > + int32_t new; > + int32_t tmp1; > + int32_t tmp2; > + > + __asm__ __volatile__( > + "movfcsr2gr %[orig_old], $r0 \n\t" > + "li.d %[tmp1], 0x200 \n\t" > + "or %[new], %[orig_old], %[tmp1] \n\t" > + "li.d %[tmp2], 0xfffffeff \n\t" > + "and %[new], %[new], %[tmp2] \n\t" > + "movgr2fcsr $r0, %[new] \n\t" > + "frint.d %[result], %[orig_x] \n\t" > + "movgr2fcsr $r0, %[orig_old] \n\t" > + : [result] "+f"(x), [old]"+r"(old), [new]"+r"(new), [tmp1] "+r"(tmp1), [tmp2] "+r"(tmp2) > + : [orig_x] "f"(x), [orig_old]"r"(old), [orig_new]"r"(new), [orig_tmp1] "r"(tmp1), [orig_tmp2] "r"(tmp2) > + :); > + > + return x; > +} > diff --git a/src/math/loongarch64/ceilf.c b/src/math/loongarch64/ceilf.c > new file mode 100644 > index 00000000..03a2d933 > --- /dev/null > +++ b/src/math/loongarch64/ceilf.c > @@ -0,0 +1,25 @@ > +#include > +#include > + > +float ceilf(float x) > +{ > + int32_t old; > + int32_t new; > + int32_t tmp1; > + int32_t tmp2; > + > + __asm__ __volatile__( > + "movfcsr2gr %[orig_old], $r0 \n\t" > + "li.d %[tmp1], 0x200 \n\t" > + "or %[new], %[orig_old], %[tmp1] \n\t" > + "li.d %[tmp2], 0xfffffeff \n\t" > + "and %[new], %[new], %[tmp2] \n\t" > + "movgr2fcsr $r0, %[new] \n\t" > + "frint.s %[result], %[orig_x] \n\t" > + "movgr2fcsr $r0, %[orig_old] \n\t" > + : [result] "+f"(x), [old]"+r"(old), [new]"+r"(new), [tmp1] "+r"(tmp1), [tmp2] "+r"(tmp2) > + : [orig_x] "f"(x), [orig_old]"r"(old), [orig_new]"r"(new), [orig_tmp1] "r"(tmp1), [orig_tmp2] "r"(tmp2) > + :); > + > + return x; > +} > diff --git a/src/math/loongarch64/copysign.c b/src/math/loongarch64/copysign.c > new file mode 100644 > index 00000000..9e3b8de3 > --- /dev/null > +++ b/src/math/loongarch64/copysign.c > @@ -0,0 +1,7 @@ > +#include > + > +double copysign(double x, double y) > +{ > + __asm__ __volatile__("fcopysign.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); > + return x; > +} > diff --git a/src/math/loongarch64/copysignf.c b/src/math/loongarch64/copysignf.c > new file mode 100644 > index 00000000..98df4254 > --- /dev/null > +++ b/src/math/loongarch64/copysignf.c > @@ -0,0 +1,7 @@ > +#include > + > +float copysignf(float x, float y) > +{ > + __asm__ __volatile__("fcopysign.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); > + return x; > +} > diff --git a/src/math/loongarch64/fabs.c b/src/math/loongarch64/fabs.c > new file mode 100644 > index 00000000..3db57fb5 > --- /dev/null > +++ b/src/math/loongarch64/fabs.c > @@ -0,0 +1,7 @@ > +#include > + > +double fabs(double x) > +{ > + __asm__ __volatile__("fabs.d %0, %1" : "=f"(x) : "f"(x)); > + return x; > +} > diff --git a/src/math/loongarch64/fabsf.c b/src/math/loongarch64/fabsf.c > new file mode 100644 > index 00000000..e24201c5 > --- /dev/null > +++ b/src/math/loongarch64/fabsf.c > @@ -0,0 +1,7 @@ > +#include > + > +float fabsf(float x) > +{ > + __asm__ __volatile__("fabs.s %0, %1" : "=f"(x) : "f"(x)); > + return x; > +} > diff --git a/src/math/loongarch64/floor.c b/src/math/loongarch64/floor.c > new file mode 100644 > index 00000000..7aead2a3 > --- /dev/null > +++ b/src/math/loongarch64/floor.c > @@ -0,0 +1,22 @@ > +#include > +#include > + > +double floor(double x) > +{ > + int32_t old; > + int32_t new; > + int32_t tmp1; > + > + __asm__ __volatile__( > + "movfcsr2gr %[old], $r0 \n\t" > + "li.d %[tmp1], 0x300 \n\t" > + "or %[new], %[old], %[tmp1] \n\t" > + "movgr2fcsr $r0, %[new] \n\t" > + "frint.d %[result], %[orig_x] \n\t" > + "movgr2fcsr $r0, %[old] \n\t" > + : [result] "+f"(x), [old]"+r"(old), [tmp1] "+r"(tmp1), [new]"+r"(new) > + : [orig_x] "f"(x), [origin_old] "r"(old), [orig_new] "r"(new), [orig_tmp1] "r"(tmp1) > + :); > + > + return x; > +} > diff --git a/src/math/loongarch64/floorf.c b/src/math/loongarch64/floorf.c > new file mode 100644 > index 00000000..772d15eb > --- /dev/null > +++ b/src/math/loongarch64/floorf.c > @@ -0,0 +1,22 @@ > +#include > +#include > + > +float floorf(float x) > +{ > + int32_t old; > + int32_t new; > + int32_t tmp1; > + > + __asm__ __volatile__( > + "movfcsr2gr %[old], $r0 \n\t" > + "li.d %[tmp1], 0x300 \n\t" > + "or %[new], %[old], %[tmp1] \n\t" > + "movgr2fcsr $r0, %[new] \n\t" > + "frint.s %[result], %[orig_x] \n\t" > + "movgr2fcsr $r0, %[old] \n\t" > + : [result] "+f"(x), [old]"+r"(old), [tmp1] "+r"(tmp1), [new]"+r"(new) > + : [orig_x] "f"(x), [origin_old] "r"(old), [orig_new] "r"(new), [orig_tmp1] "r"(tmp1) > + :); > + > + return x; > +} > diff --git a/src/math/loongarch64/fma.c b/src/math/loongarch64/fma.c > new file mode 100644 > index 00000000..0b6a3f23 > --- /dev/null > +++ b/src/math/loongarch64/fma.c > @@ -0,0 +1,7 @@ > +#include > + > +double fma(double x, double y, double z) > +{ > + __asm__ __volatile__("fmadd.d %0, %1, %2, %3" : "=f" (x) : "f"(x) , "f" (y), "f" (z)); > + return x; > +} > diff --git a/src/math/loongarch64/fmaf.c b/src/math/loongarch64/fmaf.c > new file mode 100644 > index 00000000..77a8363b > --- /dev/null > +++ b/src/math/loongarch64/fmaf.c > @@ -0,0 +1,7 @@ > +#include > + > +float fmaf(float x, float y, float z) > +{ > + __asm__ __volatile__("fmadd.s %0, %1, %2, %3" : "=f" (x) : "f"(x) , "f" (y), "f" (z)); > + return x; > +} > diff --git a/src/math/loongarch64/fmax.c b/src/math/loongarch64/fmax.c > new file mode 100644 > index 00000000..2d091877 > --- /dev/null > +++ b/src/math/loongarch64/fmax.c > @@ -0,0 +1,7 @@ > +#include > + > +double fmax(double x, double y) > +{ > + __asm__ __volatile__("fmax.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); > + return x; > +} > diff --git a/src/math/loongarch64/fmaxf.c b/src/math/loongarch64/fmaxf.c > new file mode 100644 > index 00000000..1106d47c > --- /dev/null > +++ b/src/math/loongarch64/fmaxf.c > @@ -0,0 +1,7 @@ > +#include > + > +float fmaxf(float x, float y) > +{ > + __asm__ __volatile__("fmax.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); > + return x; > +} > diff --git a/src/math/loongarch64/fmin.c b/src/math/loongarch64/fmin.c > new file mode 100644 > index 00000000..9c44ce87 > --- /dev/null > +++ b/src/math/loongarch64/fmin.c > @@ -0,0 +1,7 @@ > +#include > + > +double fmin(double x, double y) > +{ > + __asm__ __volatile__("fmin.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); > + return x; > +} > diff --git a/src/math/loongarch64/fminf.c b/src/math/loongarch64/fminf.c > new file mode 100644 > index 00000000..94a0fa45 > --- /dev/null > +++ b/src/math/loongarch64/fminf.c > @@ -0,0 +1,7 @@ > +#include > + > +float fminf(float x, float y) > +{ > + __asm__ __volatile__("fmin.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); > + return x; > +} > diff --git a/src/math/loongarch64/llrint.c b/src/math/loongarch64/llrint.c > new file mode 100644 > index 00000000..766222d3 > --- /dev/null > +++ b/src/math/loongarch64/llrint.c > @@ -0,0 +1,17 @@ > +#include > +#include > + > +long long llrint(double x) > +{ > + long long r; > + > + __asm__ __volatile__( > + "frint.d %[x], %[orig_x] \n\t" > + "ftintrz.l.d %[x], %[x] \n\t" > + "movfr2gr.d %[result], %[x] \n\t" > + : [result]"+r"(r), [x]"+f"(x) > + : [orig_x]"f"(x) > + :); > + > + return r; > +} > diff --git a/src/math/loongarch64/llrintf.c b/src/math/loongarch64/llrintf.c > new file mode 100644 > index 00000000..f5b9dd9f > --- /dev/null > +++ b/src/math/loongarch64/llrintf.c > @@ -0,0 +1,17 @@ > +#include > +#include > + > +long long llrintf(float x) > +{ > + long long r; > + > + __asm__ __volatile__( > + "frint.s %[x], %[orig_x] \n\t" > + "ftintrz.w.s %[x], %[x] \n\t" > + "movfr2gr.s %[result], %[x] \n\t" > + : [result]"+r"(r), [x]"+f"(x) > + : [orig_x]"f"(x) > + :); > + > + return r; > +} > diff --git a/src/math/loongarch64/lrint.c b/src/math/loongarch64/lrint.c > new file mode 100644 > index 00000000..d82239d1 > --- /dev/null > +++ b/src/math/loongarch64/lrint.c > @@ -0,0 +1,17 @@ > +#include > +#include > + > +long lrint(double x) > +{ > + long r; > + > + __asm__ __volatile__( > + "frint.d %[x], %[orig_x] \n\t" > + "ftintrz.l.d %[x], %[x] \n\t" > + "movfr2gr.d %[result], %[x] \n\t" > + : [result]"+r"(r), [x]"+f"(x) > + : [orig_x]"f"(x) > + :); > + > + return r; > +} > diff --git a/src/math/loongarch64/lrintf.c b/src/math/loongarch64/lrintf.c > new file mode 100644 > index 00000000..b30872e9 > --- /dev/null > +++ b/src/math/loongarch64/lrintf.c > @@ -0,0 +1,17 @@ > +#include > +#include > + > +long lrintf(float x) > +{ > + long r; > + > + __asm__ __volatile__( > + "frint.s %[x], %[orig_x] \n\t" > + "ftintrz.l.s %[x], %[x] \n\t" > + "movfr2gr.s %[result], %[x] \n\t" > + : [result]"+r"(r), [x]"+f"(x) > + : [orig_x]"f"(x) > + :); > + > + return r; > +} > diff --git a/src/math/loongarch64/rint.c b/src/math/loongarch64/rint.c > new file mode 100644 > index 00000000..862cea8c > --- /dev/null > +++ b/src/math/loongarch64/rint.c > @@ -0,0 +1,7 @@ > +#include > + > +double rint(double x) > +{ > + __asm__ __volatile__("frint.d %0, %1" : "=f"(x) : "f"(x)); > + return x; > +} > diff --git a/src/math/loongarch64/rintf.c b/src/math/loongarch64/rintf.c > new file mode 100644 > index 00000000..79ac216b > --- /dev/null > +++ b/src/math/loongarch64/rintf.c > @@ -0,0 +1,7 @@ > +#include > + > +float rintf(float x) > +{ > + __asm__ __volatile__("frint.s %0, %1" : "=f"(x) : "f"(x)); > + return x; > +} > diff --git a/src/math/loongarch64/sqrt.c b/src/math/loongarch64/sqrt.c > new file mode 100644 > index 00000000..a70e20e9 > --- /dev/null > +++ b/src/math/loongarch64/sqrt.c > @@ -0,0 +1,7 @@ > +#include > + > +double sqrt(double x) > +{ > + __asm__ __volatile__("fsqrt.d %1, %0" : "=f"(x) : "f"(x)); > + return x; > +} > diff --git a/src/math/loongarch64/sqrtf.c b/src/math/loongarch64/sqrtf.c > new file mode 100644 > index 00000000..796609b0 > --- /dev/null > +++ b/src/math/loongarch64/sqrtf.c > @@ -0,0 +1,7 @@ > +#include > + > +float sqrtf(float x) > +{ > + __asm__ __volatile__("fsqrt.s %1, %0" : "=f"(x) : "f"(x)); > + return x; > +}