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)