From patchwork Wed Aug 7 03:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Zeng X-Patchwork-Id: 1969774 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=8.43.85.97; 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 [8.43.85.97]) (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 4WdwKH2QHTz1ybS for ; Wed, 7 Aug 2024 13:15:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9261D3858416 for ; Wed, 7 Aug 2024 03:15:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from zg8tmja5ljk3lje4ms43mwaa.icoremail.net (zg8tmja5ljk3lje4ms43mwaa.icoremail.net [209.97.181.73]) by sourceware.org (Postfix) with ESMTP id 00B203858429 for ; Wed, 7 Aug 2024 03:14:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00B203858429 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 00B203858429 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.97.181.73 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723000447; cv=none; b=XVFYUkKi8GRQakUYPe7F02XsMJu+QTGI/ksaHjM7pXO6uhUwkf65ISXEFDzqbZzcoPJdxeZw8qy1oIUgI95D03UP03xtpa9oAiN5Cioo2Vq40DzRKuCpqq1c2VoTm4AifUe/M5Fj2NfiEsGulks5jwYdliRQ+lHIzpABPUtWLsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723000447; c=relaxed/simple; bh=YbdWcmTn5w9qboasqG4Ljjh7oWtS2wnYnh/zyGXrxtY=; h=From:To:Subject:Date:Message-Id; b=E6e1GxrEgU70xRwmSKDg2LK2fRWPmkY83ThP2p4Kp11RWI1JuDw3U+U5zYBut2AI1bkslviJYWmb5btfUFMoOyha/dmSugkvPx2SxSPUF+azhZpzImbKvLffJB9i3TrMITa69UBvnT7sOfbuwNHghHqh3/VUXHI7GAgod0CnCxo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (unknown [10.12.130.38]) by app1 (Coremail) with SMTP id TAJkCgBXcp1w5rJmjdkAAA--.11216S5; Wed, 07 Aug 2024 11:13:55 +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 1/1] RISC-V: Support BF16 interfaces in libgcc Date: Wed, 7 Aug 2024 11:13:51 +0800 Message-Id: <20240807031351.46105-2-zengxiao@eswincomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240807031351.46105-1-zengxiao@eswincomputing.com> References: <20240807031351.46105-1-zengxiao@eswincomputing.com> X-CM-TRANSID: TAJkCgBXcp1w5rJmjdkAAA--.11216S5 X-Coremail-Antispam: 1UD129KBjvAXoWfuF1xAr43tFW8Zry8uw4rXwb_yoW5GrW5Go W2gr4UtryfKF1kZayfu3yaqrW8ua1rKrWfXF4Fqas5Aa9xArWUGw1DA398Gasayayxuwsr Ca1xJwnrt3yxXr1Dn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYA7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r18M28IrcIa0x kI8VCY1x0267AKxVWUCVW8JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84AC jcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr 1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK6svPMxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2Iq xVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42 IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aV CY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbF_M3UUUUU== X-CM-SenderInfo: p2hqw5xldrqvxvzl0uprps33xlqjhudrp/ X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, UPPERCASE_50_75 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 gcc/ChangeLog: * builtin-types.def (BT_COMPLEX_BFLOAT16): Support BF16 node. (BT_BFLOAT16_PTR): Ditto. (BT_FN_BFLOAT16): New. (BT_FN_BFLOAT16_BFLOAT16): Ditto. (BT_FN_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16): Ditto. (BT_FN_BFLOAT16_COMPLEX_BFLOAT16): Ditto. (BT_FN_INT_BFLOAT16): Ditto. (BT_FN_LONG_BFLOAT16): Ditto. (BT_FN_LONGLONG_BFLOAT16): Ditto. (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16PTR): Ditto. (BT_FN_BFLOAT16_BFLOAT16_INT): Ditto. (BT_FN_BFLOAT16_BFLOAT16_INTPTR): Ditto. (BT_FN_BFLOAT16_BFLOAT16_LONG): Ditto. (BT_FN_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16): Ditto. (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16_BFLOAT16): Ditto. (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16_INTPTR): Ditto. * builtins.cc (expand_builtin_classify_type): Support BF16. (mathfn_built_in_2): Ditto. (CASE_MATHFN_FLOATN): Ditto. * builtins.def (DEF_GCC_FLOATN_NX_BUILTINS): Ditto. (DEF_EXT_LIB_FLOATN_NX_BUILTINS): Ditto. (BUILT_IN_NANSF16B): Added in general processing, redundant is removed here. (BUILT_IN_NEXTAFTERF16B): Ditto. * fold-const-call.cc (fold_const_call): Ditto. (fold_const_call_sss): Ditto. * gencfn-macros.cc: Support BF16. * match.pd: Like FP16, add optimization for BF16. * tree.h (CASE_FLT_FN_FLOATN_NX): Support BF16. gcc/c-family/ChangeLog: * c-cppbuiltin.cc (c_cpp_builtins): Modify suffix names to avoid conflicts. libgcc/ChangeLog: * Makefile.in: Add _mulbc3 and _divbc3. * libgcc2.c (if): Ditto. (defined): Ditto. (MTYPE): Macros defined for BF16. (CTYPE): Ditto. (AMTYPE): Ditto. (MODE): Ditto. (CEXT): Ditto. (NOTRUNC): Ditto. * libgcc2.h (LIBGCC2_HAS_BF_MODE): Support BF16. (__attribute__): Ditto. (__divbc3): Add __divbc3 declaration. (__mulbc3): Add __mulbc3 declaration. Signed-off-by: Xiao Zeng --- 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/builtin-types.def b/gcc/builtin-types.def index c97d6bad1de..6980873f2f1 100644 --- a/gcc/builtin-types.def +++ b/gcc/builtin-types.def @@ -109,6 +109,10 @@ DEF_PRIMITIVE_TYPE (BT_FLOAT128X, (float128x_type_node DEF_PRIMITIVE_TYPE (BT_COMPLEX_FLOAT, complex_float_type_node) DEF_PRIMITIVE_TYPE (BT_COMPLEX_DOUBLE, complex_double_type_node) DEF_PRIMITIVE_TYPE (BT_COMPLEX_LONGDOUBLE, complex_long_double_type_node) +DEF_PRIMITIVE_TYPE (BT_COMPLEX_BFLOAT16, (bfloat16_type_node + ? build_complex_type + (bfloat16_type_node) + : error_mark_node)) DEF_PRIMITIVE_TYPE (BT_COMPLEX_FLOAT16, (float16_type_node ? build_complex_type (float16_type_node) @@ -163,6 +167,9 @@ DEF_PRIMITIVE_TYPE (BT_CONST_DOUBLE_PTR, (build_qualified_type (double_type_node, TYPE_QUAL_CONST))) DEF_PRIMITIVE_TYPE (BT_LONGDOUBLE_PTR, long_double_ptr_type_node) +DEF_PRIMITIVE_TYPE (BT_BFLOAT16_PTR, (bfloat16_type_node + ? build_pointer_type (bfloat16_type_node) + : error_mark_node)) DEF_PRIMITIVE_TYPE (BT_FLOAT16_PTR, (float16_type_node ? build_pointer_type (float16_type_node) : error_mark_node)) @@ -239,6 +246,7 @@ DEF_FUNCTION_TYPE_0 (BT_FN_DOUBLE, BT_DOUBLE) distinguish it from two types in sequence, "long" followed by "double". */ DEF_FUNCTION_TYPE_0 (BT_FN_LONGDOUBLE, BT_LONGDOUBLE) +DEF_FUNCTION_TYPE_0 (BT_FN_BFLOAT16, BT_BFLOAT16) DEF_FUNCTION_TYPE_0 (BT_FN_FLOAT16, BT_FLOAT16) DEF_FUNCTION_TYPE_0 (BT_FN_FLOAT32, BT_FLOAT32) DEF_FUNCTION_TYPE_0 (BT_FN_FLOAT64, BT_FLOAT64) @@ -257,6 +265,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT_FLOAT, BT_FLOAT, BT_FLOAT) DEF_FUNCTION_TYPE_1 (BT_FN_DOUBLE_DOUBLE, BT_DOUBLE, BT_DOUBLE) DEF_FUNCTION_TYPE_1 (BT_FN_LONGDOUBLE_LONGDOUBLE, BT_LONGDOUBLE, BT_LONGDOUBLE) +DEF_FUNCTION_TYPE_1 (BT_FN_BFLOAT16_BFLOAT16, BT_BFLOAT16, BT_BFLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT16_FLOAT16, BT_FLOAT16, BT_FLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT32_FLOAT32, BT_FLOAT32, BT_FLOAT32) DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT64_FLOAT64, BT_FLOAT64, BT_FLOAT64) @@ -270,6 +279,8 @@ DEF_FUNCTION_TYPE_1 (BT_FN_COMPLEX_DOUBLE_COMPLEX_DOUBLE, BT_COMPLEX_DOUBLE, BT_COMPLEX_DOUBLE) DEF_FUNCTION_TYPE_1 (BT_FN_COMPLEX_LONGDOUBLE_COMPLEX_LONGDOUBLE, BT_COMPLEX_LONGDOUBLE, BT_COMPLEX_LONGDOUBLE) +DEF_FUNCTION_TYPE_1 (BT_FN_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16, + BT_COMPLEX_BFLOAT16, BT_COMPLEX_BFLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_COMPLEX_FLOAT16_COMPLEX_FLOAT16, BT_COMPLEX_FLOAT16, BT_COMPLEX_FLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_COMPLEX_FLOAT32_COMPLEX_FLOAT32, @@ -290,6 +301,8 @@ DEF_FUNCTION_TYPE_1 (BT_FN_DOUBLE_COMPLEX_DOUBLE, BT_DOUBLE, BT_COMPLEX_DOUBLE) DEF_FUNCTION_TYPE_1 (BT_FN_LONGDOUBLE_COMPLEX_LONGDOUBLE, BT_LONGDOUBLE, BT_COMPLEX_LONGDOUBLE) +DEF_FUNCTION_TYPE_1 (BT_FN_BFLOAT16_COMPLEX_BFLOAT16, + BT_BFLOAT16, BT_COMPLEX_BFLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT16_COMPLEX_FLOAT16, BT_FLOAT16, BT_COMPLEX_FLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT32_COMPLEX_FLOAT32, @@ -324,6 +337,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_INT_PTR, BT_INT, BT_PTR) DEF_FUNCTION_TYPE_1 (BT_FN_INT_FLOAT, BT_INT, BT_FLOAT) DEF_FUNCTION_TYPE_1 (BT_FN_INT_DOUBLE, BT_INT, BT_DOUBLE) DEF_FUNCTION_TYPE_1 (BT_FN_INT_LONGDOUBLE, BT_INT, BT_LONGDOUBLE) +DEF_FUNCTION_TYPE_1 (BT_FN_INT_BFLOAT16, BT_INT, BT_BFLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_INT_FLOAT16, BT_INT, BT_FLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_INT_FLOAT32, BT_INT, BT_FLOAT32) DEF_FUNCTION_TYPE_1 (BT_FN_INT_FLOAT64, BT_INT, BT_FLOAT64) @@ -337,6 +351,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_INT_DFLOAT128, BT_INT, BT_DFLOAT128) DEF_FUNCTION_TYPE_1 (BT_FN_LONG_FLOAT, BT_LONG, BT_FLOAT) DEF_FUNCTION_TYPE_1 (BT_FN_LONG_DOUBLE, BT_LONG, BT_DOUBLE) DEF_FUNCTION_TYPE_1 (BT_FN_LONG_LONGDOUBLE, BT_LONG, BT_LONGDOUBLE) +DEF_FUNCTION_TYPE_1 (BT_FN_LONG_BFLOAT16, BT_LONG, BT_BFLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_LONG_FLOAT16, BT_LONG, BT_FLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_LONG_FLOAT32, BT_LONG, BT_FLOAT32) DEF_FUNCTION_TYPE_1 (BT_FN_LONG_FLOAT64, BT_LONG, BT_FLOAT64) @@ -347,6 +362,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_LONG_FLOAT128X, BT_LONG, BT_FLOAT128X) DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_FLOAT, BT_LONGLONG, BT_FLOAT) DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_DOUBLE, BT_LONGLONG, BT_DOUBLE) DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_LONGDOUBLE, BT_LONGLONG, BT_LONGDOUBLE) +DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_BFLOAT16, BT_LONGLONG, BT_BFLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_FLOAT16, BT_LONGLONG, BT_FLOAT16) DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_FLOAT32, BT_LONGLONG, BT_FLOAT32) DEF_FUNCTION_TYPE_1 (BT_FN_LONGLONG_FLOAT64, BT_LONGLONG, BT_FLOAT64) @@ -525,6 +541,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_DOUBLE_DOUBLE_DOUBLEPTR, BT_DOUBLE, BT_DOUBLE, BT_DOUBLE_PTR) DEF_FUNCTION_TYPE_2 (BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLEPTR, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_LONGDOUBLE_PTR) +DEF_FUNCTION_TYPE_2 (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16PTR, + BT_BFLOAT16, BT_BFLOAT16, BT_BFLOAT16_PTR) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT16_FLOAT16_FLOAT16PTR, BT_FLOAT16, BT_FLOAT16, BT_FLOAT16_PTR) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT32_FLOAT32_FLOAT32PTR, @@ -549,6 +567,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_DOUBLE_DOUBLE_INT, BT_DOUBLE, BT_DOUBLE, BT_INT) DEF_FUNCTION_TYPE_2 (BT_FN_LONGDOUBLE_LONGDOUBLE_INT, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_INT) +DEF_FUNCTION_TYPE_2 (BT_FN_BFLOAT16_BFLOAT16_INT, + BT_BFLOAT16, BT_BFLOAT16, BT_INT) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT16_FLOAT16_INT, BT_FLOAT16, BT_FLOAT16, BT_INT) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT32_FLOAT32_INT, @@ -569,6 +589,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_DOUBLE_DOUBLE_INTPTR, BT_DOUBLE, BT_DOUBLE, BT_INT_PTR) DEF_FUNCTION_TYPE_2 (BT_FN_LONGDOUBLE_LONGDOUBLE_INTPTR, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_INT_PTR) +DEF_FUNCTION_TYPE_2 (BT_FN_BFLOAT16_BFLOAT16_INTPTR, + BT_BFLOAT16, BT_BFLOAT16, BT_INT_PTR) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT16_FLOAT16_INTPTR, BT_FLOAT16, BT_FLOAT16, BT_INT_PTR) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT32_FLOAT32_INTPTR, @@ -595,6 +617,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_DOUBLE_DOUBLE_LONG, BT_DOUBLE, BT_DOUBLE, BT_LONG) DEF_FUNCTION_TYPE_2 (BT_FN_LONGDOUBLE_LONGDOUBLE_LONG, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_LONG) +DEF_FUNCTION_TYPE_2 (BT_FN_BFLOAT16_BFLOAT16_LONG, + BT_BFLOAT16, BT_BFLOAT16, BT_LONG) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT16_FLOAT16_LONG, BT_FLOAT16, BT_FLOAT16, BT_LONG) DEF_FUNCTION_TYPE_2 (BT_FN_FLOAT32_FLOAT32_LONG, @@ -621,6 +645,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_COMPLEX_DOUBLE_COMPLEX_DOUBLE_COMPLEX_DOUBLE, BT_COMPLEX_DOUBLE, BT_COMPLEX_DOUBLE, BT_COMPLEX_DOUBLE) DEF_FUNCTION_TYPE_2 (BT_FN_COMPLEX_LONGDOUBLE_COMPLEX_LONGDOUBLE_COMPLEX_LONGDOUBLE, BT_COMPLEX_LONGDOUBLE, BT_COMPLEX_LONGDOUBLE, BT_COMPLEX_LONGDOUBLE) +DEF_FUNCTION_TYPE_2 (BT_FN_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16_COMPLEX_BFLOAT16, + BT_COMPLEX_BFLOAT16, BT_COMPLEX_BFLOAT16, BT_COMPLEX_BFLOAT16) DEF_FUNCTION_TYPE_2 (BT_FN_COMPLEX_FLOAT16_COMPLEX_FLOAT16_COMPLEX_FLOAT16, BT_COMPLEX_FLOAT16, BT_COMPLEX_FLOAT16, BT_COMPLEX_FLOAT16) DEF_FUNCTION_TYPE_2 (BT_FN_COMPLEX_FLOAT32_COMPLEX_FLOAT32_COMPLEX_FLOAT32, @@ -728,6 +754,8 @@ DEF_FUNCTION_TYPE_3 (BT_FN_DOUBLE_DOUBLE_DOUBLE_DOUBLE, BT_DOUBLE, BT_DOUBLE, BT_DOUBLE, BT_DOUBLE) DEF_FUNCTION_TYPE_3 (BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_LONGDOUBLE) +DEF_FUNCTION_TYPE_3 (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16_BFLOAT16, + BT_BFLOAT16, BT_BFLOAT16, BT_BFLOAT16, BT_BFLOAT16) DEF_FUNCTION_TYPE_3 (BT_FN_FLOAT16_FLOAT16_FLOAT16_FLOAT16, BT_FLOAT16, BT_FLOAT16, BT_FLOAT16, BT_FLOAT16) DEF_FUNCTION_TYPE_3 (BT_FN_FLOAT32_FLOAT32_FLOAT32_FLOAT32, @@ -748,6 +776,8 @@ DEF_FUNCTION_TYPE_3 (BT_FN_DOUBLE_DOUBLE_DOUBLE_INTPTR, BT_DOUBLE, BT_DOUBLE, BT_DOUBLE, BT_INT_PTR) DEF_FUNCTION_TYPE_3 (BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE_INTPTR, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_LONGDOUBLE, BT_INT_PTR) +DEF_FUNCTION_TYPE_3 (BT_FN_BFLOAT16_BFLOAT16_BFLOAT16_INTPTR, + BT_BFLOAT16, BT_BFLOAT16, BT_BFLOAT16, BT_INT_PTR) DEF_FUNCTION_TYPE_3 (BT_FN_FLOAT16_FLOAT16_FLOAT16_INTPTR, BT_FLOAT16, BT_FLOAT16, BT_FLOAT16, BT_INT_PTR) DEF_FUNCTION_TYPE_3 (BT_FN_FLOAT32_FLOAT32_FLOAT32_INTPTR, diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 0b902896ddd..d0fc8e755e8 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -1918,6 +1918,7 @@ expand_builtin_classify_type (tree exp) fcodef32 = BUILT_IN_##MATHFN##F32; fcodef64 = BUILT_IN_##MATHFN##F64 ; \ fcodef128 = BUILT_IN_##MATHFN##F128 ; fcodef32x = BUILT_IN_##MATHFN##F32X ; \ fcodef64x = BUILT_IN_##MATHFN##F64X ; fcodef128x = BUILT_IN_##MATHFN##F128X ;\ + fcodef16b = BUILT_IN_##MATHFN##F16B ; \ break; /* Similar to above, but appends _R after any F/L suffix. */ #define CASE_MATHFN_REENT(MATHFN) \ @@ -1937,6 +1938,7 @@ mathfn_built_in_2 (tree type, combined_fn fn) { tree mtype; built_in_function fcode, fcodef, fcodel; + built_in_function fcodef16b = END_BUILTINS; built_in_function fcodef16 = END_BUILTINS; built_in_function fcodef32 = END_BUILTINS; built_in_function fcodef64 = END_BUILTINS; @@ -2055,6 +2057,8 @@ mathfn_built_in_2 (tree type, combined_fn fn) return fcodef; else if (mtype == long_double_type_node) return fcodel; + else if (mtype == bfloat16_type_node) + return fcodef16b; else if (mtype == float16_type_node) return fcodef16; else if (mtype == float32_type_node) @@ -2137,6 +2141,8 @@ mathfn_built_in_type (combined_fn fn) #define CASE_MATHFN_FLOATN(MATHFN) \ CASE_MATHFN(MATHFN) \ + case CFN_BUILT_IN_##MATHFN##F16B: \ + return bfloat16_type_node; \ case CFN_BUILT_IN_##MATHFN##F16: \ return float16_type_node; \ case CFN_BUILT_IN_##MATHFN##F32: \ diff --git a/gcc/builtins.def b/gcc/builtins.def index f6f3e104f6a..ffd427d7d93 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -77,11 +77,12 @@ along with GCC; see the file COPYING3. If not see DEF_BUILTIN (ENUM, NAME, BUILT_IN_NORMAL, TYPE, BT_LAST, \ false, false, false, ATTRS, true, true) -/* A set of GCC builtins for _FloatN and _FloatNx types. TYPE_MACRO - is called with an argument such as FLOAT32 to produce the enum - value for the type. */ +/* A set of GCC builtins for __bf16, _FloatN and _FloatNx types. + TYPE_MACRO is called with an argument such as FLOAT32 to produce + the enum value for the type. */ #undef DEF_GCC_FLOATN_NX_BUILTINS #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) \ @@ -110,12 +111,12 @@ along with GCC; see the file COPYING3. If not see DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ true, true, true, ATTRS, false, true) -/* A set of GCC builtins for _FloatN and _FloatNx types. TYPE_MACRO is called - with an argument such as FLOAT32 to produce the enum value for the type. If - we are compiling for the C language with GNU extensions, we enable the name - without the __builtin_ prefix as well as the name with the __builtin_ - prefix. C++ does not enable these names by default because a class based - library should use the __builtin_ names. */ +/* A set of GCC builtins for __bf16, _FloatN and _FloatNx types. + TYPE_MACRO is called with an argument such as FLOAT32 to produce the enum + value for the type. If we are compiling for the C language with GNU + extensions, we enable the name without the __builtin_ prefix as well as the + name with the __builtin_ prefix. C++ does not enable these names by default + because a class based library should use the __builtin_ names. */ #undef DEF_FLOATN_BUILTIN #define DEF_FLOATN_BUILTIN(ENUM, NAME, TYPE, ATTRS) \ DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE, \ @@ -123,6 +124,7 @@ along with GCC; see the file COPYING3. If not see false, true) #undef DEF_EXT_LIB_FLOATN_NX_BUILTINS #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) \ @@ -576,7 +578,6 @@ DEF_GCC_BUILTIN (BUILT_IN_NANSF, "nansf", BT_FN_FLOAT_CONST_STRING, ATTR_ DEF_GCC_BUILTIN (BUILT_IN_NANSL, "nansl", BT_FN_LONGDOUBLE_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) DEF_GCC_FLOATN_NX_BUILTINS (BUILT_IN_NANS, "nans", NAN_TYPE, ATTR_CONST_NOTHROW_NONNULL) #undef NAN_TYPE -DEF_GCC_BUILTIN (BUILT_IN_NANSF16B, "nansf16b", BT_FN_BFLOAT16_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) DEF_GCC_BUILTIN (BUILT_IN_NANSD32, "nansd32", BT_FN_DFLOAT32_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) DEF_GCC_BUILTIN (BUILT_IN_NANSD64, "nansd64", BT_FN_DFLOAT64_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) DEF_GCC_BUILTIN (BUILT_IN_NANSD128, "nansd128", BT_FN_DFLOAT128_CONST_STRING, ATTR_CONST_NOTHROW_NONNULL) @@ -591,7 +592,6 @@ DEF_C99_BUILTIN (BUILT_IN_NEXTAFTERF, "nextafterf", BT_FN_FLOAT_FLOAT_FLO DEF_C99_BUILTIN (BUILT_IN_NEXTAFTERL, "nextafterl", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_ERRNO) #define NEXTAFTER_TYPE(F) BT_FN_##F##_##F##_##F DEF_EXT_LIB_FLOATN_NX_BUILTINS (BUILT_IN_NEXTAFTER, "nextafter", NEXTAFTER_TYPE, ATTR_MATHFN_ERRNO) -DEF_GCC_BUILTIN (BUILT_IN_NEXTAFTERF16B, "nextafterf16b", BT_FN_BFLOAT16_BFLOAT16_BFLOAT16, ATTR_MATHFN_ERRNO) DEF_C99_BUILTIN (BUILT_IN_NEXTTOWARD, "nexttoward", BT_FN_DOUBLE_DOUBLE_LONGDOUBLE, ATTR_MATHFN_ERRNO) DEF_C99_BUILTIN (BUILT_IN_NEXTTOWARDF, "nexttowardf", BT_FN_FLOAT_FLOAT_LONGDOUBLE, ATTR_MATHFN_ERRNO) DEF_C99_BUILTIN (BUILT_IN_NEXTTOWARDL, "nexttowardl", BT_FN_LONGDOUBLE_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_ERRNO) 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 diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc index 47bf8d64391..ed1ec0ab3ee 100644 --- a/gcc/fold-const-call.cc +++ b/gcc/fold-const-call.cc @@ -1354,7 +1354,6 @@ fold_const_call (combined_fn fn, tree type, tree arg) CASE_CFN_NANS: CASE_FLT_FN_FLOATN_NX (CFN_BUILT_IN_NANS): - case CFN_BUILT_IN_NANSF16B: case CFN_BUILT_IN_NANSD32: case CFN_BUILT_IN_NANSD64: case CFN_BUILT_IN_NANSD128: @@ -1462,7 +1461,6 @@ fold_const_call_sss (real_value *result, combined_fn fn, CASE_CFN_NEXTAFTER: CASE_CFN_NEXTAFTER_FN: - case CFN_BUILT_IN_NEXTAFTERF16B: CASE_CFN_NEXTTOWARD: return fold_const_nextafter (result, arg0, arg1, format); diff --git a/gcc/gencfn-macros.cc b/gcc/gencfn-macros.cc index 2581e758fe6..8c78ef084fe 100644 --- a/gcc/gencfn-macros.cc +++ b/gcc/gencfn-macros.cc @@ -156,10 +156,11 @@ const char *const internal_fn_int_names[] = { static const char *const flt_suffixes[] = { "F", "", "L", NULL }; static const char *const fltfn_suffixes[] = { "F16", "F32", "F64", "F128", - "F32X", "F64X", "F128X", NULL }; + "F32X", "F64X", "F128X","F16B", + NULL }; static const char *const fltall_suffixes[] = { "F", "", "L", "F16", "F32", "F64", "F128", "F32X", "F64X", - "F128X", NULL }; + "F128X", "F16B", NULL }; static const char *const int_suffixes[] = { "", "L", "LL", "IMAX", NULL }; static const char *const *const suffix_lists[] = { diff --git a/gcc/match.pd b/gcc/match.pd index c9c8478d286..ca01c6714d8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8386,7 +8386,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) #if GIMPLE (match float16_value_p @0 - (if (TYPE_MAIN_VARIANT (TREE_TYPE (@0)) == float16_type_node))) + (if ((TYPE_MAIN_VARIANT (TREE_TYPE (@0)) == float16_type_node) || + (TYPE_MAIN_VARIANT (TREE_TYPE (@0)) == bfloat16_type_node)))) (for froms (BUILT_IN_TRUNCL BUILT_IN_TRUNC BUILT_IN_TRUNCF BUILT_IN_FLOORL BUILT_IN_FLOOR BUILT_IN_FLOORF BUILT_IN_CEILL BUILT_IN_CEIL BUILT_IN_CEILF @@ -8403,8 +8404,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) IFN_NEARBYINT IFN_NEARBYINT IFN_NEARBYINT IFN_RINT IFN_RINT IFN_RINT IFN_SQRT IFN_SQRT IFN_SQRT) - /* (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc., - if x is a _Float16. */ + /* 1 (_Float16) round ((doube) x) -> __built_in_roundf16 (x), etc., + if x is a _Float16. + 2 (__bf16) round ((doube) x) -> __built_in_roundf16b (x), etc., + if x is a __bf16. */ (simplify (convert (froms (convert float16_value_p@0))) (if (optimize diff --git a/gcc/tree.h b/gcc/tree.h index 5dcbb2fb5dd..67fc2a2e614 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -310,7 +310,7 @@ code_helper::is_builtin_fn () const #define CASE_FLT_FN(FN) case FN: case FN##F: case FN##L #define CASE_FLT_FN_FLOATN_NX(FN) \ case FN##F16: case FN##F32: case FN##F64: case FN##F128: \ - case FN##F32X: case FN##F64X: case FN##F128X + case FN##F32X: case FN##F64X: case FN##F128X: case FN##F16B #define CASE_FLT_FN_REENT(FN) case FN##_R: case FN##F_R: case FN##L_R #define CASE_INT_FN(FN) case FN: case FN##L: case FN##LL: case FN##IMAX diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 0e46e9ef768..b71fd5e2250 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -450,9 +450,9 @@ lib2funcs = _muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3 _cmpdi2 _ucmpdi2 \ _negvsi2 _negvdi2 _ctors _ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 \ _ctzsi2 _ctzdi2 _popcount_tab _popcountsi2 _popcountdi2 \ _paritysi2 _paritydi2 _powisf2 _powidf2 _powixf2 _powitf2 \ - _mulhc3 _mulsc3 _muldc3 _mulxc3 _multc3 _divhc3 _divsc3 \ - _divdc3 _divxc3 _divtc3 _bswapsi2 _bswapdi2 _clrsbsi2 \ - _clrsbdi2 _mulbitint3 + _mulhc3 _mulbc3 _mulsc3 _muldc3 _mulxc3 _multc3 _divhc3 \ + _divbc3 _divsc3 _divdc3 _divxc3 _divtc3 _bswapsi2 _bswapdi2 \ + _clrsbsi2 _clrsbdi2 _mulbitint3 # The floating-point conversion routines that involve a single-word integer. # XX stands for the integer mode. diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c index 3fcb85c5b92..512ca92bfb9 100644 --- a/libgcc/libgcc2.c +++ b/libgcc/libgcc2.c @@ -2591,6 +2591,7 @@ NAME (TYPE x, int m) #endif #if((defined(L_mulhc3) || defined(L_divhc3)) && LIBGCC2_HAS_HF_MODE) \ + || ((defined(L_mulbc3) || defined(L_divbc3)) && LIBGCC2_HAS_BF_MODE) \ || ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \ || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \ || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \ @@ -2607,6 +2608,13 @@ NAME (TYPE x, int m) # define MODE hc # define CEXT __LIBGCC_HF_FUNC_EXT__ # define NOTRUNC (!__LIBGCC_HF_EXCESS_PRECISION__) +#elif defined(L_mulbc3) || defined(L_divbc3) +# define MTYPE BFtype +# define CTYPE BCtype +# define AMTYPE SFtype +# define MODE bc +# define CEXT __LIBGCC_BF_FUNC_EXT__ +# define NOTRUNC (!__LIBGCC_BF_EXCESS_PRECISION__) #elif defined(L_mulsc3) || defined(L_divsc3) # define MTYPE SFtype # define CTYPE SCtype @@ -2690,8 +2698,8 @@ extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1]; # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x)) #endif -#if defined(L_mulhc3) || defined(L_mulsc3) || defined(L_muldc3) \ - || defined(L_mulxc3) || defined(L_multc3) +#if defined(L_mulhc3) || defined(L_mulbc3) || defined(L_mulsc3) \ + || defined(L_muldc3) || defined(L_mulxc3) || defined(L_multc3) CTYPE CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) @@ -2760,16 +2768,16 @@ CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) } #endif /* complex multiply */ -#if defined(L_divhc3) || defined(L_divsc3) || defined(L_divdc3) \ - || defined(L_divxc3) || defined(L_divtc3) +#if defined(L_divhc3) || defined(L_divbc3) || defined(L_divsc3) \ + || defined(L_divdc3) || defined(L_divxc3) || defined(L_divtc3) CTYPE CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d) { -#if defined(L_divhc3) \ +#if (defined(L_divhc3) || defined(L_divbc3) ) \ || (defined(L_divsc3) && defined(__LIBGCC_HAVE_HWDBL__) ) - /* Half precision is handled with float precision. + /* _Float16 and __bf16 are handled with float precision. float is handled with double precision when double precision hardware is available. Due to the additional precision, the simple complex divide diff --git a/libgcc/libgcc2.h b/libgcc/libgcc2.h index b358b3a2b50..ee99badde86 100644 --- a/libgcc/libgcc2.h +++ b/libgcc/libgcc2.h @@ -43,6 +43,12 @@ extern void __eprintf (const char *, const char *, unsigned int, const char *) #define LIBGCC2_HAS_HF_MODE 0 #endif +#ifdef __LIBGCC_HAS_BF_MODE__ +#define LIBGCC2_HAS_BF_MODE 1 +#else +#define LIBGCC2_HAS_BF_MODE 0 +#endif + #ifdef __LIBGCC_HAS_SF_MODE__ #define LIBGCC2_HAS_SF_MODE 1 #else @@ -146,6 +152,10 @@ typedef unsigned int UTItype __attribute__ ((mode (TI))); typedef float HFtype __attribute__ ((mode (HF))); typedef _Complex float HCtype __attribute__ ((mode (HC))); #endif +#if LIBGCC2_HAS_BF_MODE +typedef float BFtype __attribute__ ((mode (BF))); +typedef _Complex float BCtype __attribute__ ((mode (BC))); +#endif #if LIBGCC2_HAS_SF_MODE typedef float SFtype __attribute__ ((mode (SF))); typedef _Complex float SCtype __attribute__ ((mode (SC))); @@ -465,6 +475,10 @@ extern SItype __negvsi2 (SItype); extern HCtype __divhc3 (HFtype, HFtype, HFtype, HFtype); extern HCtype __mulhc3 (HFtype, HFtype, HFtype, HFtype); #endif +#if LIBGCC2_HAS_BF_MODE +extern BCtype __divbc3 (BFtype, BFtype, BFtype, BFtype); +extern BCtype __mulbc3 (BFtype, BFtype, BFtype, BFtype); +#endif #if LIBGCC2_HAS_SF_MODE extern DWtype __fixsfdi (SFtype); extern SFtype __floatdisf (DWtype);