From owner-freebsd-numerics@freebsd.org Mon Dec 31 15:07:07 2018 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 D28DB1437618 for ; Mon, 31 Dec 2018 15:07:07 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from sonic302-3.consmr.mail.bf2.yahoo.com (sonic302-3.consmr.mail.bf2.yahoo.com [74.6.135.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 49EF86FC90 for ; Mon, 31 Dec 2018 15:07:04 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1546268823; bh=g+2dKxOEZ/jTQwAAEZB58jbKgXODW0Ru07z/EsrLUoE=; h=To:From:Subject:Date:From:Subject; b=ixg3sWKTLPnq7I3NmmiHXTKYe53xCkyKrCD0POAoRJhcPoC54gU0m1P8xKMZL9lmI/JQAL0l1+7ACiaSmF+g9ss3pJj7nhrnzoK00SyB7IRfxQoRc/GiSuqTRTRNiyh7yOHp71bAnxRN+/wsvw/nBLcM4tzQQEfdAQFMbPQ5Nf5UQYWQCNNUqiRCFooFzNvciHCU0n/migCXlc12DNh+wdHWEUtlAVfFV6beuLNZ0UdCLBUo+yNQ2Kru5utAtkxuWxdvxo8PPPJn6PIDgy9Obnf3s5bm6jiOWaqCaAGomznvgQ3y8msT9V2sXcg8GaUIzyPzMF7oO1rJAnuqiybT2g== X-YMail-OSG: _TMKZXkVM1ntFzii5rfMTlDbgeYaCAhXQszG9rn1v_LVMfEfGQsclS_.AMp6j.2 7QESUBLUGs4UvkBqeNw2CCVgu2TN7h9izEYr9XI1aGEIwBafl5zch_3CEE8KPzxzqovjK4eeazvZ LXTBTJLT_yOq4a0QXrUGV2tkgbfY5aGMzXF9GV2rLPngz7e7EV7QDa8VOASAl58mXvDvnCCmfnXg 2hEeJ1DBVSDZJtKZeRgx7T8Q6myB025EwoV7h753248URq.HxqFrucKTqsDbMsOBgk1v9k7ECzbp 0r5pofj7tsAr1TxtWhKCtpSeFBClmT7NNjbGS.We0.rliEvac3.nRtUJXLhcj2NZwhtDsK_BfOiK SpLeQpVsftL8QF4guIen2CVX_q6qpOgeS9YSLT_1wlT8jbBp0XrZBtMVVOnuAXAjF7gslohbj.nB JRctyRNCae17XiPT69niD5Iywvb3XGmTHUGkU8K_.sykRCscz25U3fAkG9kWraRMegVlnIpDJWmL L8lL53NnOxsal2nwzdNtNeJvbuB.1C702g43GkCjxhdIP9PX7RNfRCaxKVqrZ34BAWonXou87ZT3 Fg06C_QUr71rJ57xnDzE8RbeW8FqsJMHFPMTeVOkunBz.MvGwpKsgqyAIpvjEMwbqMNlHJ1cpozf v6BZZRqyXMc1cKwZJhAjjLZmbv4UKBivLdTVSN.XLXo7eNQXKQUDMMupuBBARLdgbt.DPKd10T5U sHNHXp6btw4ehJGrgsbHWJVWpfKuubdOGTRVU.3NI3s_rBE8rmkXRZXD5qPleG3L1TpV2c8ks.5H vshDAuoDe9UatNPnq_OhINGJ754noZPo5I7T5qBQ1cFXnQ9oQqu8zfiIymNoMh5oxE6x2CriDasF 3JD7p43SQ2iyGveSjEh0NqploROl479_Y1SOu8IupnXIGJoJwVEE.SlbXvUBtPzZ.7.c5B5tbX80 FbnqHhJ150OzKLWBhKpWSQzd1UJzjhm5WW9SHLWArHxKPnH9I1DO21_MNLhjjTW2PZcJtMh4JbZf a02U07slVj0gplwO3uzIAUlmunY0- Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.bf2.yahoo.com with HTTP; Mon, 31 Dec 2018 15:07:03 +0000 Received: from 181.52.72.201 (EHLO [192.168.0.5]) ([181.52.72.201]) by smtp428.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 658c98c66ce13e2472b4f404fe5e64e2 for ; Mon, 31 Dec 2018 15:06:58 +0000 (UTC) To: freebsd-numerics@FreeBSD.org From: Pedro Giffuni Subject: New math library from ARM Message-ID: <797a7755-db93-1b9c-f3b9-8850d948e098@FreeBSD.org> Date: Mon, 31 Dec 2018 10:06:57 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Queue-Id: 49EF86FC90 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.994,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:26101, ipnet:74.6.128.0/21, country:US] 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: Mon, 31 Dec 2018 15:07:08 -0000 Hi; Just noted a recent initiative from musl-libc: https://www.openwall.com/lists/musl/2018/12/08/1 It appears they plan to replace their (FreeBSD) math code with a new ARM implementation: https://github.com/ARM-software/optimized-routines Cheers, Pedro. From owner-freebsd-numerics@freebsd.org Mon Dec 31 15:19:16 2018 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 2642E1437A66 for ; Mon, 31 Dec 2018 15:19:16 +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 1E67170481; Mon, 31 Dec 2018 15:19:14 +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 wBVFJ4Eh001255 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 31 Dec 2018 07:19:04 -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 wBVFJ44N001254; Mon, 31 Dec 2018 07:19:04 -0800 (PST) (envelope-from sgk) Date: Mon, 31 Dec 2018 07:19:04 -0800 From: Steve Kargl To: Pedro Giffuni Cc: freebsd-numerics@freebsd.org Subject: Re: New math library from ARM Message-ID: <20181231151904.GB823@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu References: <797a7755-db93-1b9c-f3b9-8850d948e098@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <797a7755-db93-1b9c-f3b9-8850d948e098@FreeBSD.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: 1E67170481 X-Spamd-Bar: +++ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [3.12 / 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.80)[0.804,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.18)[ip: (0.52), ipnet: 128.95.0.0/16(0.28), 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.75)[0.754,0]; MX_GOOD(-0.01)[troutmask.apl.washington.edu]; NEURAL_SPAM_MEDIUM(0.69)[0.692,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: Mon, 31 Dec 2018 15:19:16 -0000 On Mon, Dec 31, 2018 at 10:06:57AM -0500, Pedro Giffuni wrote: > Hi; > > Just noted a recent initiative from musl-libc: > > https://www.openwall.com/lists/musl/2018/12/08/1 > > It appears they plan to replace their (FreeBSD) math code with a new ARM > implementation: > > https://github.com/ARM-software/optimized-routines > The Copyright on this code is unclear. For example, in single/e_rem_pio2.c lines 1-6: /* * e_rem_pio2.c * * Copyright (c) 1999-2018, Arm Limited. * SPDX-License-Identifier: MIT */ Then lines 16-18: /* * Simple cases: all nicked from the fdlibm version for speed. */ The original fdlibm licenses applies ot the nicked lines. -- Steve From owner-freebsd-numerics@freebsd.org Mon Dec 31 15:22:32 2018 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 A005E1437F84 for ; Mon, 31 Dec 2018 15:22:32 +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 EFC2A709A2; Mon, 31 Dec 2018 15:22:31 +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 wBVFMURl001315 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 31 Dec 2018 07:22:30 -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 wBVFMUsa001314; Mon, 31 Dec 2018 07:22:30 -0800 (PST) (envelope-from sgk) Date: Mon, 31 Dec 2018 07:22:30 -0800 From: Steve Kargl To: Pedro Giffuni Cc: freebsd-numerics@freebsd.org Subject: Re: New math library from ARM Message-ID: <20181231152230.GC823@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181231151904.GB823@troutmask.apl.washington.edu> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: EFC2A709A2 X-Spamd-Bar: +++ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [3.18 / 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.81)[0.809,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.18)[ip: (0.50), ipnet: 128.95.0.0/16(0.27), 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.78)[0.777,0]; MX_GOOD(-0.01)[cached: troutmask.apl.washington.edu]; NEURAL_SPAM_MEDIUM(0.73)[0.727,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: Mon, 31 Dec 2018 15:22:32 -0000 On Mon, Dec 31, 2018 at 07:19:04AM -0800, Steve Kargl wrote: > On Mon, Dec 31, 2018 at 10:06:57AM -0500, Pedro Giffuni wrote: > > Hi; > > > > Just noted a recent initiative from musl-libc: > > > > https://www.openwall.com/lists/musl/2018/12/08/1 > > > > It appears they plan to replace their (FreeBSD) math code with a new ARM > > implementation: > > > > https://github.com/ARM-software/optimized-routines > > > > The Copyright on this code is unclear. For example, in > single/e_rem_pio2.c lines 1-6: > > /* > * e_rem_pio2.c > * > * Copyright (c) 1999-2018, Arm Limited. > * SPDX-License-Identifier: MIT > */ > > Then lines 16-18: > > /* > * Simple cases: all nicked from the fdlibm version for speed. > */ > > The original fdlibm licenses applies ot the nicked lines. > There is also some interesting uses of float literal constants with 80 digits when at most 9 are relevant. -- Steve From owner-freebsd-numerics@freebsd.org Mon Dec 31 16:15:41 2018 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 4F26E1439028 for ; Mon, 31 Dec 2018 16:15:41 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from sonic309-14.consmr.mail.bf2.yahoo.com (sonic309-14.consmr.mail.bf2.yahoo.com [74.6.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B94E0723CA for ; Mon, 31 Dec 2018 16:15:40 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1546272934; bh=nXmCBKu/E63kGRWH5DHEtPrSpdGc76qcQxfPeHD4IBc=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=uS379B0uwNQ+zk07/ND8XPargnFOgI333psA64/nC9U/+WeNnN8DDsArM33IiOfCTdda4Uqwq00jr4zoRLwaAIqFpH9rcZKIAacfsWxhe4uGh+SrjGSIto5GNx8zM2mQg4e6TMWebT6PJ8P+Rt3zPKDh1Ck1ntdLPnDeGoxKTgfQzEGSZx92elaRFHd8yZiqrW+QbkzeU1gY79HeMlvXbIZCjALdTtxmCP08iPk+ZuR4Nf9UveunqR5r5oiC+mWAGPV/Bwoz8dhf45tegdSv1OJfKSq9Pi6IGoZKqqh00xhLtLuMKvUtGn18/EiWhOi1XFXdmY1/TbADdA8iXpzYOQ== X-YMail-OSG: BwSLEQYVM1kAi44G3NpDXO7thSVWjWRYOY4OV6XUgD6.SFfyfyg05IzVKhmVLEf dHAMtuz1lLKRO97S6oxWTnKpwwfVA4RRo2Yv0XtyjaU78X_WL23e8Oyes2RPEi5TkrNGUweS_IzG jsIkF3lbl6pmzVW3lBfVh.9FF_PvlnxsS4S98K1iSvi0hzVhkK8jfZwP79qiiLOTshxnkEy10vqP Q7ssku5oldxrVGWLzbh5JRzFCzDaDOTBTMEUqC_GM4luVPYfTm8wgxu0GstRj7VIQV7VXKOU3zkA kZgcETqDiRsr9gYP9YGm_nM8A6ErQAn9bnKvN2FmYOw3d3b_ByG4eMWwusXtakVyFrVN_ydMb_NF lBUSJlCCZ_oi3VLA2xCRgdmzl0dx.IVfj45wRah7M2fLHf75B3JZbQs73rxJZ_1qmQVjYz43tMQq sVoXAlDWdsm9VXoNxFwQ52Vkn3WRU14ge_fwlC9nKMz1dXn0F4LbpWv0kMsgeyx5SWgTQ0f1vobV 4sUIO3YOPljyg_TXqh27bWjPR6ejEPZntwgn1Qp3_aGNUZFWVrFpZKlP7Un7TqdASFcdXoa11MBu 9DGU607Oe4oNGF_oPKyKjXtFKQKF5wczUU1p4xfeQIUiVTBVkt9_KQNt1Ayg8E1HcsO8e3s9x1ea RnTUYffbVUgurs.iHKYiQEQSmJlX.sTTmyL87P5PUdGJdu0t2yACpLbNFnvWDwoRXK5KXgtxzBbD UQX3wl7uB7V7TJ1gNjwHBlDFCgzrxh.BMD4ZPDRQB1djIw5YbuQyeCUWtZEKvTI3NWQji.96E4iR z0vuVeLzaiP6grdIakfqbu1r8jt9N0cBBGGza318fxYjqFVgvpMjK9CfSTkikvBOxxwhWOr4fJIm MCdo2LXnETZBb9sRZmgiLUH_hvR.t5xXmjR8xxIXIesjnWV1tU8hxmcAVrAFbq5abvM5IQshGJoG _XQop9Ujz9pNMKIKW471t6GV5qFzuYokxNW8y3rEzsVLrL.SJw8qRZLZUk3AL1v8kpCZfUBFcsvo OH9cEP.PFxlerkCbr13j6_FiWl5920Qavo1SGH8fTGgM- Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.bf2.yahoo.com with HTTP; Mon, 31 Dec 2018 16:15:34 +0000 Received: from 181.52.72.201 (EHLO [192.168.0.5]) ([181.52.72.201]) by smtp411.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 0df031bad57b15665db6b7a4079b8623; Mon, 31 Dec 2018 16:15:30 +0000 (UTC) Subject: Re: New math library from ARM To: sgk@troutmask.apl.washington.edu Cc: freebsd-numerics@freebsd.org References: <797a7755-db93-1b9c-f3b9-8850d948e098@FreeBSD.org> <20181231151904.GB823@troutmask.apl.washington.edu> From: Pedro Giffuni Message-ID: <79234b63-8443-cc47-0ef7-27a6317a56c4@FreeBSD.org> Date: Mon, 31 Dec 2018 11:15:29 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20181231151904.GB823@troutmask.apl.washington.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Queue-Id: B94E0723CA X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.99 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.993,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:26101, ipnet:74.6.128.0/21, country:US] 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: Mon, 31 Dec 2018 16:15:41 -0000 On 12/31/18 10:19 AM, Steve Kargl wrote: > On Mon, Dec 31, 2018 at 10:06:57AM -0500, Pedro Giffuni wrote: >> Hi; >> >> Just noted a recent initiative from musl-libc: >> >> https://www.openwall.com/lists/musl/2018/12/08/1 >> >> It appears they plan to replace their (FreeBSD) math code with a new ARM >> implementation: >> >> https://github.com/ARM-software/optimized-routines >> > The Copyright on this code is unclear. For example, in > single/e_rem_pio2.c lines 1-6: > > /* > * e_rem_pio2.c > * > * Copyright (c) 1999-2018, Arm Limited. > * SPDX-License-Identifier: MIT > */ > > Then lines 16-18: > > /* > * Simple cases: all nicked from the fdlibm version for speed. > */ > > The original fdlibm licenses applies ot the nicked lines. > They should have kept the original headers. That is why I personally dislike the idea of replacing licenses with SPDX tags. We should probably report that upstream :(. FWIW, they had originally adopted an Apache License and later they relicensed it under MIT, apparently with the idea of assigning the result to the FSF. Pedro. From owner-freebsd-numerics@freebsd.org Tue Jan 1 03:32:14 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 5BF091426119 for ; Tue, 1 Jan 2019 03:32:14 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from sonic304-10.consmr.mail.bf2.yahoo.com (sonic304-10.consmr.mail.bf2.yahoo.com [74.6.128.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 004AB6B4B5 for ; Tue, 1 Jan 2019 03:32:13 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1546313532; bh=QcOeE9jyl8QPrVoYaho41LcUq/WI2EG8vtVDXGU/vWU=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=sdnrtYPJWu0Kp5y3H9t12MPaTifoBBupmGFBuL+PQk7J3pPHb7VFpEhOYwHKvjewgz0IOyzhxaD8DN+i1Ir5XuFNlfNwM1rz/fGbNspcSkd5DbGWe1Ia/4JOdRV2Jj2h1ZziX+DSfnofu/tNeZb5Vztef44b8Dd8Zyz629ZjFb25auCcBJeq3q8+PrU9Nv1ZwcCLKKD+M5cMAVBn0bTEDqS33AudVfswIoN+aLjUVQ6UxH4Q2khN+4vS7fAy6b0roGsuFX+IsMYRJQxSzzhhbvwzd7OJk5mgAJLi1ul/m9DGzj2gKpePCEsJlgYpr6XIDdXbstaESblwb8jpGfLMhQ== X-YMail-OSG: dTMVBZMVM1klQlbW2Vqswp6Q6arhL1E2tVashF9LcVC0O626aAdKOZbxSbfb6c6 _HdVBtd_gOW5FfCNFUB8WE9XXtVD4O1dbA45orV6.GsgOF.BI1EfuwkOUKZMfsJ.SF9EXbXULbdv Azd10L8LoQmajXsy_Qh0kB3SHKNPPg5DbdNZl4DBril598iDc0.VDgCcATWFlQm1qyV0leIrSlOj Ol9NL3EEQW2j9yrizjgyg13486eHICp3LQNRaygKZkqyndY7pEx0ujA6mYe5u1Z8Dws3Up8G5XtR g7XyIG1d1fYkhkSAN76ufDbFxA0hpbUVbty4Sy_9eqJETlhwRKCHTqjTPUT6QoxfouW_xK41bfW. J0SRvGBYQd.vx9IM.5A69omuWyHwAlvn6eRlP5xmHw02Hl2akQ55WU1QrxZyiWK3YfIHNHxxPiv2 9R.yr7XiJpvzunOrkJ7j21CFa4ZkmoHH.QvYSKxC_VOqjMVVSGqE1XdshL8tznMUG0tppcFt4nR9 3dBazs_qMMdqbzzYSzDytago94cxjSL8wN3BGICl45OITIfsQdoolAn1Cwh6SKgK1vVMlpt3lPGW h7Wzkjjo0cQfvbcZZyLKsTLR9iyBULf4uf2JPEk65FOVEf.StRh_tzSu2iafhYMEW0aytRIkxJq0 lNFYJ4mXUkIr.BeNd1_YdxHXLye4KflCmQwwa7v5Vjc4eQvWpC8TaIBAATsLMKpBP.RHf8drg0Wr SS65Bzr9_aL2Eg93hU60l1ISxqEgE6Ei48GxC5kmmdyYtO67GIGbYxGQOEJ_HXsA.vwRdZJ1ta8Q 6cSHWvffGJJZf71dfriSaI4f3zOdEdxyz.KQX_T9FYze5wG5fXy2AmFnTnlg0Pt3ja0jZhcPBBGF JgxoplyoMpLMdGJvh5MjCUIqINe3jByhmyAB_IFGMYIUxU.RuXgyBj_bk9WKoOL9uK2zDhEfkHel wwuGen2OGszmfiPzt9VUrAi.YBjwxZXIX1XHOB7Vss.HSeOUb.Ek2BQyLIMNeNrPSUJkurAntViH S0fKcn280pzNbZhwE3J82nISiqjETI8c46bTcFEZm.w-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.bf2.yahoo.com with HTTP; Tue, 1 Jan 2019 03:32:12 +0000 Received: from 181.52.72.201 (EHLO [192.168.0.5]) ([181.52.72.201]) by smtp402.mail.bf1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 48c39b9979d3c721aa0307d008f2f9a0; Tue, 01 Jan 2019 03:32:08 +0000 (UTC) Subject: Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM) To: freebsd-numerics@freebsd.org Cc: 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> From: Pedro Giffuni Message-ID: <06c8b6a2-ed26-f255-3947-c79b593a9dea@FreeBSD.org> Date: Mon, 31 Dec 2018 22:32:06 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20181231152230.GC823@troutmask.apl.washington.edu> Content-Type: multipart/mixed; boundary="------------77F699FB60D2895086164B43" Content-Language: en-US X-Rspamd-Queue-Id: 004AB6B4B5 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.980,0]; ASN(0.00)[asn:26101, ipnet:74.6.128.0/21, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] 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 03:32:14 -0000 This is a multi-part message in MIME format. --------------77F699FB60D2895086164B43 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. --------------77F699FB60D2895086164B43 Content-Type: text/x-patch; name="msun-pow-ub.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="msun-pow-ub.diff" 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); --------------77F699FB60D2895086164B43-- 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 From owner-freebsd-numerics@freebsd.org Tue Jan 1 05:14:48 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 60D03148984C for ; Tue, 1 Jan 2019 05:14:48 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from sonic308-10.consmr.mail.gq1.yahoo.com (sonic308-10.consmr.mail.gq1.yahoo.com [98.137.68.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B11B77043C for ; Tue, 1 Jan 2019 05:14:47 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1546319684; bh=daKsXulAQjTqXHVBa3qqyNGANBtrlHOWANep3fQvi+0=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=o8aMGazHK3sjPvWrxTBfKLVPIXed5iazwQAIpK2VkQ4f8YjC9wDIKk792fPWXpgzNlEtxkGQ/vnWpTIsEzn9tMmPfUYn1icZrNjRa1vw1TLewKzFDR30xtJlMuV4IPJ6o+Ax4mmCYS8rK04PfanpybNhmH/+KqztnS+FhajqXpYpol46YSf2Cts6EqwsnrCM7FHDlXAr7n9qczHP6JoK0281sh39Dg+BGFu78MmhEBRUbKlXIfz7zue4SHGBNX+pX85K32sTxIE7AjGpsv9vaakRCHQGhE5TWtjOJXhzTbzphmn4U67IEGlfbYqXhbgTb+MLBvdtoAWEsFTPWs19Fg== X-YMail-OSG: Jx8utVkVM1lF07FWQcAl7C60aekPo7r62b4fjnDQuiNgHDwp_uFSj9jc9dY8DVy MLcMVLQNZ7GgrXBtLU6n18cAYM3x_.nX7VG1L6fy_JAoY_E3yl7qTB6.nKIG_L4KMgQbqF1JR8Wv QShbo9Wr6KqwOOXp2hv2YaB8_C5ty8RVIv30v3yNsdfMXL08oU6pOiw8d4UdlT_AoDy0aR7JvMD0 JKnwsav66fSY.KmI42r7teFlBx7vhpHwzA3i.Xc.3FJxW2Xz21YI4CvAPbiHVPNkUaf2TYN.AyVt C3s4YFxVoSz_ZW7cAVuyrclMgu3V_QK1J9O6orjR2SqkJ9rbYn.c85cQ3pfDALoLIYLlBjuJXhwv aG.42ZgA605WPP_s_iMFuvjXoAYzXFPZO7sTSsicBOyplTkVfSqBmlohw6BIpolzgiXcGAYPhftU fzgeQaf4.D_ei0GW4duL8NMjGaNa5BUA9y2O5A8TiL88dbLOXWhH2VE9rRT6pFt8L9DIpTeEj8k_ BrOlF1EP9MGehMxvBY5taKIDV_Ob5Qmw7GtqC9eBKPlGwaqQcU2YmSAOMD9Wl_OqX_3ZoTnb3ApM hIisQEYV3K6qN9zt1FGt5UKR4YHVPzVhjyVVTB1maRU4xmFojEqgrEgu7qTxQ2waZ6pEllo4nIYO AXLxifEpMxE5_n53kAIk8Y.3I8Pv7uxFqDozZm6pz1VEh9ZzyoiYVmlbDxFB5dWhWRbV5TaIyHxj qtf07zsiGgLAaQ358hxUdlw6CmlQ5z1Pg1hyD7usykgRjQjEOYJC8kpR1KbEwaPGnh.2QQlElBjq qJeKeGCkw0dgKdMdXXcLrTaiihf2BByhlF_MK5ibP1sfISK9KebzTIb2DcjVA9E36Jn7PJJp88TM koXZkfG083qi0JRLjFmaJgnrlNoAw3cJfhLs61CJ4dXgPJjGrTGXNoKyCHM32ara7vYG7RRxls0v xM2kzATg1sC8VlwxDCgnyFrrr7JIguqNS6t9aDL4rMHQ2.i79OwkOFjXmRoQuZZDxDZinuGLK19P 9sj9_d7sOM8WLCDbVEAldBvkJOday750keVz.oAU- Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.gq1.yahoo.com with HTTP; Tue, 1 Jan 2019 05:14:44 +0000 Received: from 181.52.72.201 (EHLO [192.168.0.5]) ([181.52.72.201]) by smtp427.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID ecd8ae500f6c69bcb014abf6efa764dd; Tue, 01 Jan 2019 05:14:39 +0000 (UTC) Subject: Re: Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM) To: sgk@troutmask.apl.washington.edu Cc: freebsd-numerics@freebsd.org 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> From: Pedro Giffuni Organization: FreeBSD Project Message-ID: Date: Tue, 1 Jan 2019 00:14:38 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190101045425.GA5767@troutmask.apl.washington.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Rspamd-Queue-Id: B11B77043C X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.964,0]; ASN(0.00)[asn:36647, ipnet:98.137.64.0/21, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] 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 05:14:48 -0000 On 31/12/2018 23:54, Steve Kargl wrote: > 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 Modern standards let you declare variables within blocks. For style we do prefer to start the function with them but in this case we can't. > 2) j is already declared as int32_t And it has to be a signed integer: we later check for negative values. > 3) uint32_t should be written as u_int32_t. No, uint32_t is the standard type, u_int32_t is a BSDism. Also, the file consistently uses uint32_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? The point of the Undefined Behavior is precisely that it doesn't occur: we are lucky and the compiler behaves as it always has but the standard will let a different compiler behave differently and then we will have surprises. From owner-freebsd-numerics@freebsd.org Tue Jan 1 05:52: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 E6760148C56A for ; Tue, 1 Jan 2019 05:52:29 +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 D2B2576150; Tue, 1 Jan 2019 05:52:27 +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 x015qPMi006039 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 31 Dec 2018 21:52:25 -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 x015qPVC006038; Mon, 31 Dec 2018 21:52:25 -0800 (PST) (envelope-from sgk) Date: Mon, 31 Dec 2018 21:52:25 -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: <20190101055225.GA5982@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Queue-Id: D2B2576150 X-Spamd-Bar: +++ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [3.18 / 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.65)[0.654,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.45), ipnet: 128.95.0.0/16(0.26), asn: 73(0.18), country: US(-0.08)]; NEURAL_SPAM_SHORT(0.99)[0.986,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.69)[0.694,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 05:52:30 -0000 On Tue, Jan 01, 2019 at 12:14:38AM -0500, Pedro Giffuni wrote: > > > I'll defer to Bruce on this. My only comments are > > 1) declarations belong at the top of the file where all declarations occur > > Modern standards let you declare variables within blocks. For style we > do prefer to start the function with them but in this case we can't. I'am aware of what modern standards allow. I'm also aware of the code style of fdlibm, which I think should be maintain. > > 2) j is already declared as int32_t > And it has to be a signed integer: we later check for negative values. Yeah, I know. That's why I pointed out the collision. > > 3) uint32_t should be written as u_int32_t. > > No, uint32_t is the standard type, u_int32_t is a BSDism. Also, the file > consistently uses uint32_t. Ah, no. e_pow.c uses u_int32_t on line 107. 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? % 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. -- Steve From owner-freebsd-numerics@freebsd.org Tue Jan 1 06:21:04 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 42C10148E378 for ; Tue, 1 Jan 2019 06:21:04 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from sonic314-22.consmr.mail.ne1.yahoo.com (sonic314-22.consmr.mail.ne1.yahoo.com [66.163.189.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A6CC481B59 for ; Tue, 1 Jan 2019 06:21:03 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1546323657; bh=VwEziizEt8F1cRofhoK4deHVEGZ3/ud2kCUPSIXdnBI=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=Q0d1066gLX67ddbDooyesWVbmY9jiJX6Y+qfz+1gmjQppCgUr6XKflzeHT5B3fcvDKdLGmPta9e0a5UMVBu/RwOAIr3X/SSDQAPyYljQ03VDkLSVlhZsKX9mPO2I9Dy8dNPSwDCra9ZmVLMQSUrwPRSr3UCjrjQceSFYaB0eF5QrBPiapDjIwqK71ePsXMAh8M/EBwr6HHyEnLCnuUzV8KvbYPRkDy1ZDAozvCY1cAHFNbSMzmqDxv5ioaRaMsj+d/ri90NITfVt2Pj4dNE6Dyc5AOKJ+8fY39nEJOOjf8j5PHKPa5xERr+3OxqMUPSw3OldnG+vM/K9XElQ+Vut7Q== X-YMail-OSG: s7zxSp8VM1lhqUZcLCJOVujoYqq2HTTqw1lziYrtaYatoiF7PcXyuTi065qWagx iEwWsZTRZir_wTo1HRUz0fyYXlOlArCP80nA6qWLcAfXtq.tLtCg3_8i8z2lDaTvmFfncpzlS.Lx HtKyju_6B4yTmncIWxXfSAFxjQphZlgLHkVQSjhyxBPWvmB4WRho76jA.h5ZnTtaXqjEzOll_ES6 vkg8CnoxnPKlj4ZstV7YHdASzZOncCQCO7v8RAXOh04td8Rzzxe28g.f_jbMMzuLs94rT_eIDUY7 qEPFgx0WJOQCamCFe7pIP.Pp0jiBYPOYvue3C_5r9eJUcM1NX218T9OIewTZfBDD2lDeMf1QZhAU wj.EmuQfX.SobeBwdQ4tVgSayzLh3Y_dm.Vwf8PYwWTz2HDJjtE9dptR4XYau3fF2RrmunUcdYud B3cihIr7cxUohxNvUaRmSr8DPU3x67VOe8gSSmJlhxO2Pp.MrXEhaFlaYqJXU7585gigNy2zEuFG p6lmvB0MOgrnhFnK.4SO.KUBFZRBoFWAtd7K9hSgtk2vfZadhgK_ixtmc9oRywLRaUavawU.Rlji DyTCwL0TWXuTChEOgtEVIgo9XmFK64wFKm7Nz9Q8Olsz4ejqB1.YQQrqJb6lQSWUS1SjFJTdssGQ 0ZaSkFXvuvZ7VqgiscNgK1oSBQ3auzzVRcPRygPUOINyQzFcTJcCehPKGHwcTq1XKfb6grQTF914 3KBWsu0lwxkTAZK4nyGofsOG8JhmwvHbTOf7IlbRe3vjIOi5yKzzOKniDhyCHr5b1trWvBrqVJYV pT3n9Z0ihZdORL4YnlYdVmUvTUtvGFm7HKyVQSyiyeCsEJCEn3KQhnFJvoprTZBGmsiysXPYC3v2 30kELXTMPKEs0ZXl0q3vRhQHRFxfR4OXEbTImGUmm7YdGXhc0XOzrDNZdZTi3ud6URoRzS9MTD0y xHdGQNpddSzKvdY9pUUEwUOeDk730qGKBWUNnTiK9xoLpFACrrOPnrLpkobJ1umfQkTxsGHDL7Df _TTBeTPeWH7p2onwcNcXKAgT_mOSuu5xxQ5WdE51k Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ne1.yahoo.com with HTTP; Tue, 1 Jan 2019 06:20:57 +0000 Received: from 181.52.72.201 (EHLO [192.168.0.5]) ([181.52.72.201]) by smtp412.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 05daaf1df328de8df0de7fb0328cff94; Tue, 01 Jan 2019 06:20:54 +0000 (UTC) Subject: Re: Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM) To: sgk@troutmask.apl.washington.edu Cc: freebsd-numerics@freebsd.org 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> From: Pedro Giffuni Message-ID: Date: Tue, 1 Jan 2019 01:20:53 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190101055225.GA5982@troutmask.apl.washington.edu> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Rspamd-Queue-Id: A6CC481B59 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.93 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.93)[-0.933,0]; ASN(0.00)[asn:36646, ipnet:66.163.184.0/21, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] 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 06:21:04 -0000 On 1/1/19 12:52 AM, Steve Kargl wrote: > On Tue, Jan 01, 2019 at 12:14:38AM -0500, Pedro Giffuni wrote: >>> I'll defer to Bruce on this. My only comments are >>> 1) declarations belong at the top of the file where all declarations occur >> Modern standards let you declare variables within blocks. For style we >> do prefer to start the function with them but in this case we can't. > I'am aware of what modern standards allow. I'm also > aware of the code style of fdlibm, which I think > should be maintain. Well, the alternative is the musl-libc patch, which declares the variables upon use (twice). I think my patch is a little bit more acceptable. >>> 2) j is already declared as int32_t >> And it has to be a signed integer: we later check for negative values. > Yeah, I know. That's why I pointed out the collision. > >>> 3) uint32_t should be written as u_int32_t. >> No, uint32_t is the standard type, u_int32_t is a BSDism. Also, the file >> consistently uses uint32_t. > Ah, no. e_pow.c uses u_int32_t on line 107. Duh! I completely misread, sorry about that I probably was still looking at musl-libc instead. Yes, we should use u_int32_t. > 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. > % 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. Pedro. From owner-freebsd-numerics@freebsd.org Tue Jan 1 15:01:50 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 7BB46141B17A for ; Tue, 1 Jan 2019 15:01:50 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from sonic316-8.consmr.mail.gq1.yahoo.com (sonic316-8.consmr.mail.gq1.yahoo.com [98.137.69.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CA5A671DA4 for ; Tue, 1 Jan 2019 15:01:49 +0000 (UTC) (envelope-from pfg@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1546354906; bh=jtd7BnKCEum75h9MVzGvY82HkjmVy0CG12EsUpFtQU4=; h=Subject:From:To:Cc:References:Date:In-Reply-To:From:Subject; b=DKNpylPUdnk+QDrDiB+v5g28EAcTSbQFF9Git9zFoe3rCc/GAt9xCvD+PWJGp1xuI0jjVIzodaT+V0/DybyWLATBzNVUiwcx2oNlNZiy4HDo3Hho9C/PIlU/pKYrvjgqwpg6JW2aiE2pPygFywYyez5lN8lA9BpLXUKi3BXcjCCPljeapW/c3FEzAuHk8puAomNZgkHTQGyhK0fOv8KAyTwL4jr9nz4yR9Hn2DtEG1iTBPWBrxI7ZtsfvkNJL1UrWxl+yAW1OU790spLTgw9U0Kpm1ZvAtVTCr7azrGze2vKI7LjR+G5OQjUeJ/X5DuMO0MHouhAaaGp3vFOD/ydnw== X-YMail-OSG: TmguIWkVM1kpuhvfSOnvGmfuqjdHXezTpwJ7kpPb4bKUs2vkMuif0BNjO4o2Xy6 1aE3B8x9d3U4GWjRqhzo23aT0FW1cS9oZdKv9ORGTJzkBy3Ut2ySBPregLB0MCdjGUJKzLslQzHd XOTxvD1e3NiBotCahYbU8rBtKpZFX1KMkqnPnxAebRZo5Abay7NR.oJbPW2MX.sljXGjWKBRXwa0 Z87Ci2PAb.PxQtPL37YYxb5yS5OUS7vIEGYDhwNfbA.FJZdW7HrmDjSb3i3ggH0MAEE7eO1kqrdE wbcuL0kFs22JNNefaaLqscPZKd9uAtA7i6DYWVgfAOeUH3GFbl71RJEOBA_HKsxHJAGQGHlmxdte ZirwNN57l1fwOCS3grQWWPZZj5Uu4RLJE33L5cMHzxter93KJQ_5yRGs1ZgKPTp7lH3fMs2zdfTn GKFfhh0xnImF.DBOc6xmhw_1XtJywSms4RcjyN1dTAwpcNLXEaNu2Cu6cOBBobl31eOVNcoYomjR meoO9AqA5aNVwAjhUxzwBpMI1uLGeHF4K6EuyKutxDmnlvIiepRK1m29S5HyyM3lDa1PjyMFIGEq TS6BJBqknTjzu.mvGYRs5BE15U1w7B72vFiNMKBp28y4XBuDXKdPuVx8NxpJuO4pH_ilz6mYchgm rw8stc0GZYh5x9sxw.xkehX_bgDABMqG_T4rbpE0XvYlWGPd8yNrLebGAajcb4koh.1l6cKijlkN DnSM2kIjsdTz4W6Z7fxmOh5kjiVpbEv8GxaaHa7YMVcR8JuJjfbDy5LOexOSYp_6_p9rVG0Mk8Ky XhGjnki9KJycNHX1vOF04rmfOX_pYjyXuRBq1fDznDPA3DfpxWn70xGLm8zZnaoxfqJVsXkRwTCI vWep1g0V2cyPJYUCRADRPzAxvTBNmyZS0A9z_CF55kAvQ13QDUtRaVMbzbZz6OEougWiD_4vx5i1 dlgJgyGJYq08YuwSM_G4KTXShlTkVDhPS1G7uUEP.BgMHKGPhBMjpE.2rID7iqclVX9zEL.6wNJo KP5D9cfRKrZSBpSrB3qrKeGHhtSqmtr3j5A1aSmIBf.M- Received: from sonic.gate.mail.ne1.yahoo.com by sonic316.consmr.mail.gq1.yahoo.com with HTTP; Tue, 1 Jan 2019 15:01:46 +0000 Received: from 181.52.72.201 (EHLO [192.168.0.5]) ([181.52.72.201]) by smtp403.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 798d012e16fa5a294af7c4216195e738; Tue, 01 Jan 2019 15:01:46 +0000 (UTC) Subject: Re: Undefined Behavior in lib/msun/src/e_pow.c (was Re: New math library from ARM) From: Pedro Giffuni To: sgk@troutmask.apl.washington.edu Cc: freebsd-numerics@freebsd.org 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> Message-ID: <9cdce84b-2cff-d752-67a9-4c9ef391cc2c@FreeBSD.org> Date: Tue, 1 Jan 2019 10:01:45 -0500 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------82A09505CD03AE157475B862" Content-Language: en-US X-Rspamd-Queue-Id: CA5A671DA4 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.980,0]; ASN(0.00)[asn:36647, ipnet:98.137.64.0/21, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] 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 15:01:50 -0000 This is a multi-part message in MIME format. --------------82A09505CD03AE157475B862 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 1/1/19 1:20 AM, Pedro Giffuni wrote: > > On 1/1/19 12:52 AM, Steve Kargl wrote: >> On Tue, Jan 01, 2019 at 12:14:38AM -0500, Pedro Giffuni wrote: >>>> I'll defer to Bruce on this.  My only comments are >>>> 1) declarations belong at the top of the file where all >>>> declarations occur >>> Modern standards let you declare variables within blocks. For style we >>> do prefer to start the function with them but in this case we can't. >> I'am aware of what modern standards allow.  I'm also >> aware of the code style of fdlibm, which I think >> should be maintain. > > Well, the alternative is the musl-libc patch, which declares the > variables upon use (twice). > > I think my patch is a little bit more acceptable. > Actually, perhaps a cast is just enough ... See below ... >>>> 2) j is already declared as int32_t >>> And it has to be a signed integer: we later check for negative values. >> Yeah, I know.  That's why I pointed out the collision. >> >>>> 3) uint32_t should be written as u_int32_t. >>> No, uint32_t is the standard type, u_int32_t is a BSDism. Also, the >>> file >>> consistently uses uint32_t. >> Ah, no.  e_pow.c uses u_int32_t on line 107. > > Duh! I completely misread, sorry about that I probably was still > looking at musl-libc instead. > > Yes, we should use u_int32_t. > > >>    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. > > >> % 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. Pedro. --------------82A09505CD03AE157475B862 Content-Type: text/x-patch; name="msun-pow-ub.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="msun-pow-ub.diff" Index: lib/msun/src/e_pow.c =================================================================== --- lib/msun/src/e_pow.c (revision 342665) +++ lib/msun/src/e_pow.c (working copy) @@ -133,7 +133,7 @@ k = (iy>>20)-0x3ff; /* exponent */ if(k>20) { j = ly>>(52-k); - if((j<<(52-k))==ly) yisint = 2-(j&1); + if(((u_int32_t)j<<(52-k))==ly) yisint = 2-(j&1); } else if(ly==0) { j = iy>>(20-k); if((j<<(20-k))==iy) yisint = 2-(j&1); --------------82A09505CD03AE157475B862-- 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