From patchwork Mon May 13 08:14:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1934585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=VZnF+7CT; dkim-atps=neutral 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 4VdC3X4JbKz20d6 for ; Mon, 13 May 2024 18:15:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6490B386F812 for ; Mon, 13 May 2024 08:15:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6490B386F812 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715588133; bh=Li5q0WP+zjrcUSuMM/6kg+HlxRr7YEpJXGhGZ1HYkXk=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=VZnF+7CTxdFfVzJaLK5rT832eOBww0WAO3zFemj6kG5EOremoxbgdisnE7jze8xf5 NB51xtPpxSBbjZc9RqKUxHTOmaC/Y+z6tQCIWW18jcahaaYaRL/r0ERTIOCRnw/San 3u50jrxS83y8/bG7ATW1d3ESPq7oNu4u24sSmCds= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-f49.google.com (mail-ot1-f49.google.com [209.85.210.49]) by sourceware.org (Postfix) with ESMTPS id F227738449C0 for ; Mon, 13 May 2024 08:14:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F227738449C0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F227738449C0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588088; cv=none; b=CByGMNkYNi8vjbvWTjohId73f/u425BMEo1Ia4dAS+CWfipP3yXOoMSHpEE5vHdKRjUwPJwISYxvX+ZWzkriwLelWfRd4tlvs7+InFWQw5j5mQakushkbITRRnbuz/FB8YQFTlw4MKrvZ/cDDzoj/xiVR54xC2eNEVbJzGB/9AI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588088; c=relaxed/simple; bh=PPvXH6SrvdgdO520sg1SiNjnjOs1ty67YpxgYkbUyL0=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=KpeGWix4VW52ZhNx77epmQ4Ibb6nuQeTlRBRYwOI8+y0VlGocW8Rm1bdyJnxgp2FBws+Lk6/Ci47syWGFuEIaBkho+BRtW7PMHcrnsI3bXl8eZlGBnKXfe4Ic7zDVbBCNeznxi1qkLQCzdNATLT5EumHPpArmn1RPa4s9fLTU38= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-f49.google.com with SMTP id 46e09a7af769-6f1027cf826so614612a34.1 for ; Mon, 13 May 2024 01:14:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715588077; x=1716192877; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Li5q0WP+zjrcUSuMM/6kg+HlxRr7YEpJXGhGZ1HYkXk=; b=W6Y5cJcaj3XO3KR6zopc5Wm2cFbIk3VffiwwNX3hc4FxGexdvShNrqoACmN4v04koB avEZWarQ3Q16R8M2m3ypZrV8ZJkaEicirT4j41qlIpibxKxWA9mw8LCtpGcvXn2MjHnh 64GpR7ldurEpUZ73OUNIsbZZklAVGvJVOHhm6C2IbdQUIpAr6+Qkc2kSqadgOtmB4IAe f3u60vtKUWoLT6LdJmZQq02Fg/RhE73DwVj8ci8p12UTG4OrTEHQBznvUTJj1hsUAA/z vvVRXo56hvK7nx5PSUkmrcNlWk+ffDmWEI8HEmm/9/MaYxDyw8Pr4e4xlHQk5S3Ovu77 BcpA== X-Gm-Message-State: AOJu0YxCfad+s2hODcanZDy+VwpsqKvy1gVXoYYJnG8MwIwVhF6HdCLw 7yiELb3JWuDDq/Y0aO1/1bD5PrMuNtgTTj/o8Xv2SvNZsMUmZ2BJi/ZXzZBH X-Google-Smtp-Source: AGHT+IFva7y51xGAmzevdzIVpBtKsmIvoeJLJ79gxSskzIUKUk0/263bABt3Y6OAQ0H86GnevmqYcA== X-Received: by 2002:a9d:4d1a:0:b0:6f0:5203:4fb5 with SMTP id 46e09a7af769-6f0e913d608mr10206772a34.20.1715588076887; Mon, 13 May 2024 01:14:36 -0700 (PDT) Received: from localhost.localdomain ([2409:8700:2482:720:5054:ff:fe12:3456]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6340c99b41dsm7219999a12.52.2024.05.13.01.14.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:14:36 -0700 (PDT) From: YunQiang Su To: libc-alpha@sourceware.org Subject: [PATCH 1/6] MIPSr6/math: Use builtin fma and fmaf Date: Mon, 13 May 2024 16:14:24 +0800 Message-Id: <20240513081429.1749898-2-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240513081429.1749898-1-syq@gcc.gnu.org> References: <20240513081429.1749898-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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 MIPSr6 has MADDF.s/MADDF.d instructions, which are fused. In MIPS ISA, double support can be subsetted. Only FMAF is enabled for this case. * sysdeps/mips/fpu/math-use-builtins-fma.h Signed-off-by: YunQiang Su --- sysdeps/mips/fpu/math-use-builtins-fma.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sysdeps/mips/fpu/math-use-builtins-fma.h diff --git a/sysdeps/mips/fpu/math-use-builtins-fma.h b/sysdeps/mips/fpu/math-use-builtins-fma.h new file mode 100644 index 0000000000..6e296fd4c0 --- /dev/null +++ b/sysdeps/mips/fpu/math-use-builtins-fma.h @@ -0,0 +1,13 @@ +#if __mips_isa_rev >= 6 +# if defined(__mips_single_float) +# define USE_FMA_BUILTIN 0 +# else +# define USE_FMA_BUILTIN 1 +# endif +# define USE_FMAF_BUILTIN 1 +#else +# define USE_FMA_BUILTIN 0 +# define USE_FMAF_BUILTIN 0 +#endif +#define USE_FMAL_BUILTIN 0 +#define USE_FMAF128_BUILTIN 0 From patchwork Mon May 13 08:14:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1934584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=IUFSdSpw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4VdC3W106Pz20d8 for ; Mon, 13 May 2024 18:15:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27B0D386F822 for ; Mon, 13 May 2024 08:15:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27B0D386F822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715588133; bh=8MN6ulr8i0BY1YhfnL/ltQ7jm5SxKThPiz2oPW6ik64=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=IUFSdSpwujQMFB8C3W/xgjF+uo5g9eVpotPqCsNBZ5Jt0yO6wCqBlsHEvkcU2Qvk7 2whovqKI+qvakfi5Ns4lBhM6IZFzhVLvAi4Y8IfZsGD01btNr5sKE0fT+AJyX2bKIG CKc+xqBUuThH4rHJu7kzaLmSDCGQpI5M4OnhMy24= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) by sourceware.org (Postfix) with ESMTPS id 806693844742 for ; Mon, 13 May 2024 08:14:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 806693844742 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 806693844742 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.53 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588086; cv=none; b=rNPU1Odm82tpv2cNIFK/hyYqarRW1LtYEc2YlY/6xaSuuRS1Gd81xxUQI7oHRdXz264R9Whs7Z3DoZ8xDDFFRvp4r+uCMrUS2YNaW/LXBKGt41J4GFIMEkpqWxawxdxZtriDBRUWjaClqw1AJcK76n1LBSiWz/ig3Mi/icMAiAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588086; c=relaxed/simple; bh=S5Mhis0jf3CuRkO6WP21FpQE531tAp6kjs7TiQwWKao=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=R0S6Ed7FASY15Ya0gdW2P3dU/1WOzYcV3ZNOIh5wbe3g0qMiuP0cmczrwosjx9GtrAjMJm2BG2Z3B95ftzx7uDvRUQ9B3X0bl8X28Z9RBE1BNOAVF61W9n3Eqg6Fvarks/Cqdh4UOOnpuReHXmanf9qTXQWl0JB6xAPTez7iAvc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6f112c8f2bfso38701a34.3 for ; Mon, 13 May 2024 01:14:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715588078; x=1716192878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8MN6ulr8i0BY1YhfnL/ltQ7jm5SxKThPiz2oPW6ik64=; b=sdNrWuwsz2QvVo+mHTAEh/vkq9SwCouMhH3GOBHxKUxqKN7hcg1OQcKwp8DEmBBTJm kJUDnQQifdr8G/3xfEY7lwmbv4+b5yLaLNuqC2f/U5YnNlfQ6zDvrQRB8/FMAmy0MrAL jSd82AtpjnCwZMz8TbnpLA0e9SetM/tXPLoONHFR1my/WIOUTsCtuPnJERRzl19j//P+ 5ouCTo9RFH1B/hJh6W9bBSh+d4xJiPr8D3TzZi3QXc9eZu0T+DazCLALgrkgaKhwMYFH uYMSQ3KQynLmSdgOY5uxqm9BflHJqkkOVWM6vmooEwpptyBk61VRlbchpDHoG8rq48nD Lspw== X-Gm-Message-State: AOJu0Yzju7nrLt/bwcV8yrj2Zq3bhs6/f8EzIMROLhPSHs1iJ3Qmm3F6 mWXs5hDx80en8eYUIL/3MZDjVx2PIoO3GS+7i7b2apHfgt2jLYh5r3cfT6go X-Google-Smtp-Source: AGHT+IHw5WfWC0OZ6jZR0HmAxmJe7sDb2p367HRcPUZPYf0kEhdtHgGPjfcsl8qKytPALQrD83O/Kw== X-Received: by 2002:a9d:6acf:0:b0:6f0:6361:2d86 with SMTP id 46e09a7af769-6f109ade0bcmr2864512a34.0.1715588078330; Mon, 13 May 2024 01:14:38 -0700 (PDT) Received: from localhost.localdomain ([2409:8700:2482:720:5054:ff:fe12:3456]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6340c99b41dsm7219999a12.52.2024.05.13.01.14.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:14:37 -0700 (PDT) From: YunQiang Su To: libc-alpha@sourceware.org Subject: [PATCH 2/6] MIPS/math: Define port-specific GET_HIGH_WORD Date: Mon, 13 May 2024 16:14:25 +0800 Message-Id: <20240513081429.1749898-3-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240513081429.1749898-1-syq@gcc.gnu.org> References: <20240513081429.1749898-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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 The generic implemention may issue some unneeded stack store and load operations. * sysdeps/mips/math_private.h Signed-off-by: YunQiang Su --- sysdeps/mips/math_private.h | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sysdeps/mips/math_private.h diff --git a/sysdeps/mips/math_private.h b/sysdeps/mips/math_private.h new file mode 100644 index 0000000000..4da8b0c2d9 --- /dev/null +++ b/sysdeps/mips/math_private.h @@ -0,0 +1,56 @@ +/* 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 + . */ + +#ifndef MIPS_MATH_PRIVATE_H +#define MIPS_MATH_PRIVATE_H 1 + +#include +#include +#include_next +#include + +#if defined(__mips_hard_float) && !defined(__mips_single_float) +# undef GET_HIGH_WORD +# if __mips_isa_rev >= 2 +# define GET_HIGH_WORD(i, d) \ + do \ + { \ + asm volatile("mfhc1 %0, %1" : "=r"(i) : "f"(d)); \ + } \ + while (0) +# elif defined(__mips64) +# define GET_HIGH_WORD(i, d) \ + do \ + { \ + long long di; \ + asm volatile("dmfc1 %0, %1" : "=r"(di) : "f"(d)); \ + i = di >> 32; \ + } \ + while (0) +# else +# define GET_HIGH_WORD(i, d) \ + do \ + { \ + long long tmp[1]; \ + asm volatile("sdc1 %1, %0" : "=m"(tmp) : "f"(d)); \ + (i) = tmp[0] >> 32; \ + } \ + while (0) +# endif +#endif /* __mips_hard_float && !__mips_single_float */ + +#endif /* MIPS_MATH_PRIVATE_H */ From patchwork Mon May 13 08:14:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1934586 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=xHN6KUWD; dkim-atps=neutral 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 4VdC3b6Y48z20d6 for ; Mon, 13 May 2024 18:15:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B50B3870844 for ; Mon, 13 May 2024 08:15:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B50B3870844 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715588138; bh=N6ky3TI/L9HTsbnUX44qIZsXeXFCCGuS2ndf9EJgttg=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=xHN6KUWDWYzgzNPhnWCB3MtlIkBYGWJG7/8lExQ1RULs4aGGa/Y9bVT2/wTKxp4m8 V50EIu2N2uNbEHurv3xafxLilelVwla2EaJOecy6zE3xYnwsYuiKYcDYgdNaKth7fr rHQ5ogGiGI/Qr4ydiJyjngMB7mkeuO/0JdKdcI8s= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by sourceware.org (Postfix) with ESMTPS id 028F4384388F for ; Mon, 13 May 2024 08:14:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 028F4384388F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 028F4384388F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.161.43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588088; cv=none; b=cezdOe/CgDnAP85JNmHGJRI4aev5tG3hHelczFkS16nzO5IvNVZooH9aggKP4RgSqPDtavH9rczVAhOp/FgECiloZxwc7V49mm2j7YRwkWTRlWpuMusAr8N//a8VP+3F1jLMekrGWC0diTrJw6ua8dGWqEXygij6ox9fPOlMRSQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588088; c=relaxed/simple; bh=wdBGmkmKUOOsO2QUeGX1W5uK/IrZotmzO3L8c/Y1pe4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=qboPvnaKAGaVHW5U9mJBjD0v118QQk/nRCvsJWKTKLCXCtzfSb68wvx8Se+0vRXmnvgms0BXhUX9osa/iF2urCZjnzQrwPOR2PRL1pq397IK1myBPJeNRmsg6oCGwoSbsD/Wg8kA+gc5Xu8RUTbPJnGjX8tNZjiULHjzTptq4Mo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5aa20adda1dso2483781eaf.1 for ; Mon, 13 May 2024 01:14:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715588080; x=1716192880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N6ky3TI/L9HTsbnUX44qIZsXeXFCCGuS2ndf9EJgttg=; b=ZN2v7A1YLGrF5LBhXv8P1TqA3mlw75c5rku2Chg8nfmCuSdBN01AUKWJmAkcS+q471 Op1g33Xuon9WBx4zPxDHQghYE8wYfQCvvMWTXUct2p/16CiVl9q4be2p8Tksy5kuDMM3 mcKPKneY7UiKFOU00X5wCBer4sT7CyAHS5N/OUB3rF8WqH4LfVJ4hqAl6GvHJRv9kYL/ 1Whyj9mPlH9KOqxbKDeLjqxmp5+v8+PbqGncWFpPWxT7QjIq2BqrSgwXWIQMxmt/uP/C vbtkYLD3AtZqjiiZNXmy8N1Q1kCeBD5vzeM7weIQC9aMBatd0PwvWYGr3PYBaBuwUW8F emwg== X-Gm-Message-State: AOJu0Yxp67CWXj2L0/dk2kiLNQV8UIVqHEKBMGnslJFEPizzY74JcBAQ PGGYu04+4nHvTIv6Dp0rwaavJkKNagkSbln0EOGvDGPA7zm5AA0NEKkZWLfb X-Google-Smtp-Source: AGHT+IFqEbg4rFnXSqHZbtZ5P4I3Zx+tvI0BnluMuAyymbvuapmyT9hL52RE6xNHn1ZclLLZFtaqGQ== X-Received: by 2002:a05:6358:d39b:b0:183:e9f8:19ad with SMTP id e5c5f4694b2df-193bb63ade1mr1133571155d.18.1715588079560; Mon, 13 May 2024 01:14:39 -0700 (PDT) Received: from localhost.localdomain ([2409:8700:2482:720:5054:ff:fe12:3456]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6340c99b41dsm7219999a12.52.2024.05.13.01.14.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:14:39 -0700 (PDT) From: YunQiang Su To: libc-alpha@sourceware.org Subject: [PATCH 3/6] MIPS/math: Implement optimized issignaling(f) Date: Mon, 13 May 2024 16:14:26 +0800 Message-Id: <20240513081429.1749898-4-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240513081429.1749898-1-syq@gcc.gnu.org> References: <20240513081429.1749898-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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 MIPSr6 introduces class.fmt instructions, which can help us to determine whether a number is sNAN. We define __mips_issignaling(f) as always inline in mips/math_private.h, and call them in s_issignaling(f).c. Issignaling operation is also used by some other functions, such as fmax. Inlining it can introduce better codesize and performance, due to libcall may issue some stack operations. * sysdeps/mips/fpu_control.h: Define FCLASS constants. * sysdeps/mips/ieee754/s_issignaling.c * sysdeps/mips/ieee754/s_issignalingf.c * sysdeps/mips/math_private.h: Define __mips_issignaling(f). Signed-off-by: YunQiang Su --- sysdeps/mips/fpu_control.h | 17 +++++++ sysdeps/mips/ieee754/s_issignaling.c | 28 ++++++++++++ sysdeps/mips/ieee754/s_issignalingf.c | 27 +++++++++++ sysdeps/mips/math_private.h | 65 +++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 sysdeps/mips/ieee754/s_issignaling.c create mode 100644 sysdeps/mips/ieee754/s_issignalingf.c diff --git a/sysdeps/mips/fpu_control.h b/sysdeps/mips/fpu_control.h index 3ceb34fc25..086293117e 100644 --- a/sysdeps/mips/fpu_control.h +++ b/sysdeps/mips/fpu_control.h @@ -127,6 +127,23 @@ extern void __mips_fpu_setcw (fpu_control_t) __THROW; /* Default control word set at startup. */ extern fpu_control_t __fpu_control; +# define _FCLASS_SNAN (1 << 0) +# define _FCLASS_QNAN (1 << 1) +# define _FCLASS_MINF (1 << 2) +# define _FCLASS_MNORM (1 << 3) +# define _FCLASS_MSUBNORM (1 << 4) +# define _FCLASS_MZERO (1 << 5) +# define _FCLASS_PINF (1 << 6) +# define _FCLASS_PNORM (1 << 7) +# define _FCLASS_PSUBNORM (1 << 8) +# define _FCLASS_PZERO (1 << 9) + +# define _FCLASS_ZERO (_FCLASS_MZERO | _FCLASS_PZERO) +# define _FCLASS_SUBNORM (_FCLASS_MSUBNORM | _FCLASS_PSUBNORM) +# define _FCLASS_NORM (_FCLASS_MNORM | _FCLASS_PNORM) +# define _FCLASS_INF (_FCLASS_MINF | _FCLASS_PINF) +# define _FCLASS_NAN (_FCLASS_SNAN | _FCLASS_QNAN) + #endif /* __mips_soft_float */ #endif /* fpu_control.h */ diff --git a/sysdeps/mips/ieee754/s_issignaling.c b/sysdeps/mips/ieee754/s_issignaling.c new file mode 100644 index 0000000000..3bf65f07a5 --- /dev/null +++ b/sysdeps/mips/ieee754/s_issignaling.c @@ -0,0 +1,28 @@ +/* issignaling(). MIPS 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 + +int +__issignaling (double x) +{ + return __mips_issignaling (x); +} +libm_hidden_def (__issignaling) diff --git a/sysdeps/mips/ieee754/s_issignalingf.c b/sysdeps/mips/ieee754/s_issignalingf.c new file mode 100644 index 0000000000..14863595bc --- /dev/null +++ b/sysdeps/mips/ieee754/s_issignalingf.c @@ -0,0 +1,27 @@ +/* issignalingf(). MIPS 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 + +int +__issignalingf (float x) +{ + return __mips_issignalingf (x); +} +libm_hidden_def (__issignalingf) diff --git a/sysdeps/mips/math_private.h b/sysdeps/mips/math_private.h index 4da8b0c2d9..6c388ddb64 100644 --- a/sysdeps/mips/math_private.h +++ b/sysdeps/mips/math_private.h @@ -53,4 +53,69 @@ # endif #endif /* __mips_hard_float && !__mips_single_float */ +/* Copy from sysdeps/ieee754/flt-32/s_issignalingf.c. + Function call can introduce lots for stack operations. Inline can even + reduce codesize. */ +static __always_inline int +__mips_issignalingf (float x) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float c; + int ret; + asm volatile("class.s %0, %1" : "=f"(c) : "f"(x)); + asm volatile("mfc1 %0, %1" : "=r"(ret) : "f"(c)); + return ret & _FCLASS_SNAN; +#else + uint32_t xi; + GET_FLOAT_WORD (xi, x); +# if HIGH_ORDER_BIT_IS_SET_FOR_SNAN + /* We only have to care about the high-order bit of x's significand, because + having it set (sNaN) already makes the significand different from that + used to designate infinity. */ + return (xi & 0x7fc00000) == 0x7fc00000; +# else + /* To keep the following comparison simple, toggle the quiet/signaling bit, + so that it is set for sNaNs. This is inverse to IEEE 754-2008 (as well as + common practice for IEEE 754-1985). */ + xi ^= 0x00400000; + /* We have to compare for greater (instead of greater or equal), because x's + significand being all-zero designates infinity not NaN. */ + return (xi & 0x7fffffff) > 0x7fc00000; +# endif +#endif +} + +/* Copy from sysdeps/ieee754/dbl-64/s_issignaling.c. + Function call can introduce lots for stack operations. Inline can even + reduce codesize. */ +static __always_inline int +__mips_issignaling (double x) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double c; + int ret; + asm volatile("class.d %0, %1" : "=f"(c) : "f"(x)); + asm volatile("mfc1 %0, %1" : "=r"(ret) : "f"(c)); + return ret & _FCLASS_SNAN; +#else + uint32_t xi; + GET_HIGH_WORD (xi, x); +# if HIGH_ORDER_BIT_IS_SET_FOR_SNAN + /* We only have to care about the high-order bit of x's significand, because + having it set (sNaN) already makes the significand different from that + used to designate infinity. */ + return (xi & UINT32_C (0x7ff80000)) == UINT32_C (0x7ff80000); +# else + /* To keep the following comparison simple, toggle the quiet/signaling bit, + so that it is set for sNaNs. This is inverse to IEEE 754-2008 (as well as + common practice for IEEE 754-1985). */ + xi ^= UINT32_C (0x00080000); + /* We have to compare for greater (instead of greater or equal), because x's + significand being all-zero designates infinity not NaN. */ + return (xi & UINT32_C (0x7fffffff)) > UINT32_C (0x7ff80000); +# endif +#endif +} + #endif /* MIPS_MATH_PRIVATE_H */ From patchwork Mon May 13 08:14:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1934589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=nhg7y8PJ; dkim-atps=neutral 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 4VdC6Q1rvrz20d6 for ; Mon, 13 May 2024 18:18:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C628386F47E for ; Mon, 13 May 2024 08:18:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C628386F47E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715588284; bh=+VSh6FArXfE/5AlfepS5ROtMqwf080Njr70v4cW+jm8=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=nhg7y8PJpFFFwZt6BMDQEJ8tXF+sx8WNS6yZrhliuNaZZ8jt5SNet8y1WXAlh5TC+ Qk74ZTog9m5IGvLXgVLe0yizIPL6CCYLsc6e93az9PmQ7MUpGGc+X7dBJ97y47efIo TU4oGkS3y2UT+9O3W1OPRKf1lDFVASzefVElPDH0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by sourceware.org (Postfix) with ESMTPS id 05000384384B for ; Mon, 13 May 2024 08:14:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05000384384B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 05000384384B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.178 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588088; cv=none; b=ggfKyLgqhz3LzXUsZ09al+DzZPwOSCg8i0FOq49CFhau9fP8olElLiT7bZEHymjFxD+8cb+enUHEpIu+ajPQIWysPrRFCyyjnoLZ0K+zP+dTEkTlh61o67Yk5IY+67kjiKS9mPe+x18XqGEzmLlSwppmmv6UJLz/EcbIuX9N9ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588088; c=relaxed/simple; bh=/oPvcFsq5yPEf6g19cfdAR1ctS/9+965a3tWIEWzN50=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=MGiuYIQJbcO13Fw3X3FSHHRigTYnbCtnctZViV5+ylZb82S2JaMP+tRbPQgz5LDxZgb9+76CjkNDtAR75KAifRL8ZMouj+WrLHpNXrEJRT8YU+tN8sjo8y2M7S8xeBzYOuU29GYiy99vuhYarXe9kKyqBus95mbmTVuI8lo0494= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6f4e59191a1so1898905b3a.1 for ; Mon, 13 May 2024 01:14:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715588081; x=1716192881; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+VSh6FArXfE/5AlfepS5ROtMqwf080Njr70v4cW+jm8=; b=KbGDd8H+9B7dGRWi8Qb2+QviMZRR5rdHLLFrIwhjTbXFCikvJuWMsJlVsHU91FKoEx w6Eo/aZKsk9R8QqwfL3umXw9DxctDiLxvPz1QWaottltXillHh8pqHYOdHtZr44S+Rbf fKRHsj9V/aMPZSbv2GEwhuWbTb6WrCgjNZSq/BuJ0bUF8WjDu0ErG+Uf+kdm5dd0ZTbu P7pk6IA0CBig8i6K9J4+xVX/WLsvkGFFP2EVN2KdXC3MHkyWxj5AtowoIzQPmIEijO7A HyHMahn3G2GgsTB97v1Gm1IfJ5fvqt4VwvT4uaypGhhdhgdQPO1ghHHh056SMp+Q6nfY HxhQ== X-Gm-Message-State: AOJu0Yyt3rZsDzoPtoeJ/w26vinkPU87NsdgcchcsYcCbWGV/PdpszEH ak3zXEXFBn30nflbkX1YdaESB9aQyNCH+0jpaeuao299dZDOrMcJyB+Pjpu4 X-Google-Smtp-Source: AGHT+IE2/tCb/+qDTVlMuz8piMIapq1bsrbdOq6d/mkHFhGEg7+r1hAwlIYdTR33HGxaJXHlBR1zrg== X-Received: by 2002:a05:6a00:21c6:b0:6ed:21d5:b03a with SMTP id d2e1a72fcca58-6f4e0355541mr10691701b3a.23.1715588081106; Mon, 13 May 2024 01:14:41 -0700 (PDT) Received: from localhost.localdomain ([2409:8700:2482:720:5054:ff:fe12:3456]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6340c99b41dsm7219999a12.52.2024.05.13.01.14.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:14:40 -0700 (PDT) From: YunQiang Su To: libc-alpha@sourceware.org Subject: [PATCH 4/6] MIPS/math: Implement optimized fmaximum/fminmum(, _mag)(, f) Date: Mon, 13 May 2024 16:14:27 +0800 Message-Id: <20240513081429.1749898-5-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240513081429.1749898-1-syq@gcc.gnu.org> References: <20240513081429.1749898-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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 MIPSr6 defines max/maxa/min/mina instructions, which have slight different with fmaximum/fminimum: return the number instead of NAN if NUM vs NAN. Detecting NAN is required before these instructions. Another problem of the generic implemention for MIPS is that, it use copysign for +0/-0 problem. In fact we can use GET_HIGH_WORD or GET_FLOAT_WORD, and then determine by the sign bit: int32_t xi; GET_HIGH_WORD (xi, x); return (xi < 0 ? y : x); GET_HIGH_WORD/GET_FLOAT_WORD are much more friendly to MIPS FPU. We can use `mfhc1` to GET_HIGH_WORD, and `mfc1` to GET_FLOAT_WORD. Since the abs.fmt instructions will signal if one operand is qNAN or sNaN, M_FABS, aka __builtin_fabs will issue at least 4 instructions (mfc1/ext/ins/mtc1). So detecting NaN is also required. * sysdeps/mips/ieee754/s_fmaximum.c * sysdeps/mips/ieee754/s_fmaximum_mag.c * sysdeps/mips/ieee754/s_fmaximum_magf.c * sysdeps/mips/ieee754/s_fmaximumf.c * sysdeps/mips/ieee754/s_fminimum.c * sysdeps/mips/ieee754/s_fminimum_mag.c * sysdeps/mips/ieee754/s_fminimum_magf.c * sysdeps/mips/ieee754/s_fminimumf.c Signed-off-by: YunQiang Su --- sysdeps/mips/ieee754/s_fmaximum.c | 48 ++++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaximum_mag.c | 57 ++++++++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaximum_magf.c | 55 +++++++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaximumf.c | 46 +++++++++++++++++++++ sysdeps/mips/ieee754/s_fminimum.c | 48 ++++++++++++++++++++++ sysdeps/mips/ieee754/s_fminimum_mag.c | 57 ++++++++++++++++++++++++++ sysdeps/mips/ieee754/s_fminimum_magf.c | 55 +++++++++++++++++++++++++ sysdeps/mips/ieee754/s_fminimumf.c | 46 +++++++++++++++++++++ 8 files changed, 412 insertions(+) create mode 100644 sysdeps/mips/ieee754/s_fmaximum.c create mode 100644 sysdeps/mips/ieee754/s_fmaximum_mag.c create mode 100644 sysdeps/mips/ieee754/s_fmaximum_magf.c create mode 100644 sysdeps/mips/ieee754/s_fmaximumf.c create mode 100644 sysdeps/mips/ieee754/s_fminimum.c create mode 100644 sysdeps/mips/ieee754/s_fminimum_mag.c create mode 100644 sysdeps/mips/ieee754/s_fminimum_magf.c create mode 100644 sysdeps/mips/ieee754/s_fminimumf.c diff --git a/sysdeps/mips/ieee754/s_fmaximum.c b/sysdeps/mips/ieee754/s_fmaximum.c new file mode 100644 index 0000000000..5a1e6a0313 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximum.c @@ -0,0 +1,48 @@ +/* fmaximum(). MIPS 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) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + /* MAX.d returns NUM if NUM vs qNAN. */ + if (isunordered (x, y)) + return x + y; + double ret; + asm volatile("max.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreater (x, y)) + return x; + else if (isless (x, y)) + return y; + if (isunordered (x, y)) + return x + y; + + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? y : x); +#endif +} + +libm_alias_double (__fmaximum, fmaximum) diff --git a/sysdeps/mips/ieee754/s_fmaximum_mag.c b/sysdeps/mips/ieee754/s_fmaximum_mag.c new file mode 100644 index 0000000000..0eac275167 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximum_mag.c @@ -0,0 +1,57 @@ +/* fmaximum_mag(). MIPS 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 +#include + +double +__fmaximum_mag (double x, double y) +{ + /* MAXA.d return NUM if NUM vs qNAN. ABS.d signals both sNAN and qNAN on + pre-R5. */ + if (isunordered (x, y)) + return x + y; +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("maxa.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + double ax; + double ay; +# if defined(__mips_hard_float) && !defined(__mips_single_float) + asm volatile("abs.d %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.d %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return x; + else if (isless (ax, ay)) + return y; + + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? y : x); +#endif +} + +libm_alias_double (__fmaximum_mag, fmaximum_mag) diff --git a/sysdeps/mips/ieee754/s_fmaximum_magf.c b/sysdeps/mips/ieee754/s_fmaximum_magf.c new file mode 100644 index 0000000000..dd871bac07 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximum_magf.c @@ -0,0 +1,55 @@ +/* fmaximum_magf(). MIPS 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 +__fmaximum_magf (float x, float y) +{ + /* MAXA.s return NUM if NUM vs qNAN. ABS.s signals both sNAN and qNAN on + pre-R5. */ + if (isunordered (x, y)) + return x + y; +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("maxa.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + float ax; + float ay; +# if defined(__mips_hard_float) + asm volatile("abs.s %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.s %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return x; + else if (isless (ax, ay)) + return y; + + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? y : x); +#endif +} + +libm_alias_float (__fmaximum_mag, fmaximum_mag) diff --git a/sysdeps/mips/ieee754/s_fmaximumf.c b/sysdeps/mips/ieee754/s_fmaximumf.c new file mode 100644 index 0000000000..a266ee76b6 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximumf.c @@ -0,0 +1,46 @@ +/* fmaximumf(). MIPS 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 + +float +__fmaximumf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + /* MAX.s returns NUM if NUM vs qNAN. */ + if (isunordered (x, y)) + return x + y; + float ret; + asm volatile("max.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreater (x, y)) + return x; + else if (isless (x, y)) + return y; + if (isunordered (x, y)) + return x + y; + + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? y : x); +#endif +} + +libm_alias_float (__fmaximum, fmaximum) diff --git a/sysdeps/mips/ieee754/s_fminimum.c b/sysdeps/mips/ieee754/s_fminimum.c new file mode 100644 index 0000000000..083da390ae --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimum.c @@ -0,0 +1,48 @@ +/* fminimum(). MIPS 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) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + /* MIN.d returns NUM if NUM vs qNAN. */ + if (isunordered (x, y)) + return x + y; + double ret; + asm volatile("min.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreater (x, y)) + return y; + else if (isless (x, y)) + return x; + if (isunordered (x, y)) + return x + y; + + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? x : y); +#endif +} + +libm_alias_double (__fminimum, fminimum) diff --git a/sysdeps/mips/ieee754/s_fminimum_mag.c b/sysdeps/mips/ieee754/s_fminimum_mag.c new file mode 100644 index 0000000000..7adaa1c279 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimum_mag.c @@ -0,0 +1,57 @@ +/* fminimum_mag(). MIPS 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 +#include + +double +__fminimum_mag (double x, double y) +{ + /* MINA.d return NUM if NUM vs qNAN. ABS.d signals both sNAN and qNAN on + pre-R5. */ + if (isunordered (x, y)) + return x + y; +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("mina.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + double ax; + double ay; +# if defined(__mips_hard_float) && !defined(__mips_single_float) + asm volatile("abs.d %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.d %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return y; + else if (isless (ax, ay)) + return x; + + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? x : y); +#endif +} + +libm_alias_double (__fminimum_mag, fminimum_mag) diff --git a/sysdeps/mips/ieee754/s_fminimum_magf.c b/sysdeps/mips/ieee754/s_fminimum_magf.c new file mode 100644 index 0000000000..6839e2914d --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimum_magf.c @@ -0,0 +1,55 @@ +/* fminimum_magf(). MIPS 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 +__fminimum_magf (float x, float y) +{ + /* MAXA.s return NUM if NUM vs qNAN. ABS.s signals both sNAN and qNAN on + pre-R5. */ + if (isunordered (x, y)) + return x + y; +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("mina.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + float ax; + float ay; +# if defined(__mips_hard_float) + asm volatile("abs.s %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.s %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return y; + else if (isless (ax, ay)) + return x; + + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? x : y); +#endif +} + +libm_alias_float (__fminimum_mag, fminimum_mag) diff --git a/sysdeps/mips/ieee754/s_fminimumf.c b/sysdeps/mips/ieee754/s_fminimumf.c new file mode 100644 index 0000000000..f37ca1c23b --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimumf.c @@ -0,0 +1,46 @@ +/* fminimumf(). MIPS 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 + +float +__fminimumf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + /* MIN.s returns NUM if NUM vs qNAN. */ + if (isunordered (x, y)) + return x + y; + float ret; + asm volatile("min.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreater (x, y)) + return y; + else if (isless (x, y)) + return x; + if (isunordered (x, y)) + return x + y; + + int xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? x : y); +#endif +} + +libm_alias_float (__fminimum, fminimum) From patchwork Mon May 13 08:14:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1934590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Q81JeJGA; dkim-atps=neutral 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 4VdC8G0vqKz20d6 for ; Mon, 13 May 2024 18:19:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32BDC386F45F for ; Mon, 13 May 2024 08:19:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 32BDC386F45F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715588380; bh=Ns1xLyDYZT+2uunlkMrDftuoaC841kDEd2hBzhROh3c=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=Q81JeJGAUwEep58Qvw5mtxjKp10ex+EMLwO94ipVwqVMf4ysQ5Rr7YudvPbu0Gyo6 XnCByJgLHX+s6UkFZGW3zgfJUG6+bMzKkRZn02I/dqX6VWhoMuDRHKzG8GonuSKSLN x/mtNA8aeFn4VQzekZ4jhuiTRPGvWEDBIgslK+kU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by sourceware.org (Postfix) with ESMTPS id 67759384385F for ; Mon, 13 May 2024 08:14:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 67759384385F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 67759384385F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.161.50 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588090; cv=none; b=mEeF2wGcGXJFNnmd/+XrTEbztVgwiYd06MQjzBXVuPcBnRdWjGBt6txWfcgdXadiBdxcnVGvINymQDEfGSK/P7bzFTUHBKMTYBKF6iepwM9216jxYGAoPX5SRqVSXmIu9UkunZtJcMlMJ7Tk6K4mFWOmsgMbVkSdPR3NJKzKTqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588090; c=relaxed/simple; bh=U0j5LL0WgS8n9H0ZZ2wZiMS4tHieT3dKHjmAKpyw1eI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=BIK3YeQAJStdeCFW80ofA01IKIuF4zYiU/K5aEQXvNrobS0LfFRv4gbnh3DkNp+Uz+yoF11k6e2lB+xNF/ev67WaF41Gng7yBbUnox9ZMByIuNH+af5CA4R+eYpciCckLgLf2H+N04cH58fFMeAgsScZWYQ505SKHriQ4naZJIA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5b283d2b1b4so1570162eaf.0 for ; Mon, 13 May 2024 01:14:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715588083; x=1716192883; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ns1xLyDYZT+2uunlkMrDftuoaC841kDEd2hBzhROh3c=; b=JPY4lrJ9vZHZEKba0odEaGDRMN2MG55YuT+IGOnAPwLbYTpkgFtLPWIURWm+6fKw4Y QTXTaoRMIiDZcxhgHHk15bCAozHVsgVCGcpmRVh9rrWSbTl+W5BnSHPVJklqVmYBSS3V 9po82RS3qM21dj0rnWfs4dophUVQaP6QS4Ns186PI3rieXUgzjHOI89z1+mh5dmUhiZk gg/QwRcoApBdNbDjpzAaIEdG1m6xHw3ig44R9ykLF/e5VeG9AWRsrfyXQ7Zz67YEKn2a w//+Y6UWxWqw5nMKQ//Y014ZP9iOuzhMLWG78qlzwBaIiVEywTWL19aEZexSxnpt9Wrw 9ZaA== X-Gm-Message-State: AOJu0YzPi1UkDvLcyr42HU0B/gTDSPr2/SlzU0rFBb8uhowU5I+sBdOm TkNH2arVAuv/vZaeM29p6Qjtfq2x6xmtrkJydvW6qOfXXfL8LA5GiaCXQa9F X-Google-Smtp-Source: AGHT+IFg7gqCCXgF+9HPTbMI5Hat6gEyhIjgkpQ9BqJAU7fGZ/Pv5me16z2FitASgYiBByvjhwcWaQ== X-Received: by 2002:a05:6358:2925:b0:183:6427:10b5 with SMTP id e5c5f4694b2df-193bcfc7770mr1194027155d.21.1715588082518; Mon, 13 May 2024 01:14:42 -0700 (PDT) Received: from localhost.localdomain ([2409:8700:2482:720:5054:ff:fe12:3456]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6340c99b41dsm7219999a12.52.2024.05.13.01.14.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:14:42 -0700 (PDT) From: YunQiang Su To: libc-alpha@sourceware.org Subject: [PATCH 5/6] MIPS/math: Implement optimized fmax(mag)(f)/fmin(mag)(f) Date: Mon, 13 May 2024 16:14:28 +0800 Message-Id: <20240513081429.1749898-6-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240513081429.1749898-1-syq@gcc.gnu.org> References: <20240513081429.1749898-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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 MIPSr6 instroduces min/mina/max/maxa instructions, which can be use for fmax(mag)(f)/fmin(mag) directly. For other cases, we continue to use the generic implemention, with our defined __mips_issignaling inline functions. Since abs.fmt instructions will signal for NAN, so we need to be sure that the operands is orderable first. * sysdeps/mips/ieee754/s_fmax.c * sysdeps/mips/ieee754/s_fmaxf.c * sysdeps/mips/ieee754/s_fmin.c * sysdeps/mips/ieee754/s_fminf.c * sysdeps/mips/ieee754/s_fmaxmag.c * sysdeps/mips/ieee754/s_fmaxmagf.c * sysdeps/mips/ieee754/s_fminmag.c * sysdeps/mips/ieee754/s_fminmagf.c --- sysdeps/mips/ieee754/s_fmax.c | 45 ++++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaxf.c | 43 +++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaxmag.c | 62 +++++++++++++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaxmagf.c | 61 ++++++++++++++++++++++++++++++ sysdeps/mips/ieee754/s_fmin.c | 44 ++++++++++++++++++++++ sysdeps/mips/ieee754/s_fminf.c | 43 +++++++++++++++++++++ sysdeps/mips/ieee754/s_fminmag.c | 62 +++++++++++++++++++++++++++++++ sysdeps/mips/ieee754/s_fminmagf.c | 61 ++++++++++++++++++++++++++++++ 8 files changed, 421 insertions(+) create mode 100644 sysdeps/mips/ieee754/s_fmax.c create mode 100644 sysdeps/mips/ieee754/s_fmaxf.c create mode 100644 sysdeps/mips/ieee754/s_fmaxmag.c create mode 100644 sysdeps/mips/ieee754/s_fmaxmagf.c create mode 100644 sysdeps/mips/ieee754/s_fmin.c create mode 100644 sysdeps/mips/ieee754/s_fminf.c create mode 100644 sysdeps/mips/ieee754/s_fminmag.c create mode 100644 sysdeps/mips/ieee754/s_fminmagf.c diff --git a/sysdeps/mips/ieee754/s_fmax.c b/sysdeps/mips/ieee754/s_fmax.c new file mode 100644 index 0000000000..190ca4a885 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmax.c @@ -0,0 +1,45 @@ +/* fmax(). MIPS 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 +__fmax (double x, double y) +{ + +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("max.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreaterequal (x, y)) + return x; + else if (isless (x, y)) + return y; + + if (__mips_issignaling (x) || __mips_issignaling (y)) + return x + y; + else + return isnan (y) ? x : y; +#endif +} + +libm_alias_double (__fmax, fmax) diff --git a/sysdeps/mips/ieee754/s_fmaxf.c b/sysdeps/mips/ieee754/s_fmaxf.c new file mode 100644 index 0000000000..358ddefc17 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaxf.c @@ -0,0 +1,43 @@ +/* fmaxf(). MIPS 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 +__fmaxf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("max.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreaterequal (x, y)) + return x; + else if (isless (x, y)) + return y; +#endif + + if (__mips_issignalingf (x) || __mips_issignalingf (y)) + return x + y; + else + return isnan (y) ? x : y; +} + +libm_alias_float (__fmax, fmax) diff --git a/sysdeps/mips/ieee754/s_fmaxmag.c b/sysdeps/mips/ieee754/s_fmaxmag.c new file mode 100644 index 0000000000..3f1b32afe9 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaxmag.c @@ -0,0 +1,62 @@ +/* fmaxmag(). MIPS 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 +#include + +double +__fmaxmag (double x, double y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("maxa.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + /* ABS.d signals both sNAN and qNAN on pre-R5. */ + if (!isunordered (x, y)) + { + double ax; + double ay; +# if defined(__mips_hard_float) && !defined(__mips_single_float) + asm volatile("abs.d %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.d %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return x; + else if (isless (ax, ay)) + return y; + + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? y : x); + } +#endif /* __mips_isa_rev >= 6 */ + + if (__mips_issignaling (x) || __mips_issignaling (y)) + return x + y; + else + return isnan (y) ? x : y; +} + +libm_alias_double (__fmaxmag, fmaxmag) diff --git a/sysdeps/mips/ieee754/s_fmaxmagf.c b/sysdeps/mips/ieee754/s_fmaxmagf.c new file mode 100644 index 0000000000..cfa44c773d --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaxmagf.c @@ -0,0 +1,61 @@ +/* fmaxmagf(). MIPS 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 +#include + +float +__fmaxmagf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("maxa.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + /* ABS.s signals both sNAN and qNAN on pre-R5. */ + if (!isunordered (x, y)) + { + float ax; + float ay; +# if defined(__mips_hard_float) + asm volatile("abs.s %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.s %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return x; + else if (isless (ax, ay)) + return y; + + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? y : x); + } +#endif /* __mips_isa_rev >= 6 */ + + if (__mips_issignalingf (x) || __mips_issignalingf (y)) + return x + y; + else + return isnan (y) ? x : y; +} + +libm_alias_float (__fmaxmag, fmaxmag) diff --git a/sysdeps/mips/ieee754/s_fmin.c b/sysdeps/mips/ieee754/s_fmin.c new file mode 100644 index 0000000000..56ff7100c4 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmin.c @@ -0,0 +1,44 @@ +/* fmin(). MIPS 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 +__fmin (double x, double y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("min.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreaterequal (x, y)) + return y; + else if (isless (x, y)) + return x; +#endif + + if (__mips_issignaling (x) || __mips_issignaling (y)) + return x + y; + else + return isnan (y) ? x : y; +} + +libm_alias_double (__fmin, fmin) diff --git a/sysdeps/mips/ieee754/s_fminf.c b/sysdeps/mips/ieee754/s_fminf.c new file mode 100644 index 0000000000..55c56183c1 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminf.c @@ -0,0 +1,43 @@ +/* fminf(). MIPS 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 +__fminf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("min.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + if (isgreaterequal (x, y)) + return y; + else if (isless (x, y)) + return x; +#endif + + if (__mips_issignalingf (x) || __mips_issignalingf (y)) + return x + y; + else + return isnan (y) ? x : y; +} + +libm_alias_float (__fmin, fmin) diff --git a/sysdeps/mips/ieee754/s_fminmag.c b/sysdeps/mips/ieee754/s_fminmag.c new file mode 100644 index 0000000000..bd115675f4 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminmag.c @@ -0,0 +1,62 @@ +/* fminmag(). MIPS 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 +#include + +double +__fminmag (double x, double y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("mina.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + /* ABS.d signals both sNAN and qNAN on pre-R5. */ + if (!isunordered (x, y)) + { + double ax; + double ay; +# if defined(__mips_hard_float) && !defined(__mips_single_float) + asm volatile("abs.d %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.d %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return y; + else if (isless (ax, ay)) + return x; + + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? x : y); + } +#endif /* __mips_isa_rev >= 6 */ + + if (__mips_issignaling (x) || __mips_issignaling (y)) + return x + y; + else + return isnan (y) ? x : y; +} + +libm_alias_double (__fminmag, fminmag) diff --git a/sysdeps/mips/ieee754/s_fminmagf.c b/sysdeps/mips/ieee754/s_fminmagf.c new file mode 100644 index 0000000000..8997ef05f7 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminmagf.c @@ -0,0 +1,61 @@ +/* fminmagf(). MIPS 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 +#include + +float +__fminmagf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("mina.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + return ret; +#else + /* ABS.s signals both sNAN and qNAN on pre-R5. */ + if (!isunordered (x, y)) + { + float ax; + float ay; +# if defined(__mips_hard_float) + asm volatile("abs.s %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.s %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return y; + else if (isless (ax, ay)) + return x; + + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? x : y); + } +#endif + + if (__mips_issignalingf (x) || __mips_issignalingf (y)) + return x + y; + else + return isnan (y) ? x : y; +} + +libm_alias_float (__fminmag, fminmag) From patchwork Mon May 13 08:14:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1934588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=gfbp0nqX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4VdC6F5842z20d6 for ; Mon, 13 May 2024 18:17:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4DD2386F429 for ; Mon, 13 May 2024 08:17:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E4DD2386F429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1715588275; bh=Z3RYKCG+W1+8ihQnrQ/G16S401jGtoEWIzJ8B2D/U28=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=gfbp0nqXNH9iPYVGex9jPTUZ6YJgzeZD6kMfc+5YqbcC94181zIbMag5Uq/ENOEkc ArHQ3g/BbUWnSdhPB57RHRxtZNIj0IidvRRY3woH4lUF5+57U/a+whD0LPVACtOHoN pobzlrjkz8C1fjre0JACVlsFebNcUVsT2yS8LRNY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by sourceware.org (Postfix) with ESMTPS id 5D9D63842FD9 for ; Mon, 13 May 2024 08:14:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D9D63842FD9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5D9D63842FD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588091; cv=none; b=stDZet6vlAevvHn3ft6OtxjcQGBIOJyofBafxZA9NsRJl7TLROM/7ORbs79KHxJMKh3ifqOuIciQ1Xl+gNPv7W3/oYU36RBjCAdVPXAoPUo4StKdJqS6kMCNi5eFQYFVpw2AEDvORa6kS317pcGP4Rua+pwh3B1rAD/fg6WvaoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715588091; c=relaxed/simple; bh=LDWlQbgfwISHPd/V8XaxCJns1pJVHiyjO8IsHXhTABc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=IGOnwXndyD3otmzymogi2jzMZoMXSVURJoPXrGen9neIwpgvJO8gr4SYIUjNHFoF7B07orHX2uBZvePnK9n3jentn86CAfO/H9gzMtNW3+DXp9txZ6/YLo49bNDLguJliCQqIuDYJ5xmCC0ZQOYNODYzClwRWMQ7tfMxT3I74e4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6f4603237e0so2760827b3a.0 for ; Mon, 13 May 2024 01:14:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715588085; x=1716192885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z3RYKCG+W1+8ihQnrQ/G16S401jGtoEWIzJ8B2D/U28=; b=Xc82VABaUhFEou3mzHzR/pkTezijjYs/4RLbzBsjVZM1O3l+jqlEORC6jNidUee9hU Jj7ZRlSNEmkq8GawLDp4UgdqzQcHV0bcEYRuwkJZc0TFblleciRcsq90fd/EyXWsiTHj DgQDAcGVBnsXc7biLEP/4enb5x9BRqtUDW2VNpIaQlAbeJZeck4EhQj4Zz9XhyRsGlmf DE2n43HXXsA0GeClWiqeVso4o+Lp+N0NGYzmTVpRHDaTv1NZ6PYUpkunIECXXBLmD3So s66wgsPl8fqVyZvDvMPHImrgqvIUOvdkj+7QbsTHydLluk1Be7aHb7OjI/OPA8q07d8I k7rg== X-Gm-Message-State: AOJu0YxoHKeZCKp+yWOs5T/cveHVrlMhuHdXm0jnnmAos+9Pp68Y9NPi GF5R/pNxbAW6oSFFbqKMrNZGPtpQ/NAxE33G0i7NfZyorAupRczOPHBFKHTI X-Google-Smtp-Source: AGHT+IEKgfalwY1BbAmko4mcVj/hx/5ehg8vf45NycE6rpS+brxB3a4hgiz8t1F07w7YyxyIPXWwVQ== X-Received: by 2002:a05:6a20:6a2b:b0:1af:af86:ce47 with SMTP id adf61e73a8af0-1afd1444bb2mr19185418637.14.1715588084461; Mon, 13 May 2024 01:14:44 -0700 (PDT) Received: from localhost.localdomain ([2409:8700:2482:720:5054:ff:fe12:3456]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6340c99b41dsm7219999a12.52.2024.05.13.01.14.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:14:43 -0700 (PDT) From: YunQiang Su To: libc-alpha@sourceware.org Subject: [PATCH 6/6] MIPS/math: Implement optimized f(max, min)imum(_mag)_num(f) Date: Mon, 13 May 2024 16:14:29 +0800 Message-Id: <20240513081429.1749898-7-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240513081429.1749898-1-syq@gcc.gnu.org> References: <20240513081429.1749898-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 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 MIPSr6 instroduces min.s/min.d/max.s/max.d instructions, which have slight different with fmaximum_num, when one operand is sNaN. In this case, these instructions will return qNaN, while fmaximum_num requires another operand. For pre-r6 with hardfloat, we determine whether NAN is present, so that we can use abs.fmt, which can boost performance. We also use GET_HIGH_WORD/GET_FLOAT_WORD instead of copysign for the equal cases. * sysdeps/mips/ieee754/s_fmaximum_num.c * sysdeps/mips/ieee754/s_fmaximum_numf.c * sysdeps/mips/ieee754/s_fminimum_num.c * sysdeps/mips/ieee754/s_fminimum_numf.c * sysdeps/mips/ieee754/s_fmaximum_mag_num.c * sysdeps/mips/ieee754/s_fmaximum_mag_numf.c * sysdeps/mips/ieee754/s_fminimum_mag_num.c * sysdeps/mips/ieee754/s_fminimum_mag_numf.c Signed-off-by: YunQiang Su --- sysdeps/mips/ieee754/s_fmaximum_mag_num.c | 65 ++++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaximum_mag_numf.c | 64 +++++++++++++++++++++ sysdeps/mips/ieee754/s_fmaximum_num.c | 54 ++++++++++++++++++ sysdeps/mips/ieee754/s_fmaximum_numf.c | 53 ++++++++++++++++++ sysdeps/mips/ieee754/s_fminimum_mag_num.c | 65 ++++++++++++++++++++++ sysdeps/mips/ieee754/s_fminimum_mag_numf.c | 64 +++++++++++++++++++++ sysdeps/mips/ieee754/s_fminimum_num.c | 54 ++++++++++++++++++ sysdeps/mips/ieee754/s_fminimum_numf.c | 53 ++++++++++++++++++ 8 files changed, 472 insertions(+) create mode 100644 sysdeps/mips/ieee754/s_fmaximum_mag_num.c create mode 100644 sysdeps/mips/ieee754/s_fmaximum_mag_numf.c create mode 100644 sysdeps/mips/ieee754/s_fmaximum_num.c create mode 100644 sysdeps/mips/ieee754/s_fmaximum_numf.c create mode 100644 sysdeps/mips/ieee754/s_fminimum_mag_num.c create mode 100644 sysdeps/mips/ieee754/s_fminimum_mag_numf.c create mode 100644 sysdeps/mips/ieee754/s_fminimum_num.c create mode 100644 sysdeps/mips/ieee754/s_fminimum_numf.c diff --git a/sysdeps/mips/ieee754/s_fmaximum_mag_num.c b/sysdeps/mips/ieee754/s_fmaximum_mag_num.c new file mode 100644 index 0000000000..83e9a28bed --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximum_mag_num.c @@ -0,0 +1,65 @@ +/* fmaximum_mag_num(). MIPS 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 +#include + +double +__fmaximum_mag_num (double x, double y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("maxa.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignaling (x)) + ret = x; + else if (!__mips_issignaling (y)) + ret = y; + } + return ret; +#else + double ax; + double ay; + /* ABS.d signals both sNAN and qNAN on pre-R5. */ + if (isunordered (x, y)) + return isnan (y) ? (isnan (x) ? x + y : x) : y; +# if defined(__mips_hard_float) && !defined(__mips_single_float) + asm volatile("abs.d %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.d %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return x; + else if (isless (ax, ay)) + return y; + else + { + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? y : x); + } +#endif +} + +libm_alias_double (__fmaximum_mag_num, fmaximum_mag_num) diff --git a/sysdeps/mips/ieee754/s_fmaximum_mag_numf.c b/sysdeps/mips/ieee754/s_fmaximum_mag_numf.c new file mode 100644 index 0000000000..c0e6589c00 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximum_mag_numf.c @@ -0,0 +1,64 @@ +/* fmaximum_mag_numf(). MIPS 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 +#include + +float +__fmaximum_mag_numf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("maxa.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignalingf (x)) + ret = x; + else if (!__mips_issignalingf (y)) + ret = y; + } + return ret; +#else + float ax; + float ay; + /* ABS.s signals both sNAN and qNAN on pre-R5. */ + if (isunordered (x, y)) + return isnan (y) ? (isnan (x) ? x + y : x) : y; +# if defined(__mips_hard_float) + asm volatile("abs.s %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.s %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return x; + else if (isless (ax, ay)) + return y; + else + { + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? y : x); + } +#endif +} + +libm_alias_float (__fmaximum_mag_num, fmaximum_mag_num) diff --git a/sysdeps/mips/ieee754/s_fmaximum_num.c b/sysdeps/mips/ieee754/s_fmaximum_num.c new file mode 100644 index 0000000000..85816a12be --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximum_num.c @@ -0,0 +1,54 @@ +/* fmaximum_num(). MIPS 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_num (double x, double y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("max.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignaling (x)) + ret = x; + else if (!__mips_issignaling (y)) + ret = y; + } + return ret; +#else + if (isgreater (x, y)) + return x; + else if (isless (x, y)) + return y; + else if (x == y) + { + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? y : x); + } + else + return isnan (y) ? (isnan (x) ? x + y : x) : y; +#endif +} + +libm_alias_double (__fmaximum_num, fmaximum_num) diff --git a/sysdeps/mips/ieee754/s_fmaximum_numf.c b/sysdeps/mips/ieee754/s_fmaximum_numf.c new file mode 100644 index 0000000000..1047f354be --- /dev/null +++ b/sysdeps/mips/ieee754/s_fmaximum_numf.c @@ -0,0 +1,53 @@ +/* fmaximum_numf(). MIPS 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 +__fmaximum_numf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("max.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignalingf (x)) + ret = x; + if (!__mips_issignalingf (y)) + ret = y; + } + return ret; +#else + if (isgreater (x, y)) + return x; + else if (isless (x, y)) + return y; + else if (x == y) + { + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? y : x); + } + else + return isnan (y) ? (isnan (x) ? x + y : x) : y; +#endif +} + +libm_alias_float (__fmaximum_num, fmaximum_num) diff --git a/sysdeps/mips/ieee754/s_fminimum_mag_num.c b/sysdeps/mips/ieee754/s_fminimum_mag_num.c new file mode 100644 index 0000000000..a6df931aaf --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimum_mag_num.c @@ -0,0 +1,65 @@ +/* fminimum_mag_num(). MIPS 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 +#include + +double +__fminimum_mag_num (double x, double y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("mina.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignaling (x)) + ret = x; + else if (!__mips_issignaling (y)) + ret = y; + } + return ret; +#else + double ax; + double ay; + /* ABS.d signals both sNAN and qNAN on pre-R5. */ + if (isunordered (x, y)) + return isnan (y) ? (isnan (x) ? x + y : x) : y; +# if defined(__mips_hard_float) && !defined(__mips_single_float) + asm volatile("abs.d %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.d %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return y; + else if (isless (ax, ay)) + return x; + else + { + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? x : y); + } +#endif +} + +libm_alias_double (__fminimum_mag_num, fminimum_mag_num) diff --git a/sysdeps/mips/ieee754/s_fminimum_mag_numf.c b/sysdeps/mips/ieee754/s_fminimum_mag_numf.c new file mode 100644 index 0000000000..74d189b380 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimum_mag_numf.c @@ -0,0 +1,64 @@ +/* fminimum_mag_numf(). MIPS 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 +#include + +float +__fminimum_mag_numf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("mina.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignalingf (x)) + ret = x; + else if (!__mips_issignalingf (y)) + ret = y; + } + return ret; +#else + float ax; + float ay; + /* ABS.s signals both sNAN and qNAN on pre-R5. */ + if (isunordered (x, y)) + return isnan (y) ? (isnan (x) ? x + y : x) : y; +# if defined(__mips_hard_float) + asm volatile("abs.s %0, %1" : "=f"(ax) : "f"(x)); + asm volatile("abs.s %0, %1" : "=f"(ay) : "f"(y)); +# else + ax = M_FABS (x); + ay = M_FABS (y); +# endif + if (isgreater (ax, ay)) + return y; + else if (isless (ax, ay)) + return x; + else + { + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? x : y); + } +#endif +} + +libm_alias_float (__fminimum_mag_num, fminimum_mag_num) diff --git a/sysdeps/mips/ieee754/s_fminimum_num.c b/sysdeps/mips/ieee754/s_fminimum_num.c new file mode 100644 index 0000000000..62fd139d63 --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimum_num.c @@ -0,0 +1,54 @@ +/* fminimum_num(). MIPS 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_num (double x, double y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) \ + && !defined(__mips_single_float) + double ret; + asm volatile("min.d %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignaling (x)) + ret = x; + if (!__mips_issignaling (y)) + ret = y; + } + return ret; +#else + if (isgreater (x, y)) + return y; + else if (isless (x, y)) + return x; + else if (x == y) + { + int32_t xi; + GET_HIGH_WORD (xi, x); + return (xi < 0 ? x : y); + } + else + return isnan (y) ? (isnan (x) ? x + y : x) : y; +#endif +} + +libm_alias_double (__fminimum_num, fminimum_num) diff --git a/sysdeps/mips/ieee754/s_fminimum_numf.c b/sysdeps/mips/ieee754/s_fminimum_numf.c new file mode 100644 index 0000000000..37d66ff6fa --- /dev/null +++ b/sysdeps/mips/ieee754/s_fminimum_numf.c @@ -0,0 +1,53 @@ +/* fminimum_numf(). MIPS 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 +__fminimum_numf (float x, float y) +{ +#if __mips_isa_rev >= 6 && defined(__mips_hard_float) + float ret; + asm volatile("min.s %0, %1, %2" : "=f"(ret) : "f"(x), "f"(y)); + if (isnan (ret)) + { + if (!__mips_issignalingf (x)) + ret = x; + if (!__mips_issignalingf (y)) + ret = y; + } + return ret; +#else + if (isgreater (x, y)) + return y; + else if (isless (x, y)) + return x; + else if (x == y) + { + int32_t xi; + GET_FLOAT_WORD (xi, x); + return (xi < 0 ? x : y); + } + else + return isnan (y) ? (isnan (x) ? x + y : x) : y; +#endif +} + +libm_alias_float (__fminimum_num, fminimum_num)