[PATCH] libm fixes for 16-bit targets

<[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Hi,

Attached are a couple of patches to libm to fix warnings when compiling for
16-bit targets.

The first in e_scalb.c calls scalbln instead of scalbn, as 65000 is out of
range for an 'int'.

+#if INT_MAX == 32767
+	if ( fn > 65000.0) return scalbln(x, 65000);
+	if (-fn > 65000.0) return scalbln(x,-65000);
+#else
 	if ( fn > 65000.0) return scalbn(x, 65000);
 	if (-fn > 65000.0) return scalbn(x,-65000);
+#endif

The second in math_config.h (issignalingf_inline) fixes the signed overflow
warning that occurs.

-  return 2 * (ix ^ 0x00400000) > 2u * 0x7fc00000;
+  return 2 * (ix ^ 0x00400000) > 0xFF800000u;

Although I hope I'm not missing something subtle with the mixing of the
types there.

Cheers,
Jon
0002-e_scalb.c-Call-scalbln-instead-of-scalbn-on-16-bit-t.patch (application/octet-stream, 884 B)
From 66caa00a1df8c92f400660679eb0cc83190e9097 Mon Sep 17 00:00:00 2001
From: Jon Beniston <[email protected]>
Date: Fri, 31 Aug 2018 22:42:29 +0100
Subject: [PATCH 2/3] e_scalb.c: Call scalbln instead of scalbn on 16-bit
 targets to ensure constant fits in an int.

---
 newlib/libm/math/e_scalb.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/newlib/libm/math/e_scalb.c b/newlib/libm/math/e_scalb.c
index 0bb924b43..4d8bb8b71 100644
--- a/newlib/libm/math/e_scalb.c
+++ b/newlib/libm/math/e_scalb.c
@@ -46,8 +46,13 @@
 	    else       return x/(-fn);
 	}
 	if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
+#if INT_MAX == 32767
+	if ( fn > 65000.0) return scalbln(x, 65000);
+	if (-fn > 65000.0) return scalbln(x,-65000);
+#else
 	if ( fn > 65000.0) return scalbn(x, 65000);
 	if (-fn > 65000.0) return scalbn(x,-65000);
+#endif
 	return scalbn(x,(int)fn);
 #endif
 }
-- 
2.17.0
0003-math_config.h-Fix-signed-overflow-warning-for-16-bit.patch (application/octet-stream, 804 B)
From 0022ed99969f0953845f678fb69cb778a3d15b8d Mon Sep 17 00:00:00 2001
From: Jon Beniston <[email protected]>
Date: Fri, 31 Aug 2018 23:10:00 +0100
Subject: [PATCH 3/3] math_config.h: Fix signed overflow warning for 16-bit
 targets

---
 newlib/libm/common/math_config.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/newlib/libm/common/math_config.h b/newlib/libm/common/math_config.h
index f28c52b00..dcbc61ae2 100644
--- a/newlib/libm/common/math_config.h
+++ b/newlib/libm/common/math_config.h
@@ -155,7 +155,7 @@ issignalingf_inline (float x)
   uint32_t ix = asuint (x);
   if (!IEEE_754_2008_SNAN)
     return (ix & 0x7fc00000) == 0x7fc00000;
-  return 2 * (ix ^ 0x00400000) > 2u * 0x7fc00000;
+  return 2 * (ix ^ 0x00400000) > 0xFF800000u;
 }
 
 static inline int
-- 
2.17.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.