From 1ab1306baa4eba19b42ceb208b1ae18bb899c352 Mon Sep 17 00:00:00 2001 From: George Koehler Date: Sun, 29 Oct 2017 17:01:29 -0400 Subject: [PATCH] Always use unsigned long in lang/cem Same reason as commit 649410b. --- lang/cem/cemcom.ansi/BigPars | 1 - lang/cem/cemcom.ansi/SmallPars | 1 - lang/cem/cemcom.ansi/cstoper.c | 86 ++++------------------------------ lang/cem/cpp.ansi/ch3bin.c | 74 ++--------------------------- 4 files changed, 12 insertions(+), 150 deletions(-) diff --git a/lang/cem/cemcom.ansi/BigPars b/lang/cem/cemcom.ansi/BigPars index fa9f30c9f..e3fad8296 100644 --- a/lang/cem/cemcom.ansi/BigPars +++ b/lang/cem/cemcom.ansi/BigPars @@ -122,7 +122,6 @@ !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ -/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */ !File: static.h diff --git a/lang/cem/cemcom.ansi/SmallPars b/lang/cem/cemcom.ansi/SmallPars index 237fd4dd0..3e3d00d98 100644 --- a/lang/cem/cemcom.ansi/SmallPars +++ b/lang/cem/cemcom.ansi/SmallPars @@ -122,7 +122,6 @@ !File: spec_arith.h /* describes internal compiler arithmetics */ #undef SPECIAL_ARITHMETICS /* something different from native long */ -/*#define UNSIGNED_ARITH unsigned arith /* if it is supported */ !File: static.h diff --git a/lang/cem/cemcom.ansi/cstoper.c b/lang/cem/cemcom.ansi/cstoper.c index ac11c2ca9..f904d9180 100644 --- a/lang/cem/cemcom.ansi/cstoper.c +++ b/lang/cem/cemcom.ansi/cstoper.c @@ -47,39 +47,8 @@ cstbin(expp, oper, expr) expr_warning(expr, "division by 0"); break; } - if (uns) { -#ifdef UNSIGNED_ARITH - o1 /= (UNSIGNED_ARITH) o2; -#else - /* this is more of a problem than you might - think on C compilers which do not have - unsigned arith (== long (probably)). - */ - if (o2 & arith_sign) {/* o2 > max_arith */ - o1 = ! (o1 >= 0 || o1 < o2); - /* this is the unsigned test - o1 < o2 for o2 > max_arith - */ - } - else { /* o2 <= max_arith */ - arith half, bit, hdiv, hrem, rem; - - half = (o1 >> 1) & ~arith_sign; - bit = o1 & 01; - /* now o1 == 2 * half + bit - and half <= max_arith - and bit <= max_arith - */ - hdiv = half / o2; - hrem = half % o2; - rem = 2 * hrem + bit; - o1 = 2 * hdiv + (rem < 0 || rem >= o2); - /* that is the unsigned compare - rem >= o2 for o2 <= max_arith - */ - } -#endif - } + if (uns) + o1 /= (unsigned arith) o2; else o1 /= o2; break; @@ -91,31 +60,8 @@ cstbin(expp, oper, expr) expr_warning(expr, "modulo by 0"); break; } - if (uns) { -#ifdef UNSIGNED_ARITH - o1 %= (UNSIGNED_ARITH) o2; -#else - if (o2 & arith_sign) {/* o2 > max_arith */ - o1 = (o1 >= 0 || o1 < o2) ? o1 : o1 - o2; - /* this is the unsigned test - o1 < o2 for o2 > max_arith - */ - } - else { /* o2 <= max_arith */ - arith half, bit, hrem, rem; - - half = (o1 >> 1) & ~arith_sign; - bit = o1 & 01; - /* now o1 == 2 * half + bit - and half <= max_arith - and bit <= max_arith - */ - hrem = half % o2; - rem = 2 * hrem + bit; - o1 = (rem < 0 || rem >= o2) ? rem - o2 : rem; - } -#endif - } + if (uns) + o1 %= (unsigned arith) o2; else o1 %= o2; break; @@ -146,16 +92,8 @@ cstbin(expp, oper, expr) } /* Fall through */ case '>': - if (uns) { -#ifdef UNSIGNED_ARITH - o1 = (UNSIGNED_ARITH) o1 > (UNSIGNED_ARITH) o2; -#else - o1 = (o1 & arith_sign ? - (o2 & arith_sign ? o1 > o2 : 1) : - (o2 & arith_sign ? 0 : o1 > o2) - ); -#endif - } + if (uns) + o1 = (unsigned arith) o1 > (unsigned arith) o2; else o1 = o1 > o2; break; @@ -168,16 +106,8 @@ cstbin(expp, oper, expr) } /* Fall through */ case GREATEREQ: - if (uns) { -#ifdef UNSIGNED_ARITH - o1 = (UNSIGNED_ARITH) o1 >= (UNSIGNED_ARITH) o2; -#else - o1 = (o1 & arith_sign ? - (o2 & arith_sign ? o1 >= o2 : 1) : - (o2 & arith_sign ? 0 : o1 >= o2) - ); -#endif - } + if (uns) + o1 = (unsigned arith) o1 >= (unsigned arith) o2; else o1 = o1 >= o2; break; diff --git a/lang/cem/cpp.ansi/ch3bin.c b/lang/cem/cpp.ansi/ch3bin.c index e85457e7a..f9f43cfbf 100644 --- a/lang/cem/cpp.ansi/ch3bin.c +++ b/lang/cem/cpp.ansi/ch3bin.c @@ -22,37 +22,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns) break; } if (*pis_uns) { -#ifdef UNSIGNED_ARITH - *pval /= (UNSIGNED_ARITH) val; -#else - /* this is more of a problem than you might - think on C compilers which do not have - unsigned arith (== long (probably)). - */ - if (val & arith_sign) {/* val > max_arith */ - *pval = ! (*pval >= 0 || *pval < val); - /* this is the unsigned test - *pval < val for val > max_arith - */ - } - else { /* val <= max_arith */ - arith half, bit, hdiv, hrem, rem; - - half = (*pval >> 1) & ~arith_sign; - bit = *pval & 01; - /* now *pval == 2 * half + bit - and half <= max_arith - and bit <= max_arith - */ - hdiv = half / val; - hrem = half % val; - rem = 2 * hrem + bit; - *pval = 2 * hdiv + (rem < 0 || rem >= val); - /* that is the unsigned compare - rem >= val for val <= max_arith - */ - } -#endif + *pval /= (unsigned arith) val; } else { *pval = *pval / val; @@ -64,29 +34,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns) break; } if (*pis_uns) { -#ifdef UNSIGNED_ARITH - *pval %= (UNSIGNED_ARITH) val; -#else - if (val & arith_sign) {/* val > max_arith */ - *pval = (*pval >= 0 || *pval < val) ? *pval : *pval - val; - /* this is the unsigned test - *pval < val for val > max_arith - */ - } - else { /* val <= max_arith */ - arith half, bit, hrem, rem; - - half = (*pval >> 1) & ~arith_sign; - bit = *pval & 01; - /* now *pval == 2 * half + bit - and half <= max_arith - and bit <= max_arith - */ - hrem = half % val; - rem = 2 * hrem + bit; - *pval = (rem < 0 || rem >= val) ? rem - val : rem; - } -#endif + *pval %= (unsigned arith) val; } else { *pval = *pval % val; @@ -117,14 +65,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns) /* fall through */ case '>': if (*pis_uns) { -#ifdef UNSIGNED_ARITH - *pval = (UNSIGNED_ARITH) *pval > (UNSIGNED_ARITH) val; -#else - *pval = (*pval & arith_sign ? - (val & arith_sign ? *pval > val : 1) : - (val & arith_sign ? 0 : *pval > val) - ); -#endif + *pval = (unsigned arith) *pval > (unsigned arith) val; } else *pval = (*pval > val); break; @@ -133,14 +74,7 @@ ch3bin(pval, pis_uns, oper, val, is_uns) /* fall through */ case GREATEREQ: if (*pis_uns) { -#ifdef UNSIGNED_ARITH - *pval = (UNSIGNED_ARITH) *pval >= (UNSIGNED_ARITH) val; -#else - *pval = (*pval & arith_sign ? - (val & arith_sign ? *pval >= val : 1) : - (val & arith_sign ? 0 : *pval >= val) - ); -#endif + *pval = (unsigned arith) *pval >= (unsigned arith) val; } else *pval = (*pval >= val); break;