From owner-freebsd-numerics@freebsd.org Tue Jan 1 18:32:36 2019 Return-Path: Delivered-To: freebsd-numerics@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2F1351424B33 for ; Tue, 1 Jan 2019 18:32:36 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "troutmask", Issuer "troutmask" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id DF24F80F84; Tue, 1 Jan 2019 18:32:33 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id x01IWQVY011818 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 1 Jan 2019 10:32:26 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id x01IWQZ6011817; Tue, 1 Jan 2019 10:32:26 -0800 (PST) (envelope-from sgk) Date: Tue, 1 Jan 2019 10:32:26 -0800 From: Steve Kargl To: Pedro Giffuni Cc: freebsd-numerics@freebsd.org Subject: Re: Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM) Message-ID: <20190101183226.GA11443@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu References: <797a7755-db93-1b9c-f3b9-8850d948e098@FreeBSD.org> <20181231151904.GB823@troutmask.apl.washington.edu> <20181231152230.GC823@troutmask.apl.washington.edu> <06c8b6a2-ed26-f255-3947-c79b593a9dea@FreeBSD.org> <20190101045425.GA5767@troutmask.apl.washington.edu> <20190101055225.GA5982@troutmask.apl.washington.edu> <9cdce84b-2cff-d752-67a9-4c9ef391cc2c@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9cdce84b-2cff-d752-67a9-4c9ef391cc2c@FreeBSD.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: DF24F80F84 X-Spamd-Bar: +++ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [3.01 / 15.00]; ARC_NA(0.00)[]; HAS_REPLYTO(0.00)[sgk@troutmask.apl.washington.edu]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(0.93)[0.933,0]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[washington.edu]; AUTH_NA(1.00)[]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; IP_SCORE(0.16)[ip: (0.44), ipnet: 128.95.0.0/16(0.25), asn: 73(0.18), country: US(-0.08)]; RCVD_IN_DNSWL_MED(-0.20)[21.76.95.128.list.dnswl.org : 127.0.11.2]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(0.64)[0.635,0]; MX_GOOD(-0.01)[troutmask.apl.washington.edu]; NEURAL_SPAM_MEDIUM(0.59)[0.592,0]; R_SPF_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:73, ipnet:128.95.0.0/16, country:US]; MID_RHS_MATCH_FROM(0.00)[] X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Jan 2019 18:32:36 -0000 On Tue, Jan 01, 2019 at 10:01:45AM -0500, Pedro Giffuni wrote: > > >> This would be easy > >> to see if all declarations are grouped together. In additional, > >> don't you need to include stdint.h to get uint32_t? > > > > Well, my patch did compile, but I will match the existing style if > > the change is accepted/desired. Yeah, I found that out myself. I cannot find where stdint.h is being pulled into the build. It seems that one of the included headers may have some namespace pollution. > >> % grep uint32_t /usr/src/lib/msun/src/e_pow.c > >> % grep u_int32_t /usr/src/lib/msun/src/e_pow.c > >> u_int32_t lx,ly; > >> n = ((u_int32_t)hx>>31)-1; > >> > >> Code churn to placate lint for an event that cannot occur > >> seems dubious to me. > >> > > UBsan should be able to detect it. I think Undefined Behavior is > > considered a portability bug. > > > > There is no urgency but it is still a bug. > > > In the new patch: the first j comparison has to be made against an > unsigned value anyways and the second comparison will never be against > the magical 31 so there is no need to cast that one. > I'll defer to Bruce on which patch he prefers. If bde doesn't weigh in, then choose which ever you want. Me, I would do Index: src/e_pow.c =================================================================== --- src/e_pow.c (revision 2135) +++ src/e_pow.c (working copy) @@ -104,7 +104,7 @@ __ieee754_pow(double x, double y) double y1,t1,t2,r,s,t,u,v,w; int32_t i,j,k,yisint,n; int32_t hx,hy,ix,iy; - u_int32_t lx,ly; + u_int32_t jj,lx,ly; EXTRACT_WORDS(hx,lx,x); EXTRACT_WORDS(hy,ly,y); @@ -132,8 +132,8 @@ __ieee754_pow(double x, double y) else if(iy>=0x3ff00000) { k = (iy>>20)-0x3ff; /* exponent */ if(k>20) { - j = ly>>(52-k); - if((j<<(52-k))==ly) yisint = 2-(j&1); + jj = ly>>(52-k); + if((jj<<(52-k))==ly) yisint = 2-(j&1); } else if(ly==0) { j = iy>>(20-k); if((j<<(20-k))==iy) yisint = 2-(j&1); -- Steve