From patchwork Wed Sep 11 14:19:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Zhu X-Patchwork-Id: 1983966 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3jQY3pKsz1y1C for ; Thu, 12 Sep 2024 00:20:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BCE78385DDFA for ; Wed, 11 Sep 2024 14:20:17 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from bogon.localdomain (unknown [182.118.239.68]) by sourceware.org (Postfix) with ESMTP id 583303858C98 for ; Wed, 11 Sep 2024 14:19:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 583303858C98 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=bogon.localdomain ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 583303858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=182.118.239.68 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726064400; cv=none; b=bvgyZKtPeFkGRdZSdY9pUfnAxxOXZwOhCELCm40ZnLbr8FJaxf+Z5G3b1GXKw4zT0HKR9MvmnDBmgj1ELttJN7LR9UA5LRzGkv0IpMELcpoiZhmR6+VQ5nn8mxRnFtC10Fe678kJ6wkpZ832tbrWQLeSYx5swupLdrAbxJb84Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726064400; c=relaxed/simple; bh=dwnWQHUanfvi63sus6hNp+XhVPgcIDj1GRLT3rMXLIU=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=JXmml7OCdpHHw4h2oWQUzGtTGxUb9u41JpsXxtfwsBEYWQYzrBJ5atUs3q37pzRqKFPMwhXD42/U95g00f7ulDtHpfx7nGx0rMr7HVairwhYunuc1OPf8qI0PIS3hWbJkwFsM8cbuoeQNuQPdYgA0gbT8WQaN4ie82I6Pqy+S88= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by bogon.localdomain (Postfix, from userid 501) id 905AD30AF0D0; Wed, 11 Sep 2024 22:19:54 +0800 (CST) From: Julian Zhu To: libc-alpha@sourceware.org Cc: Julian Zhu Subject: [PATCH 1/2] RISC-V: Add implementation for fmaximum and fminimum Date: Wed, 11 Sep 2024 22:19:51 +0800 Message-ID: <20240911141952.37217-1-jz531210@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, NML_ADSP_CUSTOM_MED, NO_DNS_FOR_FROM, RCVD_IN_PBL, SPF_HELO_NONE, SPF_NONE, SPOOFED_FREEMAIL, SPOOF_GMAIL_MID, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Implemented `fmaximum{f}` and `fminimum{f}` using hard-float `fclass.fmt` and `f{max,min}.fmt` instructions to generate more simplified code. Signed-off-by: Julian Zhu --- sysdeps/riscv/rvd/s_fmaximum.c | 36 +++++++++++++++++++++++++++++++++ sysdeps/riscv/rvd/s_fminimum.c | 36 +++++++++++++++++++++++++++++++++ sysdeps/riscv/rvf/s_fmaximumf.c | 36 +++++++++++++++++++++++++++++++++ sysdeps/riscv/rvf/s_fminimumf.c | 36 +++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 sysdeps/riscv/rvd/s_fmaximum.c create mode 100644 sysdeps/riscv/rvd/s_fminimum.c create mode 100644 sysdeps/riscv/rvf/s_fmaximumf.c create mode 100644 sysdeps/riscv/rvf/s_fminimumf.c diff --git a/sysdeps/riscv/rvd/s_fmaximum.c b/sysdeps/riscv/rvd/s_fmaximum.c new file mode 100644 index 0000000000..ef9f622b55 --- /dev/null +++ b/sysdeps/riscv/rvd/s_fmaximum.c @@ -0,0 +1,36 @@ +/* Return maximum of X and Y. RISC-V version. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +double +__fmaximum (double x, double y) +{ + double res; + + if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmax.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); + return res; + } +} +libm_alias_double (__fmaximum, fmaximum) diff --git a/sysdeps/riscv/rvd/s_fminimum.c b/sysdeps/riscv/rvd/s_fminimum.c new file mode 100644 index 0000000000..c46383af1e --- /dev/null +++ b/sysdeps/riscv/rvd/s_fminimum.c @@ -0,0 +1,36 @@ +/* Return minimum of X and Y. RISC-V version. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +double +__fminimum (double x, double y) +{ + double res; + + if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmin.d %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); + return res; + } +} +libm_alias_double (__fminimum, fminimum) diff --git a/sysdeps/riscv/rvf/s_fmaximumf.c b/sysdeps/riscv/rvf/s_fmaximumf.c new file mode 100644 index 0000000000..61a2bd0be8 --- /dev/null +++ b/sysdeps/riscv/rvf/s_fmaximumf.c @@ -0,0 +1,36 @@ +/* Return maximum of X and Y. RISC-V version. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +float +__fmaximumf (float x, float y) +{ + float res; + + if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmax.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); + return res; + } +} +libm_alias_float (__fmaximum, fmaximum) diff --git a/sysdeps/riscv/rvf/s_fminimumf.c b/sysdeps/riscv/rvf/s_fminimumf.c new file mode 100644 index 0000000000..9c657ad9ac --- /dev/null +++ b/sysdeps/riscv/rvf/s_fminimumf.c @@ -0,0 +1,36 @@ +/* Return minimum of X and Y. RISC-V version. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +float +__fminimumf (float x, float y) +{ + float res; + + if (__glibc_unlikely((_FCLASS (x) | _FCLASS (y)) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmin.s %0, %1, %2" : "=f" (res) : "f" (x), "f" (y)); + return res; + } +} +libm_alias_float (__fminimum, fminimum)