From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 71DAB3858C52 for ; Fri, 28 Apr 2023 14:04:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71DAB3858C52 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1a67bcde3a7so100573965ad.3 for ; Fri, 28 Apr 2023 07:04:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1682690684; x=1685282684; h=to:from:cc:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:from:to:cc:subject:date :message-id:reply-to; bh=bVdkek8hAYIjikW4VdY/rOdIXFjs1xc+zcgVoZbIsKc=; b=Y26paR6kI61YrX+xa8ODV85oVzjPw34j8qIBjBaZi3bqfv0dvgSXYSjU2qpyvmO5uk ulCJDfy4/8Z/WB1LqWTR0sKA7tvqgUp0c0wUTWwRKHjYxE0jNTdp6u3sHvndxuHa89dH oaFXhAMSFjT+htKIHdzm3mU5BA8EfiS8DCxoYhxaC6VKMgtmaJahO0M2AL3+7QVJmguo DfeR4kflTCjPyj1stNSsgMnEQAQp9bEuO9+0pujTfEw8TayLQJ5Zsk11NsMP7ixu1Ppx sLlTbEp2hz3kRe3mI9RWqUQH8WEeiD7gTrmhScuknChONREcicBnRSsLfMsjlfVJbVF2 a5YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682690684; x=1685282684; h=to:from:cc:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bVdkek8hAYIjikW4VdY/rOdIXFjs1xc+zcgVoZbIsKc=; b=UV8RTdro5adELUjL67L2yMiAlO+vUbWb3vUgogizeJeLJ46NOY7JayvWhKA2jkr3qi nAYNtV408L94hmwrh9o9n9tcvrKWlQi453llXwtkDuec2uudqbQaRr+WT3tWMFtQV6rA lDQY9RfmdqCT2RVtFdUCOHluVaXc4Ra4SDw35tzn+avR/1wuQpIj6JCk2J2cRij/I2zG TyeE4IZ9bvlvF6ITmHYFG9kr2FEB1uxMPc4kA9V0NZyduCouS05ePW6bWJq+19ImQ34H wA43kfRw6oUDtjwQwcq/LGNot25YKIfC0SWbVyp3LRfHGghKBvhdkb9S3kFXMde5Ins/ xZoA== X-Gm-Message-State: AC+VfDwuyrlaTj4OQUsZrgiNb45ihGJlzh/oWFbIpVWCpprC0UbR6vYH s7WdXvN9dsjz3EMJIrz0bLHFcFRjL9419XJq+GI= X-Google-Smtp-Source: ACHHUZ4WxOeok/nG2p/dgLCtV93zKCp2Mm6P50+Lic+OLeLP2+r12OuYII9k6bL+C9GX+2k1kZB9EQ== X-Received: by 2002:a17:902:7208:b0:1a5:1b94:e63d with SMTP id ba8-20020a170902720800b001a51b94e63dmr4929510plb.65.1682690684361; Fri, 28 Apr 2023 07:04:44 -0700 (PDT) Received: from localhost ([135.180.227.0]) by smtp.gmail.com with ESMTPSA id q16-20020a170902bd9000b001a6dc4f4a8csm9277015pls.73.2023.04.28.07.04.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 07:04:43 -0700 (PDT) Subject: [COMMITTED 2/2] Remap __GLIBC_FLT_EVAL_METHOD to 0 if __FLT_EVAL_METHOD__ is -1 Date: Fri, 28 Apr 2023 07:04:27 -0700 Message-Id: <20230428140427.13133-2-palmer@rivosinc.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230428140427.13133-1-palmer@rivosinc.com> References: <20230428140427.13133-1-palmer@rivosinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Kito Cheng , Palmer Dabbelt , lco=20Dijkstra=C2=A0?= From: Palmer Dabbelt To: libc-alpha@sourceware.org X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,KAM_NUMSUBJECT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Kito Cheng __GLIBC_FLT_EVAL_METHOD will effect the definition of float_t and double_t, currently we'll set __GLIBC_FLT_EVAL_METHOD to 2 when __FLT_EVAL_METHOD__ is -1, that means we'll define float_t and double_t to long double. However some target isn't natively (HW) support long double like AArch64 and RISC-V, they defined long double as 128-bits IEEE 754 floating point type. That means setting __GLIBC_FLT_EVAL_METHOD to 2 will cause very inefficient code gen for those target who didn't provide native support for long double, and that's violate the spirit float_t and double_t - most efficient types at least as wide as float and double. So this patch propose to remap __GLIBC_FLT_EVAL_METHOD to 0 rather than 2 when __FLT_EVAL_METHOD__ is -1, which means we'll use float/double rather than long double for float_t and double_t. Note: __FLT_EVAL_METHOD__ == -1 means the precision is indeterminable, which means compiler might using indeterminable precision during optimization/code gen, clang will set this value to -1 when fast math is enabled. Note: Default definition float_t and double_t in current glibc: | __GLIBC_FLT_EVAL_METHOD | float_t | double_t | 0 or 16 | float | double | 1 | double | doulbe | 2 | long double | long double More complete list see math/math.h Note: RISC-V has defined ISA extension to support 128-bits IEEE 754 floating point operations, but only rare RISC-V core will implement that. Related link: [1] LLVM issue (__FLT_EVAL_METHOD__ is set to -1 with Ofast. #60781): https://github.com/llvm/llvm-project/issues/60781 [2] Last version of this patch: https://sourceware.org/pipermail/libc-alpha/2023-February/145622.html Acked-by: Palmer Dabbelt # RISC-V Reviewed-by: Wilco Dijkstra  Link: https://inbox.sourceware.org/libc-alpha/20230314151948.12892-1-kito.cheng@sifive.com Signed-off-by: Palmer Dabbelt --- bits/flt-eval-method.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bits/flt-eval-method.h b/bits/flt-eval-method.h index 75f57b9a0e..f9262d7d0b 100644 --- a/bits/flt-eval-method.h +++ b/bits/flt-eval-method.h @@ -26,14 +26,12 @@ -1. */ /* In the default version of this header, follow __FLT_EVAL_METHOD__. - -1 is mapped to 2 (considering evaluation as long double to be a - conservatively safe assumption), and if __FLT_EVAL_METHOD__ is not - defined then assume there is no excess precision and use the value - 0. */ + If __FLT_EVAL_METHOD__ is not defined or set to -1, assume there is no + excess precision and use the value 0 (this is correct for most targets). */ #ifdef __FLT_EVAL_METHOD__ # if __FLT_EVAL_METHOD__ == -1 -# define __GLIBC_FLT_EVAL_METHOD 2 +# define __GLIBC_FLT_EVAL_METHOD 0 # else # define __GLIBC_FLT_EVAL_METHOD __FLT_EVAL_METHOD__ # endif -- 2.40.0