Always use unsigned long in lang/cem

Same reason as commit 649410b.
This commit is contained in:
George Koehler 2017-10-29 17:01:29 -04:00
parent 3d6ee435cf
commit 1ab1306baa
4 changed files with 12 additions and 150 deletions

View file

@ -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

View file

@ -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

View file

@ -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;

View file

@ -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;