From owner-freebsd-numerics@freebsd.org Tue Jan 1 04:54:30 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 521BB1429A2D for ; Tue, 1 Jan 2019 04:54:30 +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 9FD7F6DFF8; Tue, 1 Jan 2019 04:54:28 +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 x014sQ6S005830 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 31 Dec 2018 20:54: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 x014sQj9005829; Mon, 31 Dec 2018 20:54:26 -0800 (PST) (envelope-from sgk) Date: Mon, 31 Dec 2018 20:54: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: <20190101045425.GA5767@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <06c8b6a2-ed26-f255-3947-c79b593a9dea@FreeBSD.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 9FD7F6DFF8 X-Spamd-Bar: ++ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [2.88 / 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_MEDIUM(0.81)[0.806,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.17)[ip: (0.47), ipnet: 128.95.0.0/16(0.26), asn: 73(0.18), country: US(-0.08)]; NEURAL_SPAM_SHORT(0.45)[0.445,0]; RCVD_IN_DNSWL_MED(-0.20)[21.76.95.128.list.dnswl.org : 127.0.11.2]; MX_GOOD(-0.01)[cached: troutmask.apl.washington.edu]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_SPAM_LONG(0.77)[0.774,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 04:54:30 -0000 On Mon, Dec 31, 2018 at 10:32:06PM -0500, Pedro Giffuni wrote: > Hmm ... > > Looking at the changes in musl's libc I found this issue which seems > real (although somewhat theoretical): > > https://git.musl-libc.org/cgit/musl/commit/src/math?id=688d3da0f1730daddbc954bbc2d27cc96ceee04c > > Is the attached patch acceptable? > > Also, their code is bit different here: > > https://git.musl-libc.org/cgit/musl/commit/src/math?id=282b1cd26649d69de038111f5876853df6ddc345 > > but we may also have to check fmaf(-0x1.26524ep-54, -0x1.cb7868p+11, > 0x1.d10f5ep-29). > > Cheers, > > Pedro. > > Index: lib/msun/src/e_pow.c > =================================================================== > --- lib/msun/src/e_pow.c (revision 342665) > +++ lib/msun/src/e_pow.c (working copy) > @@ -130,6 +130,7 @@ > if(hx<0) { > if(iy>=0x43400000) yisint = 2; /* even integer y */ > else if(iy>=0x3ff00000) { > + uint32_t j; /* Avoid UB in bit operations below. */ > k = (iy>>20)-0x3ff; /* exponent */ > if(k>20) { > j = ly>>(52-k); I'll defer to Bruce on this. My only comments are 1) declarations belong at the top of the file where all declarations occur 2) j is already declared as int32_t 3) uint32_t should be written as u_int32_t. Are you sure that UB occurs? Or, is this an attempt to placate a static analysis tool that only see shifting of a signed type? Do you need to make a similar change to e_powf.c? -- Steve