Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/sys Implement __negative_p without floating-point arithm...
details: https://anonhg.NetBSD.org/src/rev/bda98696946f
branches: trunk
changeset: 789738:bda98696946f
user: gsutre <gsutre%NetBSD.org@localhost>
date: Thu Sep 05 21:00:15 2013 +0000
description:
Implement __negative_p without floating-point arithmetic, using
a solution proposed by jxh on Stack Overflow. Fixes the second
half of PR lib/48131.
While there, simplify __type_fit_u by using the same logic
as in __type_fit_s.
ok christos@
diffstat:
sys/sys/cdefs.h | 14 +++++---------
1 files changed, 5 insertions(+), 9 deletions(-)
diffs (36 lines):
diff -r 8e3683e6fe17 -r bda98696946f sys/sys/cdefs.h
--- a/sys/sys/cdefs.h Thu Sep 05 20:49:25 2013 +0000
+++ b/sys/sys/cdefs.h Thu Sep 05 21:00:15 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cdefs.h,v 1.108 2013/09/05 09:03:13 gsutre Exp $ */
+/* $NetBSD: cdefs.h,v 1.109 2013/09/05 21:00:15 gsutre Exp $ */
/*
* Copyright (c) 1991, 1993
@@ -553,13 +553,9 @@
#define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \
(~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL)
-#ifndef __ASSEMBLER__
-static __inline long long __zeroll(void) { return 0; }
-static __inline int __negative_p(double x) { return x < 0; }
-#else
#define __zeroll() (0LL)
-#define __negative_p(x) ((x) < 0)
-#endif
+#define __zeroull() (0ULL)
+#define __negative_p(x) (!((x) > 0) && ((x) != 0))
#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1))))
#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1))))
@@ -570,8 +566,8 @@
#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t))
-#define __type_fit_u(t, a) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \
- (((a) & __type_mask(t)) == 0) : !__negative_p(a))
+#define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \
+ (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t))
#define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \
((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \
Home |
Main Index |
Thread Index |
Old Index