From owner-freebsd-numerics@FreeBSD.ORG Thu Mar 27 02:29:24 2014 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4D07AFDD for ; Thu, 27 Mar 2014 02:29:24 +0000 (UTC) Received: from um-tip2-missouri-out.um.umsystem.edu (um-tip2-missouri-out.um.umsystem.edu [198.209.49.149]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "um-tip1.um.umsystem.edu", Issuer "InCommon Server CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id DAC8FDB5 for ; Thu, 27 Mar 2014 02:29:23 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMFAAqMM1PPoJ7S/2dsb2JhbABZDoJ4O1fDAYEbFnSCJQEBAQRrDQEQAgEIDgoJFg8JAwIBAgEgJQIEDQEHAQGHdco0hnEXjj4zB4Q4BIkakGaRAIJvP4Ir X-IPAS-Result: AhMFAAqMM1PPoJ7S/2dsb2JhbABZDoJ4O1fDAYEbFnSCJQEBAQRrDQEQAgEIDgoJFg8JAwIBAgEgJQIEDQEHAQGHdco0hnEXjj4zB4Q4BIkakGaRAIJvP4Ir Received: from um-ncas5.um.umsystem.edu ([207.160.158.210]) by um-tip2-exch-relay.um.umsystem.edu with ESMTP; 26 Mar 2014 21:28:16 -0500 Received: from UM-MBX-N02.um.umsystem.edu ([169.254.5.16]) by UM-NCAS5.um.umsystem.edu ([207.160.158.210]) with mapi id 14.03.0181.006; Wed, 26 Mar 2014 21:28:14 -0500 From: "Montgomery-Smith, Stephen" To: Steve Kargl Subject: Re: clang is almost useless for complex arithmetic Thread-Topic: clang is almost useless for complex arithmetic Thread-Index: AQHPSIl06QNmv2vusESQ4jQvsrqL3pr0g5GAgAAB8QCAAAWfgA== Date: Thu, 27 Mar 2014 02:28:13 +0000 Message-ID: <53338CB9.4030405@missouri.edu> References: <20140326002205.GA9940@troutmask.apl.washington.edu> <53338661.7060205@missouri.edu> <20140327020802.GA15862@troutmask.apl.washington.edu> In-Reply-To: <20140327020802.GA15862@troutmask.apl.washington.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 x-originating-ip: [207.160.158.206] Content-Type: text/plain; charset="iso-8859-1" Content-ID: <6CD2E0D9F68C01428F4C357F002041BD@missouri.edu> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "freebsd-numerics@freebsd.org" X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.17 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: Thu, 27 Mar 2014 02:29:24 -0000 On 03/26/2014 09:08 PM, Steve Kargl wrote: > On Thu, Mar 27, 2014 at 02:01:08AM +0000, Montgomery-Smith, Stephen wrote= : >> On 03/25/2014 07:22 PM, Steve Kargl wrote: >>> It appears that clang developers have chosen the naive >>> complex division algorithm, and it does not matter whether >>> one turns CX_LIMITED_RANGE on or off. This means that=20 >>> if one uses clang with complex types, one must be careful >>> with the range of values allowed in complex division. In >>> other words, implementation of complex libm routines cannot >>> use complex data types and must fallback to a decomposition >>> into real and imaginary components.=20 >> >> Could someone write a patch for clang to fix this? >=20 > Well, I certainly hope someone writes a patch. I don't > know the internals of llvm/clang/compiler_rt. >=20 I did a bit of grepping. Could it be that the division algorithm is contained in the file src/contrib/llvm/tools/clang/lib/CodeGen/CGExprComplex.cpp inside the function ComplexExprEmitter::EmitBinDiv ? If you look at the code, it certainly looks like it is generating code to perform complex division, and it definitely looks like they are using the naive algorithm. Presumably even if one didn't fully understand the C++ used, one could do a "monkey sees - monkey does" change to the code, and then do some tests to see if it works. Although looking at figure 5 in http://arxiv.org/abs/1210.4539, it becomes clear that one has to include conditional in the generated code. So maybe you would need a bit of guidance from someone more expert in the clang compiler. Stephen=