This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: Fix __signbitf() and __signbitd() for 16-bit targets


Hi Guys,

  I ran across a couple of bugs in the implementations of __signbitf()
  and __signbitd() should the target happen to use 16-bit integers:
  
  Firstly the functions pass the "unsigned int" type to the
  GET_FLOAT_WORD and GET_HIGH_WORD macros, but these macros are
  expecting a "__uint32_t" type.

  Secondly they assume that the "int" return type is wide enough to hold
  bit 31 of the extracted word.

  The patch below fixes both of these problems and results in fixed gcc
  testcase (gcc.dg/pr43419.c) when run on a 16-bit target.  (With no
  regressions for 32-bit and 64-bit targets).

  OK to apply ?

Cheers
  Nick

newlib/ChangeLog
2013-12-18  Nick Clifton  <nickc@redhat.com>

	* libm/common/s_signbit.c (__signbitf): Pass __uint32_t to
	GET_FLOAT_WORD.  Convert return value into a boolean.
	(__signbitd): Pass __uint32_t to GET_HIGH_WORD.  Convert return
	value into a boolean.

Index: newlib/libm/common/s_signbit.c
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libm/common/s_signbit.c,v
retrieving revision 1.2
diff -u -3 -p -r1.2 s_signbit.c
--- newlib/libm/common/s_signbit.c	6 Apr 2009 17:07:23 -0000	1.2
+++ newlib/libm/common/s_signbit.c	18 Dec 2013 08:44:31 -0000
@@ -41,19 +41,19 @@ int __signbitd (double x);
 int
 __signbitf (float x)
 {
-  unsigned int w;
+  __uint32_t w;
 
   GET_FLOAT_WORD(w,x);
 
-  return (w & 0x80000000);
+  return (w & 0x80000000) != 0;
 }
 
 int
 __signbitd (double x)
 {
-  unsigned int msw;
+  __uint32_t msw;
 
   GET_HIGH_WORD(msw, x);
 
-  return (msw & 0x80000000);
+  return (msw & 0x80000000) != 0;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]