From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id E33CD3858D39 for ; Sun, 31 Mar 2024 10:31:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E33CD3858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E33CD3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711881089; cv=none; b=uIxdqf7UPFUmJ3+/n6DBrEevhANr77uFX7FdbrJAlwaTqCSbtLR+H/be8rUsymSQ2cgr8AoV/skkOr4MrUYPWo85z8uVZSRaoTEhxT7QGsRuxJmGCocNezBjXVhyabYrV5IKZ+YjeRhGNjhX0nKnUHq96BPpoapGTE5hPQNEtC0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711881089; c=relaxed/simple; bh=HzEubBmKwqP4J1oWD60F/I3EiEfhYVd+JdJxG/R3Q9U=; h=Subject:To:From:Message-ID:Date:MIME-Version; b=ka3kgwFtxQXyRIPL9FZlymFblYK89fiuiudhGo4+y9PebrUmuraJRwWlqTwalDqFa1Jkp/hZ0wleb99kjjJkedP1Gx99zMB/eLARzV3d4q/hAVEWMYrmo4wXBvptNfPV16/nJS0omhM8FdNXOxt4MFaKktRw8+V6xerp+q22KGI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from loongson.cn (unknown [10.20.4.90]) by gateway (Coremail) with SMTP id _____8DxK+l8OwlmPaEhAA--.59281S3; Sun, 31 Mar 2024 18:31:24 +0800 (CST) Received: from [10.20.4.90] (unknown [10.20.4.90]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bxb896OwlmXBlvAA--.16107S2; Sun, 31 Mar 2024 18:31:22 +0800 (CST) Subject: Re: [PATCH] LoongArch: Add soft floating-point fe* function implementations. To: Joseph Myers Cc: libc-alpha@sourceware.org, adhemerval.zanella@linaro.org, xry111@xry111.site, xuchenghua@loongson.cn References: <20240326124623.1245676-1-caiyinyu@loongson.cn> <2193d4f3-6f55-1812-5923-2845226b3011@loongson.cn> From: caiyinyu Message-ID: Date: Sun, 31 Mar 2024 18:31:22 +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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID:AQAAf8Bxb896OwlmXBlvAA--.16107S2 X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW3JF4rCw47XryxArW3JrWDGFX_yoWxuw15pr Z7ur15trWfJFWxZrs7C3W8XF1rJa1UKF48WFy3ua48JrW3tr1rWryvvF9I9FyUX3y8JrW8 Zrn5JF12v3Z5Z3gCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUv0b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lc7I2V7IY0VAS07AlzV AYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8czVUUU UUU== X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00,BODY_8BITS,GIT_PATCH_0,KAM_DMARC_STATUS,KAM_SHORT,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 在 2024/3/28 上午1:10, Joseph Myers 写道: > On Wed, 27 Mar 2024, caiyinyu wrote: > >> Yes, this patch does make sense in both libc and libm and it can be proved by >> the following glibc tests: > Please explain more how it works. > >> All the functions Implemented in this patch are exported from libm.so the same >> as powerpc nofpu. > I'm talking about functions such as __adddf3 (which would need to be > exported from libc, not libm, to provide exceptions / rounding modes > support for software floating point). I don't see them in any Versions > file for LoongArch. > > Furthermore, this patch isn't changing sfp-machine.h for LoongArch, which > uses fpu_control.h to get rounding mode / exceptions state, and it isn't > changing how fpu_control.h uses constant 0 for that state in the > soft-float case. So I don't see how it would produce *working* exceptions > / rounding modes support for software floating-point arithmetic. I revised and submitted the version 2 patch: The main corrections in the version 2 patch are: 1. Correcting the nofpu libc files:  sim-full.c sfp-machine.h soft-supp.h. 2. Updating/modifying the fpu/nofpu libc Versions/libc.abilist/localplt.data files. v1: https://sourceware.org/pipermail/libc-alpha/2024-March/155597.html v2: https://sourceware.org/pipermail/libc-alpha/2024-March/155707.html LoongArch soft float support was added in version 2.37, but the fe* functions were not completely added. I want to backport this patch if possible (it requires some modifications) to the 2.37/38/39/master branch, so the version of the relevant symbols in  Versions is GLIBC_2.37. Here is the difference between v1 and v2 : 1. diff --git a/sysdeps/loongarch/nofpu/sim-full.c b/sysdeps/loongarch/nofpu/sim-full.c index a2bbb9f880..b10e5b2f4d 100644 --- a/sysdeps/loongarch/nofpu/sim-full.c +++ b/sysdeps/loongarch/nofpu/sim-full.c @@ -16,8 +16,22 @@     License along with the GNU C Library.  If not, see     .  */ +#include "soft-fp.h"  #include "soft-supp.h" +#include  /* By default, no exceptions should trap.  */  __thread int __sim_cw_thread;  libc_hidden_tls_def (__sim_cw_thread); + +void +__simulate_exceptions (int excepts) +{ +  int enable; +  __sim_cw_thread |= excepts; + +  enable = __sim_cw_thread & _FPU_ENABLE_MASK; +  if (excepts & __sim_cw_thread & (enable << ENABLE_SHIFT)) +    raise (SIGFPE); +} +libc_hidden_def (__simulate_exceptions) diff --git a/sysdeps/loongarch/nofpu/soft-supp.h b/sysdeps/loongarch/nofpu/soft-supp.h index 37d83399e8..8d3ba09764 100644 --- a/sysdeps/loongarch/nofpu/soft-supp.h +++ b/sysdeps/loongarch/nofpu/soft-supp.h @@ -18,3 +18,5 @@  extern __thread int __sim_cw_thread attribute_tls_model_ie;  libc_hidden_tls_proto (__sim_cw_thread, tls_model ("initial-exec")); + +extern void __simulate_exceptions (int excepts); diff --git a/sysdeps/loongarch/sfp-machine.h b/sysdeps/loongarch/sfp-machine.h index cbf66500db..eda6c66423 100644 --- a/sysdeps/loongarch/sfp-machine.h +++ b/sysdeps/loongarch/sfp-machine.h @@ -64,10 +64,6 @@      } \    while (0) -#define _FP_DECL_EX fpu_control_t _fcw - -#define FP_ROUNDMODE (_fcw & 0x300) -  #define FP_RND_NEAREST FE_TONEAREST  #define FP_RND_ZERO FE_TOWARDZERO  #define FP_RND_PINF FE_UPWARD @@ -82,6 +78,8 @@  #define _FP_TININESS_AFTER_ROUNDING 1  #ifdef __loongarch_hard_float +#define _FP_DECL_EX fpu_control_t _fcw +#define FP_ROUNDMODE (_fcw & 0x300)  #define FP_INIT_ROUNDMODE \    do \      { \ @@ -98,5 +96,12 @@    while (0)  #define FP_TRAPPING_EXCEPTIONS ((_fcw << 16) & 0x1f0000)  #else -#define FP_INIT_ROUNDMODE _fcw = FP_RND_NEAREST +#define FP_HANDLE_EXCEPTIONS    __simulate_exceptions (_fex) +#define FP_ROUNDMODE        (__sim_cw_thread & _FPU_RC_MASK) +#define FP_TRAPPING_EXCEPTIONS    (__sim_cw_thread & _FPU_ENABLE_MASK) + +extern __thread int __sim_cw_thread attribute_tls_model_ie; +libc_hidden_tls_proto (__sim_cw_thread, tls_model ("initial-exec")); +extern void __simulate_exceptions (int excepts); +libc_hidden_proto (__simulate_exceptions)  #endif 2. libc.abilist is too long so not listed here. diff --git a/sysdeps/loongarch/nofpu/Versions b/sysdeps/loongarch/nofpu/Versions index 6d7f6aae6c..73b6a71bbd 100644 --- a/sysdeps/loongarch/nofpu/Versions +++ b/sysdeps/loongarch/nofpu/Versions @@ -1,5 +1,13 @@  libc { +  GLIBC_2.37 { +    __adddf3; __addsf3; __divdf3; __divsf3; __eqdf2; __eqsf2; +    __extendsfdf2; __fixdfsi; __fixsfsi; +    __fixunsdfsi; __fixunssfsi; +    __floatsidf; __floatsisf; +    __gedf2; __gesf2; __ledf2; __lesf2; __muldf3; __mulsf3; +    __negdf2; __negsf2; __subdf3; __subsf3; __truncdfsf2; +  }    GLIBC_PRIVATE { -    __sim_cw_thread; +    __sim_cw_thread; __simulate_exceptions;    }  } diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/fpu/localplt.data b/sysdeps/unix/sysv/linux/loongarch/lp64/fpu/localplt.data new file mode 100644 index 0000000000..547b1c1b7f --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/fpu/localplt.data @@ -0,0 +1,7 @@ +# See scripts/check-localplt.awk for how this file is processed. +# PLT use is required for the malloc family and for matherr because +# users can define their own functions and have library internals call them. +libc.so: calloc +libc.so: free +libc.so: malloc +libc.so: realloc diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/nofpu/Implies b/sysdeps/unix/sysv/linux/loongarch/lp64/nofpu/Implies new file mode 100644 index 0000000000..1090fb545a --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/nofpu/Implies @@ -0,0 +1 @@ +loongarch/nofpu diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/nofpu/localplt.data b/sysdeps/unix/sysv/linux/loongarch/lp64/nofpu/localplt.data new file mode 100644 index 0000000000..d40826c783 --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/nofpu/localplt.data @@ -0,0 +1,23 @@ +# See scripts/check-localplt.awk for how this file is processed. +# PLT use is required for the malloc family and for matherr because +# users can define their own functions and have library internals call them. +libc.so: calloc +libc.so: free +libc.so: malloc +libc.so: realloc +libc.so: __fixsfsi +libc.so: __divsf3 +libc.so: __adddf3 +libc.so: __eqdf2 +libc.so: __gedf2 +libc.so: __floatsisf +libc.so: __eqsf2 +libc.so: __subsf3 +libc.so: __mulsf3 +libc.so: __muldf3 +libc.so: __subdf3 +libc.so: __divdf3 +libc.so: __ledf2 +libc.so: __floatsidf +libc.so: __extendsfdf2 +libc.so: __addsf3 >