From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id C17F43858D35 for ; Thu, 7 Sep 2023 02:17:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C17F43858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 51767300089; Thu, 7 Sep 2023 02:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1694053030; bh=r5HNnD70xUxSa+CEKoqGsb5hY7C+JWXY8X7Ua8tC2D4=; h=From:To:Cc:Subject:Date:Message-ID:Mime-Version: Content-Transfer-Encoding; b=MXjl4j8wLMMV2y09mg/NC+3KzbJM7c1EzWgXdH4xKSUQStjIWcwOu2YK1zivRkyTL 2Jdku2YhxXYoaAM4GYdaKnREajaChXoFlVizqZlFnFL4VXYCFGPMwOFB298ALVAfif KpUgofGyRcGzZD5lOnaxnW4mgfB2+tk5swDNz+bA= From: Tsukasa OI To: Tsukasa OI , Kito Cheng , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [RFC PATCH 0/2] RISC-V: Change RISC-V bit manipulation / scalar crypto builtin types Date: Thu, 7 Sep 2023 02:17:00 +0000 Message-ID: Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KAM_MANYTO,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello, Many RISC-V builtins operate in signed integer types but in many cases, they are better to be unsigned. There are a few reasons to do that: 1. Being more natural For bit manipulation operations, the direct input and the result should have an unsigned type. e.g. __builtin_bswap16 Both input and output should be (and are) unsigned. e.g. __builtin_popcount The input should be (and is) unsigned. The output is a bit count and is in int (signed integer). 2. In parity with LLVM 17 LLVM made similar changes to this patch set in commit 599421ae36c3 ("[RISCV] Use unsigned instead of signed types for Zk* and Zb* builtins.") by Craig Topper. Note that shift amount / round number argument types are changed to unsigned in this LLVM commit, I did the same. 3. Minimum compatibility breakage This change rarely causes warnings even if both -Wall and -Wextra are specified. In fact, only applying PATCH 1/2 does not cause any additional test failures. PATCH 2/2 only contains testsuite changes (uses correct types as the builtin uses). But not completely compatible. For instance, we will notice when operating with for instance C++'s "auto" / "decltype" or overload resolution. So, I would like to hear your thoughts first. Note that, the only reason I separated this RFC patch set to two patches is to demonstrate that no additional warnings occur even if only PATCH 1/2 is applied. If approved or leaves an RFC PATCH, both will be merged. p.s. LLVM has another type of different builtin types (with the same name), scalar cryptography builtins that operate in 32-bit integers, not XLEN- specific (applies to SHA-256, SM3 and SM4). For those cases, GCC prefers XLEN-specific integer type but LLVM 17 always prefers uint32_t. This is a result of LLVM commit 599421ae36c3 ("[RISCV] Re-define sha256, Zksed, and Zksh intrinsics to use i32 types."). Because just changing the width causes errors on GCC, even if I change them to uint32_t, that would be in a different patch set. Sincerely, Tsukasa Tsukasa OI (2): RISC-V: Make bit manipulation value / round number and shift amount types for builtins unsigned RISC-V: Update testsuite for type-changed builtins gcc/config/riscv/riscv-builtins.cc | 7 +- gcc/config/riscv/riscv-cmo.def | 16 +-- gcc/config/riscv/riscv-ftypes.def | 24 ++-- gcc/config/riscv/riscv-scalar-crypto.def | 104 +++++++++--------- gcc/testsuite/gcc.target/riscv/zbc32.c | 6 +- gcc/testsuite/gcc.target/riscv/zbc64.c | 6 +- gcc/testsuite/gcc.target/riscv/zbkb32.c | 10 +- gcc/testsuite/gcc.target/riscv/zbkb64.c | 8 +- gcc/testsuite/gcc.target/riscv/zbkc32.c | 4 +- gcc/testsuite/gcc.target/riscv/zbkc64.c | 4 +- gcc/testsuite/gcc.target/riscv/zbkx32.c | 4 +- gcc/testsuite/gcc.target/riscv/zbkx64.c | 4 +- gcc/testsuite/gcc.target/riscv/zknd32.c | 4 +- gcc/testsuite/gcc.target/riscv/zknd64.c | 10 +- gcc/testsuite/gcc.target/riscv/zkne32.c | 4 +- gcc/testsuite/gcc.target/riscv/zkne64.c | 8 +- gcc/testsuite/gcc.target/riscv/zknh-sha256.c | 8 +- .../gcc.target/riscv/zknh-sha512-32.c | 12 +- .../gcc.target/riscv/zknh-sha512-64.c | 8 +- gcc/testsuite/gcc.target/riscv/zksed32.c | 4 +- gcc/testsuite/gcc.target/riscv/zksed64.c | 4 +- gcc/testsuite/gcc.target/riscv/zksh32.c | 4 +- gcc/testsuite/gcc.target/riscv/zksh64.c | 4 +- 23 files changed, 133 insertions(+), 134 deletions(-) base-commit: af88776caa20342482b11ccb580742a46c621250 -- 2.42.0