From patchwork Thu Aug 13 14:23:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Zhu X-Patchwork-Id: 141320 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F93D4BAE7DA for ; Thu, 13 Aug 2026 14:24:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F93D4BAE7DA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=WZgGlp1Y X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id AA7894B9DB49 for ; Thu, 13 Aug 2026 14:23:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA7894B9DB49 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AA7894B9DB49 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786631025; cv=none; b=PUNt+HGcphbhtQgEqml8LBe+3EOVVtObg9KvJI+2v9cCdrZ5dM3r5/I0o2oTda4fFxhwq6jVPH3U7bExCZjv/LvtXO7arWN8GN9KyOXuvuJnQDbpSJkw/Z9mozFvYXsCZBY4nDHsY1NoMzwLWlAdkasKJ/gS3Q3msXji/Fw80uA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786631025; c=relaxed/simple; bh=DcvNDsjwbxZo0K/BWLjalWSFIWeahuleFbhU0J4SssI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=giCLI+TkLAS/+xuloHwiaaRwszZ9B/ruW47IruQfpIwkLeqcOa14wH5ncfhb4bNBzvx7ongV2mp4l+PEY+elm4Y2YTqKQwWi25PgQ7wQTjhNm/9cvCbZIbgOC+L10Dq0rza/qD4QhbbN+dF6UGh2OU/Kx7LaOC92AAlSVni0xSw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=WZgGlp1Y DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA7894B9DB49 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-493b966dd74so5399565e9.3 for ; Thu, 13 Aug 2026 07:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786631024; x=1787235824; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=5gahzVSYWqD1/5rfHYk5YjmHg2Nx6uL4and1yMfirtQ=; b=WZgGlp1YPs8x2DaDw8vU55B1RfsNTfkph4dAOmwOQSSkX+eVsZl0w7yhxEkTSTc2oN kiReLMWvn7iEXapooVDcXkDJcjCqOau+CuJJ4HXcvTWpM2+Zcke212Sb64EB9JX1AyBf AHUrKIUMNuiBKzdJjBKAMiXFDXIo/ytaf98/83T8sx3pjF6g/fDQN67oEi+Ls2tHWVyS Qc8N5NNKazBr9wu1VYuL09p/B7L45/bbH5cRQ7XLJ689h+lplfNMx+zH+06pqYNtvH2b FHkir9QWDBzzDNADKW0gOO02NP4kAO2SKEvWK8NKG1vPHN/FQyT8/a+v5KF5lqSXOh1m gDWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786631024; x=1787235824; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5gahzVSYWqD1/5rfHYk5YjmHg2Nx6uL4and1yMfirtQ=; b=ffDeYYYIvXjExT79e81YWW7Wi6BdJ52g4kI7s8ajj0gzfaH0lyzuMKHjOBBOyuQtAw ovvKdM3ftwwbCLvhBZpVgfaKZQXlFyaa450w2nslE+7rnXxxfollRMYgpMkSmyIsMmuS yv2BMxcqlSpqx7JI4EIanlKsWa7306DNU+r/nCTfAB0ieXdchvKt82g98I7KMwCKdfoX GR5PjjW4KFdG3o88e0KikKaSKzQOV7FTTG0MM9CBylMf4fPSuGHS012s1Gsdrmnfh3sk zLl/id6PKR4yp31QX2vvNC9hggjiav7hRFY1ZPs4ibAYhSe124xsIJKVmwuzlN+2ZbvT Ic7Q== X-Gm-Message-State: AOJu0YymD3U1u6lY+DtreOxUd9LbvEFRdsYUnbQA+N/il+n7kwXRjjXo 6frG08zVzLjyDyFGdWcHy/ezuYsEf4S4Hox5nQ5tjLiWYzh+VOJ41CgVGNxOJwEapSQMOg== X-Gm-Gg: AR+sD12krNmThTJIMr/jfHGMwnPmRVoZpQFMb1vdaz6L9MIi6jOD2WTI7NnHoxW0vHj UFkPTOzv/rZdQRZeeZ/kc8JO6aEc1b+kMSKEvpKSAOHTj9cfmRMs5S8wxhyU0tMVFdMrjJ0ipr8 3OjJ8ZvmqvCnktTKbCEWNkjcWoCQSbergTEJb3aelrWmizQQnUnRkchItlqbVHg7BrENt1l9HXB S2Agk3DjqCRBINUObAUeMeDNx0jvFn9E2siXhcGaH8MYx9cIY3FZtAHS0oop/tGE/uDOBgthIVV VVLv+ZIs/qf6HinXiMIj0IezY5rrFb7JeXiWIHg4haY0GKuw7qXa8eeazRuSy9q7vcl9gsYTjLb fcJnLdpYEzsSRqCp8oO5+3SnrYhZnsuQjbzjN4i/c6L2jluT+LkFooVOH6A7OTL8xU5mdt9274U hBXYnYuSqxszTuoE1TAqt4EJSe8Z/vk5bnnfXwiwEq X-Received: by 2002:a05:600c:4e87:b0:499:79b9:e226 with SMTP id 5b1f17b1804b1-4998218496amr70317665e9.0.1786631024062; Thu, 13 Aug 2026 07:23:44 -0700 (PDT) Received: from localhost ([2a09:bac1:1e00:8::1d6:189]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4998212a3a1sm68430035e9.6.2026.08.13.07.23.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2026 07:23:42 -0700 (PDT) From: Julian Zhu To: libc-alpha@sourceware.org Cc: Julian Zhu Subject: [PATCH v2 1/4] riscv: Use builtins for the fmaximum and fminimum Date: Thu, 13 Aug 2026 22:23:17 +0800 Message-ID: <20260813142320.3617764-1-jz531210@gmail.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GB_FREEMAIL_NUM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@sourceware.org Enable the fmax and fmin builtins for the fmaximum{_num} and fminimum{_num}. The generic fmaximum{_num} and fminimum{_num} use them for ordered operands, on rv64gc the double-precision functions drop from 21, 26, 23 and 29 instructions to 8, 8, 14 and 14. fmax and fmin keep their own implementations, which need a signaling NaN check because the instruction returns the number where C requires a quiet NaN. The headers live in rvd because without floating-point registers GCC lowers the builtins to a call, which would recurse. Signed-off-by: Julian Zhu --- sysdeps/riscv/rvd/math-use-builtins-fmax.h | 15 +++++++++++++++ sysdeps/riscv/rvd/math-use-builtins-fmin.h | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 sysdeps/riscv/rvd/math-use-builtins-fmax.h create mode 100644 sysdeps/riscv/rvd/math-use-builtins-fmin.h diff --git a/sysdeps/riscv/rvd/math-use-builtins-fmax.h b/sysdeps/riscv/rvd/math-use-builtins-fmax.h new file mode 100644 index 0000000000..8865377475 --- /dev/null +++ b/sysdeps/riscv/rvd/math-use-builtins-fmax.h @@ -0,0 +1,15 @@ +/* This does not affect fmax and fmaxf, which have their own + implementations in rvd and rvf: the instruction returns the number for + a signaling NaN operand where C requires a quiet NaN, so they need an + explicit check. Only the fmaximum and fminimum families and hypot use + these builtins. */ +#if __GNUC_PREREQ (13, 0) +# define USE_FMAX_BUILTIN 1 +# define USE_FMAXF_BUILTIN 1 +#else +# define USE_FMAX_BUILTIN 0 +# define USE_FMAXF_BUILTIN 0 +#endif + +#define USE_FMAXL_BUILTIN 0 +#define USE_FMAXF128_BUILTIN 0 diff --git a/sysdeps/riscv/rvd/math-use-builtins-fmin.h b/sysdeps/riscv/rvd/math-use-builtins-fmin.h new file mode 100644 index 0000000000..06e46bf7dd --- /dev/null +++ b/sysdeps/riscv/rvd/math-use-builtins-fmin.h @@ -0,0 +1,15 @@ +/* This does not affect fmin and fminf, which have their own + implementations in rvd and rvf: the instruction returns the number for + a signaling NaN operand where C requires a quiet NaN, so they need an + explicit check. Only the fmaximum and fminimum families and hypot use + these builtins. */ +#if __GNUC_PREREQ (13, 0) +# define USE_FMIN_BUILTIN 1 +# define USE_FMINF_BUILTIN 1 +#else +# define USE_FMIN_BUILTIN 0 +# define USE_FMINF_BUILTIN 0 +#endif + +#define USE_FMINL_BUILTIN 0 +#define USE_FMINF128_BUILTIN 0