This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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]

soft-fp: fix floating-point to integer unsigned saturation


The soft-fp macro _FP_TO_INT is supposed to saturate its result for
out-of-range arguments.  But in the case of unsigned saturation, it
mistakenly produces 0 for positive results and ~0 for negative ones,
the reverse of correct unsigned saturation.  This patch fixes the
logic to be as intended.  (In C terms for glibc/libgcc semantics, the
value chosen is of course arbitrary, but this is relevant for
instruction emulation in the Linux kernel, where I've submitted the
corresponding patch <http://lkml.org/lkml/2013/10/8/694>, and
divergence between the two versions is generally undesirable.)

Tested for powerpc-nofpu.

2013-10-09  Joseph Myers  <joseph@codesourcery.com>

	* soft-fp/op-common.h (_FP_TO_INT): Reverse test of sign for
	computing saturated result for unsigned overflow.

diff --git a/soft-fp/op-common.h b/soft-fp/op-common.h
index bed1e21..e7d58d1 100644
--- a/soft-fp/op-common.h
+++ b/soft-fp/op-common.h
@@ -1286,7 +1286,7 @@ do {									\
 	  r -= 1 - X##_s;						\
 	} else {							\
 	  r = 0;							\
-	  if (X##_s)							\
+	  if (!X##_s)							\
 	    r = ~r;							\
 	}								\
 									\

-- 
Joseph S. Myers
joseph@codesourcery.com


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