From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=44352 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PN6kW-0006OK-Tf for qemu-devel@nongnu.org; Mon, 29 Nov 2010 11:38:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PN6kV-00030j-EW for qemu-devel@nongnu.org; Mon, 29 Nov 2010 11:38:44 -0500 Received: from mail.codesourcery.com ([38.113.113.100]:59950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PN6kV-00030a-4m for qemu-devel@nongnu.org; Mon, 29 Nov 2010 11:38:43 -0500 Date: Mon, 29 Nov 2010 08:38:42 -0800 From: Nathan Froyd Subject: Re: [Qemu-devel] [PATCH 07/12] ARM: Return correct result for float-to-integer conversion of NaN Message-ID: <20101129163842.GA8544@codesourcery.com> References: <1290538431-13170-1-git-send-email-peter.maydell@linaro.org> <1290538431-13170-8-git-send-email-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1290538431-13170-8-git-send-email-peter.maydell@linaro.org> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel@nongnu.org On Tue, Nov 23, 2010 at 06:53:46PM +0000, Peter Maydell wrote: > The ARM architecture mandates that converting a NaN value to > integer gives zero (if Invalid Operation FP exceptions are > not being trapped). This isn't the behaviour of the SoftFloat > library, so NaNs must be special-cased. > > +/* Helper routines to identify NaNs. Note that softfloat's > + * floatxx_is_nan() actually only returns true for quiet NaNs. > + * A NaN has an exponent field all 1s and a fraction field > + * anything except all zeros. Conveniently we can detect this > + * by masking out the sign bit and doing an unsigned comparison. > + */ > +static int float32_is_any_nan(float32 x) > +{ > + return ((float32_val(x) & ~(1 << 31)) > 0x7f800000UL); > +} > + > +static int float64_is_any_nan(float64 x) > +{ > + return ((float64_val(x) & ~(1ULL << 63)) > 0x7ff0000000000000ULL); > +} Why not just use: static int float32_is_any_nan(float32 x) { return float32_is_nan(x) || float32_is_signaling_nan(x); } and likewise for the 64-bit case? -Nathan