From: Message-Id: <200306231801.h5NI1p7N013912@speedy.ludd.luth.se> Subject: Re: fpclassify In-Reply-To: <3EF60409.FCD867F@phekda.freeserve.co.uk> "from Richard Dawe at Jun 22, 2003 08:31:21 pm" To: djgpp-workers AT delorie DOT com Date: Mon, 23 Jun 2003 20:01:51 +0200 (CEST) X-Mailer: ELM [version 2.4ME+ PL78 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-MailScanner: Found to be clean Reply-To: djgpp-workers AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp-workers AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk Hello. Thumbs up for the feedback. Besides corrections in this mail. I've done: Eli: FP_* symbols should be in @code Richard: was -> were. Esa: @findex According to Richard Dawe: > > Note that I kept __attribute((const)) in the texinfo file. > [snip] > > I don't think we should keep this in the documentation. I think the > documentation should have the ANSI declaration, if it's an ANSI function (*). > __attribute__((const)) is an implementation detail - a gcc-ism. I'm also don't > think the user cares that it has this attribute. The user may care about > __attribute((noreturn)). Ok. > libc seems to use __attribute__, not __attribute. Please use __attribute__ to > be consistent with the rest of the library. Yes. > Can you write some tests, please? Maybe you have some, but forgot to include > them. I have an isinf (or was is isnan) test so far. I'll try to make more (time time time). > Out of interest: why did you write this in assembler rather than C? To avoid > the type-punning unions (float_t, etc.)? That is a nice side effect. No, it started with my writing isnan{f,d,ld}() in assembly. The goal was to write them without any jumps, which meant fun with setCC, dec, sar and and. Plus improving my assembly. Then I found/remembered fpclassify() and realised that obviously isnan*() should be coded as fpclassify(X) == FP_NAN. So I reused my isnan*()s. Alas the cases is many more for fpclassify(), so I removed the non-jump acrobatics to favour (what I think is) the usual case (no taken jumps for FP_NORMAL and one for FP_SUBNORMAL and alas two for FP_ZERO, the others don't care (which became one to two taken jumps)). If somebody thinks that the non-jump version would be a good idea I could redo them like that, but in that case I'll probably clobber many registers so there probably needs to be a couple of pushes/pops. Here's the (now obsolete) isnanld.S so you get an idea of what the code would look like: /* * File __isnanld.S. * * Copyright (C) 2003 Martin Str@"omberg . * * This software may be used freely so long as this copyright notice is * left intact. There is no warranty on this software. * */ /* * Stack: * 12(%esp): high 16 bits of the long double * 8(%esp): middle 32 bits of the long double * 4(%esp): low 32 bits of the long double * 0(%esp): return address */ .globl __isnanld __isnanld: movw 12(%esp), %cx xorl %eax, %eax /* Need eax zeroed for setne below. */ andl $0x7fff, %ecx /* Use ecx to check for exponent 0x7fff. */ movl 8(%esp), %edx /* Use edx to collect any set bit of the mantissa. */ cmpl $0x7fff, %ecx movl %edx, %ecx /* Use ecx to verify that high bit of mantissa is set. */ setne %al andl $0x7fffffff, %edx /* Clear high bit of mantissa. */ sarl $31, %ecx /* ecx all 1s if bit 31 is set else all 0. */ orl 4(%esp), %edx /* edx contains at least one set bit if any mantissa bit is set in the long double. */ dec %eax /* eax all 1s if long double exponent == 0x7fff, else all 0. */ andl %edx, %eax andl %ecx, %eax ret > I have some documentation corrections: > > +Returns the kind of the floating point value supplied. You should use > > +the type generic macro @code{fpclassify} instead of this > > Can you add a cross-reference, please? E.g. (@pxref{fpclassify}). Done * 3. > > +if( __fpclassifyf(0.0) != FP_ZERO ) > > Typo: __fpclassifyf -> __fpclassifyd. Done. > > +if( __fpclassifyf(0.0L) != FP_ZERO ) > > Typo: __fpclassifyf -> __fpclassifyld. Done. Right, MartinS