From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vgjdg-0001cg-RX for qemu-devel@nongnu.org; Wed, 13 Nov 2013 18:14:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgjdY-0007wb-Ed for qemu-devel@nongnu.org; Wed, 13 Nov 2013 18:14:24 -0500 Sender: Richard Henderson Message-ID: <528407BE.6000707@twiddle.net> Date: Thu, 14 Nov 2013 09:14:06 +1000 From: Richard Henderson MIME-Version: 1.0 References: <1383769916-5582-1-git-send-email-tommusta@gmail.com> <1383769916-5582-13-git-send-email-tommusta@gmail.com> <527C221A.5000609@twiddle.net> <527C2297.7040407@twiddle.net> <527C2C92.7060006@twiddle.net> <5283E5BE.1080809@gmail.com> In-Reply-To: <5283E5BE.1080809@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 12/14] VSX Stage 4: Add Scalar SP Fused Multiply-Adds List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Tom Musta , qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org On 11/14/2013 06:49 AM, Tom Musta wrote: > I have reviewed the code and the spec and I cannot see a flaw. The sequence is > effectively this: > > - float64_muladd - performs proper FMA for 64 bit numbers) > - float64_to_float32 - converts to single precision, including proper rounding > - float32_to_float64 > > The implementation of float64_muladd would seem to provide enough mantissa bits > for proper handling of the case you describe. The only rounding occurs in the > second step. > > I have also done quite a bit of random and targeted random testing using Power > hardware to produce expected results. The targeted random tests followed your > suggestion above: generate AxB + C where abs(exp(A) - exp(B)) = 23 and > abs(exp(A) - exp(C)) = 46. Several million test patterns have been generated > and played back through QEMU without any miscompares in the numerical results. Here's an example that produces wrong results when rounding to double first. Replace the portable math.h calls with ppc asm as necessary. r~ $ cat z.c #include #include float a = 65281; float b = 257; float c = 0x1p-29f; int main() { double dd = fma(a, b, c); float d = dd; float e = fmaf(a, b, c); printf("a = %a\n", a); printf("b = %a\n", b); printf("c = %a\n", c); printf("dd= %a\n", dd); printf("d = %a\n", d); printf("e = %a\n", e); return 0; } $ ./a.out a = 0x1.fe02p+15 b = 0x1.01p+8 c = 0x1p-29 dd= 0x1.000001p+24 d = 0x1p+24 e = 0x1.000002p+24