[Git][NTPsec/ntpsec][master] Replace grotty macro calls with cleaner code.

Eric S. Raymond gitlab at mg.gitlab.com
Mon Dec 26 19:48:31 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
0653897a by Eric S. Raymond at 2016-12-26T14:47:38-05:00
Replace grotty macro calls with cleaner code.

- - - - -


2 changed files:

- include/ntp_fp.h
- tests/libntp/lfpfunc.c


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -192,21 +192,10 @@ typedef uint32_t u_fp;
 	(((uint32_t)((a_i) ^ 0x80000000) > (uint32_t)((b_i) ^ 0x80000000)) || \
 	  ((a_i) == (b_i) && ((uint32_t)(a_f)) > ((uint32_t)(b_f))))
 
-#define	M_ISGTU(a_i, a_f, b_i, b_f)	/* a > b unsigned */ \
-	(((uint32_t)(a_i)) > ((uint32_t)(b_i)) || \
-	  ((a_i) == (b_i) && ((uint32_t)(a_f)) > ((uint32_t)(b_f))))
-
-#define	M_ISHIS(a_i, a_f, b_i, b_f)	/* a >= b unsigned */ \
-	(((uint32_t)(a_i)) > ((uint32_t)(b_i)) || \
-	  ((a_i) == (b_i) && ((uint32_t)(a_f)) >= ((uint32_t)(b_f))))
-
 #define	M_ISGEQ(a_i, a_f, b_i, b_f)	/* a >= b signed */ \
 	(((uint32_t)((a_i) ^ 0x80000000) > (uint32_t)((b_i) ^ 0x80000000)) || \
 	  ((a_i) == (b_i) && (uint32_t)(a_f) >= (uint32_t)(b_f)))
 
-#define	M_ISEQU(a_i, a_f, b_i, b_f)	/* a == b unsigned */ \
-	((uint32_t)(a_i) == (uint32_t)(b_i) && (uint32_t)(a_f) == (uint32_t)(b_f))
-
 /*
  * Operations on the long fp format
  * FIXME: Using lfpuint(x) as rvalue, this will fail when representation changes.
@@ -221,11 +210,10 @@ typedef uint32_t u_fp;
 #define	L_ISNEG(v)	M_ISNEG(lfpuint(*v))
 #define L_ISZERO(v)	((lfpuint(*v) | lfpfrac(*v)) == 0)
 #define	L_ISGT(a, b)	M_ISGT(lfpsint(*a), lfpfrac(*a), lfpsint(*b), lfpfrac(*b))
-#define	L_ISGTU(a, b)	M_ISGTU(lfpuint(*a), lfpfrac(*a), lfpuint(*b), lfpfrac(*b))
-#define	L_ISHIS(a, b)	M_ISHIS(lfpuint(*a), lfpfrac(*a), lfpuint(*b), lfpfrac(*b))
+#define	L_ISGTU(a, b)	(lfp_to_uint64(*a) > lfp_to_uint64(*b))
 #define	L_ISGEQ(a, b)	M_ISGEQ(lfpuint(*a), lfpfrac(*a), lfpuint(*b), lfpfrac(*b))
-#define L_ISGEQU(a, b)  L_ISHIS(a, b)
-#define	L_ISEQU(a, b)	M_ISEQU(lfpuint(*a), lfpfrac(*a), lfpuint(*b), lfpfrac(*b))
+#define L_ISGEQU(a, b)  (lfp_to_uint64(*a) >= lfp_to_uint64(*b))
+#define	L_ISEQU(a, b)	(lfp_to_uint64(*a) == lfp_to_uint64(*b))
 
 /*
  * s_fp/double and u_fp/double conversions


=====================================
tests/libntp/lfpfunc.c
=====================================
--- a/tests/libntp/lfpfunc.c
+++ b/tests/libntp/lfpfunc.c
@@ -172,9 +172,9 @@ static bool l_isgtu(const l_fp first, const l_fp second)
 	return L_ISGTU(&first, &second);
 }
 
-static bool l_ishis(const l_fp first, const l_fp second)
+static bool l_isgequ(const l_fp first, const l_fp second)
 {
-	return L_ISHIS(&first, &second);
+	return L_ISGEQU(&first, &second);
 }
 
 static bool l_isgeq(const l_fp first, const l_fp second)
@@ -450,15 +450,15 @@ TEST(lfpfunc, UnsignedRelOps) {
 			TEST_ASSERT_TRUE (l_isgtu(op1, op2));
 			TEST_ASSERT_FALSE(l_isgtu(op2, op1));
 
-			TEST_ASSERT_TRUE (l_ishis(op1, op2));
-			TEST_ASSERT_FALSE(l_ishis(op2, op1));
+			TEST_ASSERT_TRUE (l_isgequ(op1, op2));
+			TEST_ASSERT_FALSE(l_isgequ(op2, op1));
 			break;
 		case 0:
 			TEST_ASSERT_FALSE(l_isgtu(op1, op2));
 			TEST_ASSERT_FALSE(l_isgtu(op2, op1));
 
-			TEST_ASSERT_TRUE (l_ishis(op1, op2));
-			TEST_ASSERT_TRUE (l_ishis(op2, op1));
+			TEST_ASSERT_TRUE (l_isgequ(op1, op2));
+			TEST_ASSERT_TRUE (l_isgequ(op2, op1));
 			break;
 		default:
 			TEST_FAIL_MESSAGE("unexpected UCMP result: ");



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/0653897a059f0da54655ab56096254e3d1ac23ef
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161226/0d498a8d/attachment.html>


More information about the vc mailing list