From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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) -- 2.39.2