From patchwork Wed Aug 7 03:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Zeng X-Patchwork-Id: 1969773 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.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 4WdwJQ41hlz1yXs for ; Wed, 7 Aug 2024 13:14:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EDEEA3858289 for ; Wed, 7 Aug 2024 03:14:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tmtyylji0my4xnjeumjiw.icoremail.net (zg8tmtyylji0my4xnjeumjiw.icoremail.net [162.243.161.220]) by sourceware.org (Postfix) with ESMTP id 84A163858CD9 for ; Wed, 7 Aug 2024 03:13:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 84A163858CD9 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=eswincomputing.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eswincomputing.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 84A163858CD9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=162.243.161.220 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723000440; cv=none; b=D+lrQ2hnjlIJwEObR/O+XarbseNVll1x0bTvaReA1AeW31PEe4hH2MBvzlctmtsvqa6s2puoKuua0mG6t43UBu1la0KqTgfz1WZOCUZ+aqQHz5Joxx3HJgp6OgH9Dt1W94q7wU2+KI20mQ3GL6k7tq4cuyUysh1eXW4zUwfbBAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723000440; c=relaxed/simple; bh=Pwbi2ONI2dyMF2e/Zo3KQ+rHpgYAf6i7Ut71FkTuJtQ=; h=From:To:Subject:Date:Message-Id; b=EoNCM7NL27+XtR1P5UfASiY/3LGHKBhFJcPjYyqoO0KRc2RUUOGEdnzUWNIwgyULJRLdBARvlb3wdqH4NB1BTwGlKl0rj+muyABD0H5HLg9f6DzyonB7gb98Phq/DQ7lA3bNbpCPtirKLs/cTCM2mIJQofNZNBqLiUzRSlsOiwA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.38]) by app1 (Coremail) with SMTP id TAJkCgBXcp1w5rJmjdkAAA--.11216S4; Wed, 07 Aug 2024 11:13:53 +0800 (CST) From: Xiao Zeng To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, research_trasio@irq.a4lg.com, kito.cheng@gmail.com, palmer@dabbelt.com, zhengyu@eswincomputing.com, Xiao Zeng Subject: [PATCH v2 0/1] RISC-V: Support BF16 interfaces in libgcc Date: Wed, 7 Aug 2024 11:13:50 +0800 Message-Id: <20240807031351.46105-1-zengxiao@eswincomputing.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: TAJkCgBXcp1w5rJmjdkAAA--.11216S4 X-Coremail-Antispam: 1UD129KBjvJXoWxXFWDJFWkZr43KFWruF1fXrb_yoWrZw4kpr 13Jr13Jr18Jr13Jr1fJryUXr15Jr18Jr1UJr47Jr18Ar1UAr1UJr1UJr18JryUJryUJw1U Jr1UtF1UKr1UJwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk214x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK6svPMxAI w28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr 4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxG rwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8Jw CI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2 z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUov38UUUUU X-CM-SenderInfo: p2hqw5xldrqvxvzl0uprps33xlqjhudrp/ X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_L4, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org 1 Why should bf16 be modified to f16b? -------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------- There is such code: -------------------------------------------------------------------------------------------------------------- DEF_C99_BUILTIN (BUILT_IN_LOGB, "logb", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_LOGBF, "logbf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO) -------------------------------------------------------------------------------------------------------------- bf16 and f16 will conflict when expanded, but f16b and f16 will not. The previous code also used the symbol f16b: -------------------------------------------------------------------------------------------------------------- -DEF_GCC_BUILTIN (BUILT_IN_NANSF16B, "nansf16b", BT_FN_BFLOAT16_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) -DEF_GCC_BUILTIN (BUILT_IN_NEXTAFTERF16B, "nextafterf16b", BT_FN_BFLOAT16_BFLOAT16_BFLOAT16, ATTR_MATHFN_ERRNO) -------------------------------------------------------------------------------------------------------------- 2 Why should BUILT_IN_NANSF16B and BUILT_IN_NEXTAFTERF16B be deleted? -------------------------------------------------------------------------------------------------------------- -DEF_GCC_BUILTIN (BUILT_IN_NANSF16B, "nansf16b", BT_FN_BFLOAT16_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) -DEF_GCC_BUILTIN (BUILT_IN_NEXTAFTERF16B, "nextafterf16b", BT_FN_BFLOAT16_BFLOAT16_BFLOAT16, ATTR_MATHFN_ERRNO) -------------------------------------------------------------------------------------------------------------- In the general macro definition, it has already been processed to remove redundant code. -------------------------------------------------------------------------------------------------------------- #define DEF_GCC_FLOATN_NX_BUILTINS(ENUM, NAME, TYPE_MACRO, ATTRS) \ + DEF_GCC_BUILTIN (ENUM ## F16B, NAME "f16b", TYPE_MACRO (BFLOAT16), ATTRS) \ DEF_GCC_BUILTIN (ENUM ## F16, NAME "f16", TYPE_MACRO (FLOAT16), ATTRS) \ DEF_GCC_BUILTIN (ENUM ## F32, NAME "f32", TYPE_MACRO (FLOAT32), ATTRS) \ DEF_GCC_BUILTIN (ENUM ## F64, NAME "f64", TYPE_MACRO (FLOAT64), ATTRS) \ // and #define DEF_EXT_LIB_FLOATN_NX_BUILTINS(ENUM, NAME, TYPE_MACRO, ATTRS) \ + DEF_FLOATN_BUILTIN (ENUM ## F16B, NAME "f16b", TYPE_MACRO (BFLOAT16), ATTRS) \ DEF_FLOATN_BUILTIN (ENUM ## F16, NAME "f16", TYPE_MACRO (FLOAT16), ATTRS) \ DEF_FLOATN_BUILTIN (ENUM ## F32, NAME "f32", TYPE_MACRO (FLOAT32), ATTRS) \ DEF_FLOATN_BUILTIN (ENUM ## F64, NAME "f64", TYPE_MACRO (FLOAT64), ATTRS) \ -------------------------------------------------------------------------------------------------------------- 3 This modification will have an impact on all architectures that support BF16. I have completed the following tests: x86_64 bootstrap based on 18eb6ca136fcd22b381d222cab81265d812ea7b9 passed. riscv64 bootstrap based on a59c4e496fa916cb9a484a649aa1b4cebd6550f2 passed. The riscv64 regression passed. Xiao Zeng (1): RISC-V: Support BF16 interfaces in libgcc gcc/builtin-types.def | 30 ++++++++++++++++++++++++++++++ gcc/builtins.cc | 6 ++++++ gcc/builtins.def | 22 +++++++++++----------- gcc/c-family/c-cppbuiltin.cc | 2 +- gcc/fold-const-call.cc | 2 -- gcc/gencfn-macros.cc | 5 +++-- gcc/match.pd | 9 ++++++--- gcc/tree.h | 2 +- libgcc/Makefile.in | 6 +++--- libgcc/libgcc2.c | 20 ++++++++++++++------ libgcc/libgcc2.h | 14 ++++++++++++++ 11 files changed, 89 insertions(+), 29 deletions(-) diff --git a/gcc/c-family/c-cppbuiltin.cc b/gcc/c-family/c-cppbuiltin.cc index a80372c8991..273bb9cf028 100644 --- a/gcc/c-family/c-cppbuiltin.cc +++ b/gcc/c-family/c-cppbuiltin.cc @@ -1422,7 +1422,7 @@ c_cpp_builtins (cpp_reader *pfile) else if (bfloat16_type_node && mode == TYPE_MODE (bfloat16_type_node)) { - memcpy (suffix, "bf16", 5); + memcpy (suffix, "f16b", 5); memcpy (float_h_prefix, "BFLT16", 7); } else