From patchwork Wed Feb 4 18:15:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pincheng Wang X-Patchwork-Id: 59655 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 27C2C4BA23C7 for ; Wed, 4 Feb 2026 18:15:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27C2C4BA23C7 X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from cstnet.cn (smtp25.cstnet.cn [159.226.251.25]) by sourceware.org (Postfix) with ESMTPS id 2B2904BA2E08 for ; Wed, 4 Feb 2026 18:15:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B2904BA2E08 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=isrc.iscas.ac.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=isrc.iscas.ac.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2B2904BA2E08 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=159.226.251.25 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770228942; cv=none; b=p5VO8ncpCHJQEQAMsylPHuEsx5is1Uc+WPeFglmZMM74f1BS4UyEshAnMLp7Dtp00VitUuTDY4exbjDllNLVKDXbLdeTlweP8hGA4YZpj0XUYS2fexjNfFAyY/0nrA7k5c0U2FY59XGw2J9UzfwNUUy41DyAh2Ta416EMNFfS2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770228942; c=relaxed/simple; bh=Em4zk5IoxUTOG+iFms7u4Ns8oUk5sZ0qBmJzP9iN2Dk=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=Z9v3qtIgHPFRRtwVu7l3J7hEWwH1F4SV4NY8xjPb1V/IWTTolT1udilBL9Bugyv6OMMpeyB7L/XZ19FvhY2cHq2PkR+hr1mfLSit4xxZDThobgd8flFJbV4eVV0KiLqBBo8Wagq7fOljfVk6xqNX84xrZgbYRnzTYDn6SKpjNvc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B2904BA2E08 Received: from ROG.lan (unknown [118.251.177.185]) by APP-05 (Coremail) with SMTP id zQCowABX7A_GjINp+yx9Bw--.30190S2; Thu, 05 Feb 2026 02:15:35 +0800 (CST) From: Pincheng Wang To: newlib@sourceware.org Cc: pincheng.plct@isrc.iscas.ac.cn Subject: [RFC PATCH 0/2] Add RISC-V vector math library support Date: Thu, 5 Feb 2026 02:15:31 +0800 Message-Id: <20260204181533.1498013-1-pincheng.plct@isrc.iscas.ac.cn> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-CM-TRANSID: zQCowABX7A_GjINp+yx9Bw--.30190S2 X-Coremail-Antispam: 1UD129KBjvJXoWxXFW7GrWxKryDKry3WF4kJFb_yoW5WF18pF 4fGryrGw48Jr1fXrnrX3y0vr15Jas5G3W3Gr13Ja15Z3ykWw1vqFWqyw1rZa47Ja4UCFy7 XasrGr1ruw43ZrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyq14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r1j 6r4UM28EF7xvwVC2z280aVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r1j6r 4UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48J MxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfU5WlkUUUUU X-Originating-IP: [118.251.177.185] X-CM-SenderInfo: pslquxhhqjh1xofwqxxvufhxpvfd2hldfou0/ X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLOCKED 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: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org Hi all, This RFC patch series propose adding RISC-V Vector Extension (RVV) optimized math functions to newlib, starting with a vectorized implementation of sin(). The motivation is to enable automatic vectorization of math functions on RISC-V platforms with vector extensions, which can provide significant performance improvements for numerical applications. After applying the gcc vecmath patch[1], compiler supports automatic vectorzation using the vector ABI[2](also in RFC). When compiling with auto-vectorization enabled (-O3 -ffast-math), the compiler can replace scalar math function calls with vector variants if they are available in the math library. This patch series adds infrastructure support for building vector math functions conditionally via a newly added "--enable-vecmath" configure option (disabled by default), and a vectorized sin() implementation for RISC-V using intrinsics from the RISC-V Vector Extension. While adding the above option, I encountered an automake compatibility issue during math object copying. Therefore, commit 1 is dedicated to fixing that issue and does not involve any vector math changes. The vector sin implementation is derived from the SLEEF library (Boost licensed) and adapted for newlib's RISC-V target. It uses RVV 1.0 intrinsics and provides performance-optimized computation with proper handling of edge cases. To configure and build, use below command. configure --target=riscv64-unknown-elf \ --prefix=/opt/vecmath-newlib \ CFLAGS_FOR_TARGET="-O2 -march=rv64gcv -mabi=lp64d" \ --enable-vecmath To compile a program that can take benefit of this patch, use the patched[1] gcc and run command like below. /opt/vecmath-gcc/bin/riscv64-unknown-elf-gcc \ -O3 -ffast-math -march=rv64gcv \ --sysroot=/opt/vecmath-newlib \ -L/opt/vecmath-newlib/riscv64-unknown-elf/lib \ -I/opt/vecmath-newlib/riscv64-unknown-elf/include \ test_sin.c -o test_sin -lm Comments and suggestions are welcome! [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-November/667352.html [2] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/455 Thanks, Pincheng Wang Pincheng Wang (2): newlib: Fix automake 1.16 compatibility for math object copying newlib: Add RISC-V vector math library support newlib/Makefile.am | 26 +- newlib/configure.ac | 10 + newlib/libc/include/math.h | 1 + newlib/libm/machine/riscv/Makefile.inc | 5 + newlib/libm/machine/riscv/riscv-vec-math.h | 1461 ++++++++++++++++++++ newlib/libm/machine/riscv/vec_sin.c | 79 ++ 6 files changed, 1569 insertions(+), 13 deletions(-) create mode 100644 newlib/libm/machine/riscv/riscv-vec-math.h create mode 100644 newlib/libm/machine/riscv/vec_sin.c