From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4C0D33858D37 for ; Thu, 20 Apr 2023 14:02:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C0D33858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681999330; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=GIS7xZh7WYVvLF3st5YV3hT5J75ytIaqCVRKVkEv/iE=; b=F2k3gWllQO1MkzFO0o1EQVKihboHChxYfzYrd2SbrjVHTR9I/SaYnD/NOQWcJLYQ9kch1y XHhaAFGvF6wRW1/evk2XsudHabv2e4QXuekJ3Mq+FybWIEKCBqfy4mnIi2jZqF5uU0l3X0 nFM0LxTc0jLT9WbK8at4iCn0gQZDWPw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-384-ZpCCS_mzNt2fuyakhpFkOA-1; Thu, 20 Apr 2023 10:02:09 -0400 X-MC-Unique: ZpCCS_mzNt2fuyakhpFkOA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3416185A7AB; Thu, 20 Apr 2023 14:02:07 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54F601121315; Thu, 20 Apr 2023 14:02:07 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 33KE24am1981935 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 20 Apr 2023 16:02:04 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33KE23e11981934; Thu, 20 Apr 2023 16:02:03 +0200 Date: Thu, 20 Apr 2023 16:02:02 +0200 From: Jakub Jelinek To: Siddhesh Poyarekar Cc: Aldy Hernandez , "Joseph S. Myers" , GCC patches , Andrew MacLeod Subject: Re: [PATCH] Implement range-op entry for sin/cos. Message-ID: Reply-To: Jakub Jelinek References: <20230418131250.310916-1-aldyh@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="0RjtiHcTPTmPfeUJ" Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: --0RjtiHcTPTmPfeUJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Apr 20, 2023 at 09:17:10AM -0400, Siddhesh Poyarekar wrote: > On 2023-04-20 08:59, Jakub Jelinek via Gcc-patches wrote: > > > + r.set (type, dconstm1, dconst1); > > > > See above, are we sure we can use [-1., 1.] range safely, or should that be > > [-1.-Nulps, 1.+Nulps] for some kind of expected worse error margin of the > > implementation? And ditto for -frounding-math, shall we increase that > > interval in that case, or is [-1., 1.] going to be ok? > > Do any math implementations generate results outside of [-1., 1.]? If yes, Clearly they do. > then it's a bug in those implementations IMO, not in the range assumption. > It feels wrong to cater for what ought to be trivially fixable in libraries > if they ever happen to generate such results. So, I wrote following test. On x86_64-linux with glibc 2.35, I see for i in FLOAT DOUBLE LDOUBLE FLOAT128; do for j in TONEAREST UPWARD DOWNWARD TOWARDZERO; do gcc -D$i -DROUND=FE_$j -g -O1 -o /tmp/sincos{,.c} -lm; /tmp/sincos || echo $i $j; done; done Aborted (core dumped) FLOAT UPWARD Aborted (core dumped) FLOAT DOWNWARD On sparc-sun-solaris2.11 I see for i in FLOAT DOUBLE LDOUBLE; do for j in TONEAREST UPWARD DOWNWARD TOWARDZERO; do gcc -D$i -DROUND=FE_$j -g -O1 -o sincos{,.c} -lm; ./sincos || echo $i $j; done; done Abort (core dumped) DOUBLE UPWARD Abort (core dumped) DOUBLE DOWNWARD Haven't tried anything else. So that shows (but doesn't prove) that maybe [-1., 1.] interval is fine for -fno-rounding-math on those, but not for -frounding-math. Jakub --0RjtiHcTPTmPfeUJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="sincos.c" #define _GNU_SOURCE #include #include #ifdef FLOAT #define TYPE float #define SIN sinf #define COS cosf #ifdef M_PI_2f #define PI2 M_PI_2f #else #define PI2 1.570796326794896619231321691639751442f #endif #define NEXTAFTER nextafterf #elif defined DOUBLE #define TYPE double #define SIN sin #define COS cos #ifdef M_PI_2 #define PI2 M_PI_2 #else #define PI2 1.570796326794896619231321691639751442f #endif #define NEXTAFTER nextafter #elif defined LDOUBLE #define TYPE long double #define SIN sinl #define COS cosl #ifdef M_PI_2l #define PI2 M_PI_2l #else #define PI2 1.570796326794896619231321691639751442f #endif #define NEXTAFTER nextafterl #elif defined FLOAT128 #define TYPE _Float128 #define SIN sinf128 #define COS cosf128 #ifdef #define PI2 M_PI_2f128 #else #define PI2 1.570796326794896619231321691639751442f #endif #define NEXTAFTER nextafterf128 #endif int main () { #ifdef ROUND fesetround (ROUND); #endif for (int i = -1024; i <= 1024; i++) for (int j = -1; j <= 1; j += 2) { TYPE val = ((TYPE) i) * PI2; TYPE inf = j * __builtin_inf (); for (int k = 0; k < 1000; k++) { TYPE res = SIN (val); if (res < (TYPE) -1.0 || res > (TYPE) 1.0) __builtin_abort (); res = COS (val); if (res < (TYPE) -1.0 || res > (TYPE) 1.0) __builtin_abort (); val = NEXTAFTER (val, inf); } } } --0RjtiHcTPTmPfeUJ--