diff options
Diffstat (limited to '')
-rw-r--r-- | compiler_and_linker/unsorted/CInt64.c (renamed from CInt64.c) | 393 |
1 files changed, 196 insertions, 197 deletions
diff --git a/CInt64.c b/compiler_and_linker/unsorted/CInt64.c index 9b793bd..ce2c45c 100644 --- a/CInt64.c +++ b/compiler_and_linker/unsorted/CInt64.c @@ -1,5 +1,4 @@ -#include <MacHeadersMach-O> -#include "CInt64.h" +#include "compiler/CInt64.h" const CInt64 cint64_negone = {0xFFFFFFFF, 0xFFFFFFFF}; const CInt64 cint64_zero = {0, 0}; @@ -14,9 +13,9 @@ void CInt64_Init() { CInt64 CInt64_Not(CInt64 input) { CInt64 output; - unsigned char c; + Boolean c; - c = (input.a == 0 && input.b == 0); + c = (input.hi == 0 && input.lo == 0); CInt64_SetLong(&output, c); return output; @@ -24,31 +23,31 @@ CInt64 CInt64_Not(CInt64 input) { CInt64 CInt64_Inv(CInt64 input) { CInt64 output; - output.a = ~input.a; - output.b = ~input.b; + output.hi = ~input.hi; + output.lo = ~input.lo; return output; } CInt64 CInt64_Add(CInt64 lhs, CInt64 rhs) { - if (lhs.b & 0x80000000) { - if (rhs.b & 0x80000000) { - lhs.b += rhs.b; - lhs.a += 1; + if (lhs.lo & 0x80000000) { + if (rhs.lo & 0x80000000) { + lhs.lo += rhs.lo; + lhs.hi += 1; } else { - lhs.b += rhs.b; - if (!(lhs.b & 0x80000000)) - lhs.a += 1; + lhs.lo += rhs.lo; + if (!(lhs.lo & 0x80000000)) + lhs.hi += 1; } } else { - if (rhs.b & 0x80000000) { - lhs.b += rhs.b; - if (!(lhs.b & 0x80000000)) - lhs.a += 1; + if (rhs.lo & 0x80000000) { + lhs.lo += rhs.lo; + if (!(lhs.lo & 0x80000000)) + lhs.hi += 1; } else { - lhs.b += rhs.b; + lhs.lo += rhs.lo; } } - lhs.a += rhs.a; + lhs.hi += rhs.hi; return lhs; } @@ -66,22 +65,22 @@ CInt64 CInt64_Sub(CInt64 lhs, CInt64 rhs) { CInt64 CInt64_MulU(CInt64 lhs, CInt64 rhs) { CInt64 result; CInt64 work1; - unsigned long aaaa; - unsigned long bbbb; - unsigned long cccc; - unsigned long dddd; - unsigned long eeee; - - aaaa = rhs.b; - result.a = result.b = 0; - bbbb = lhs.b; - cccc = rhs.a; - dddd = rhs.b; + UInt32 aaaa; + UInt32 bbbb; + UInt32 cccc; + UInt32 dddd; + UInt32 eeee; + + aaaa = rhs.lo; + result.hi = result.lo = 0; + bbbb = lhs.lo; + cccc = rhs.hi; + dddd = rhs.lo; while (bbbb != 0) { if (bbbb & 1) { - work1.a = cccc; - work1.b = dddd; + work1.hi = cccc; + work1.lo = dddd; result = CInt64_Add(result, work1); } cccc <<= 1; @@ -91,10 +90,10 @@ CInt64 CInt64_MulU(CInt64 lhs, CInt64 rhs) { bbbb >>= 1; } - eeee = lhs.a; + eeee = lhs.hi; while (eeee != 0 && aaaa != 0) { if (eeee & 1) - result.a += aaaa; + result.hi += aaaa; aaaa <<= 1; eeee >>= 1; } @@ -116,26 +115,26 @@ CInt64 CInt64_Mul(CInt64 lhs, CInt64 rhs) { } void CInt64_DivMod(const CInt64 *lhs, const CInt64 *rhs, CInt64 *pDiv, CInt64 *pMod) { - unsigned char bad; - unsigned long workA; - unsigned long workB; - unsigned long leftA; - unsigned long leftB; - unsigned long rightA; - unsigned long rightB; - unsigned long outA; - unsigned long outB; + Boolean bad; + UInt32 workA; + UInt32 workB; + UInt32 leftA; + UInt32 leftB; + UInt32 rightA; + UInt32 rightB; + UInt32 outA; + UInt32 outB; CInt64 work; int counter; - bad = (rhs->a == 0) && (rhs->b == 0); + bad = (rhs->hi == 0) && (rhs->lo == 0); if (!bad) { workA = 0; workB = 0; - leftA = lhs->a; - leftB = lhs->b; - rightA = rhs->a; - rightB = rhs->b; + leftA = lhs->hi; + leftB = lhs->lo; + rightA = rhs->hi; + rightB = rhs->lo; outA = 0; outB = 0; counter = 0; @@ -166,20 +165,20 @@ void CInt64_DivMod(const CInt64 *lhs, const CInt64 *rhs, CInt64 *pDiv, CInt64 *p outB |= 1; - work.a = workA; - work.b = workB; + work.hi = workA; + work.lo = workB; work = CInt64_Sub(work, *rhs); - workA = work.a; - workB = work.b; + workA = work.hi; + workB = work.lo; } while (++counter < 64); if (pDiv) { - pDiv->a = outA; - pDiv->b = outB; + pDiv->hi = outA; + pDiv->lo = outB; } if (pMod) { - pMod->a = workA; - pMod->b = workB; + pMod->hi = workA; + pMod->lo = workB; } } } @@ -238,50 +237,50 @@ CInt64 CInt64_ModU(CInt64 lhs, CInt64 rhs) { CInt64 CInt64_Shl(CInt64 lhs, CInt64 rhs) { int counter; - unsigned long a; - unsigned long b; + UInt32 a; + UInt32 b; - if (rhs.a == 0 && rhs.b < 64) { - a = lhs.a; - b = lhs.b; - for (counter = rhs.b; counter != 0; --counter) { + if (rhs.hi == 0 && rhs.lo < 64) { + a = lhs.hi; + b = lhs.lo; + for (counter = rhs.lo; counter != 0; --counter) { a <<= 1; if (b & 0x80000000) a |= 1; b <<= 1; } - lhs.a = a; - lhs.b = b; + lhs.hi = a; + lhs.lo = b; } else { - lhs.a = 0; - lhs.b = 0; + lhs.hi = 0; + lhs.lo = 0; } return lhs; } CInt64 CInt64_Shr(CInt64 lhs, CInt64 rhs) { int counter; - long a; - unsigned long b; + SInt32 a; + UInt32 b; - if (rhs.a == 0 && rhs.b < 64) { - a = lhs.a; - b = lhs.b; - for (counter = rhs.b; counter != 0; --counter) { + if (rhs.hi == 0 && rhs.lo < 64) { + a = lhs.hi; + b = lhs.lo; + for (counter = rhs.lo; counter != 0; --counter) { b >>= 1; if (a & 1) b |= 0x80000000; a >>= 1; } - lhs.a = a; - lhs.b = b; + lhs.hi = a; + lhs.lo = b; } else { - if (lhs.a & 0x80000000) { - lhs.a = 0xFFFFFFFF; - lhs.b = 0xFFFFFFFF; + if (lhs.hi & 0x80000000) { + lhs.hi = 0xFFFFFFFF; + lhs.lo = 0xFFFFFFFF; } else { - lhs.a = 0; - lhs.b = 0; + lhs.hi = 0; + lhs.lo = 0; } } return lhs; @@ -289,35 +288,35 @@ CInt64 CInt64_Shr(CInt64 lhs, CInt64 rhs) { CInt64 CInt64_ShrU(CInt64 lhs, CInt64 rhs) { int counter; - unsigned long a; - unsigned long b; + UInt32 a; + UInt32 b; - if (rhs.a == 0 && rhs.b < 64) { - a = lhs.a; - b = lhs.b; - for (counter = rhs.b; counter != 0; --counter) { + if (rhs.hi == 0 && rhs.lo < 64) { + a = lhs.hi; + b = lhs.lo; + for (counter = rhs.lo; counter != 0; --counter) { b >>= 1; if (a & 1) b |= 0x80000000; a >>= 1; } - lhs.a = a; - lhs.b = b; + lhs.hi = a; + lhs.lo = b; } else { - lhs.a = 0; - lhs.b = 0; + lhs.hi = 0; + lhs.lo = 0; } return lhs; } int CInt64_UnsignedCompare(const CInt64 *lhs, const CInt64 *rhs) { - if (lhs->a == rhs->a) { - if (lhs->b < rhs->b) + if (lhs->hi == rhs->hi) { + if (lhs->lo < rhs->lo) return -1; else - return lhs->b > rhs->b; + return lhs->lo > rhs->lo; } else { - return ((unsigned long) lhs->a < rhs->a) ? -1 : 1; + return ((UInt32) lhs->hi < rhs->hi) ? -1 : 1; } } @@ -330,62 +329,62 @@ int CInt64_SignedCompare(const CInt64 *lhs, const CInt64 *rhs) { return CInt64_UnsignedCompare(&lhs_, &rhs_); } -unsigned char CInt64_Less(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_Less(CInt64 lhs, CInt64 rhs) { return CInt64_SignedCompare(&lhs, &rhs) < 0; } -unsigned char CInt64_LessU(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_LessU(CInt64 lhs, CInt64 rhs) { return CInt64_UnsignedCompare(&lhs, &rhs) < 0; } -unsigned char CInt64_Greater(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_Greater(CInt64 lhs, CInt64 rhs) { return CInt64_SignedCompare(&lhs, &rhs) > 0; } -unsigned char CInt64_GreaterU(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_GreaterU(CInt64 lhs, CInt64 rhs) { return CInt64_UnsignedCompare(&lhs, &rhs) > 0; } -unsigned char CInt64_LessEqual(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_LessEqual(CInt64 lhs, CInt64 rhs) { return CInt64_SignedCompare(&lhs, &rhs) <= 0; } -unsigned char CInt64_LessEqualU(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_LessEqualU(CInt64 lhs, CInt64 rhs) { return CInt64_UnsignedCompare(&lhs, &rhs) <= 0; } -unsigned char CInt64_GreaterEqual(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_GreaterEqual(CInt64 lhs, CInt64 rhs) { return CInt64_SignedCompare(&lhs, &rhs) >= 0; } -unsigned char CInt64_GreaterEqualU(CInt64 lhs, CInt64 rhs) { +Boolean CInt64_GreaterEqualU(CInt64 lhs, CInt64 rhs) { return CInt64_UnsignedCompare(&lhs, &rhs) >= 0; } -unsigned char CInt64_Equal(CInt64 lhs, CInt64 rhs) { - return lhs.a == rhs.a && lhs.b == rhs.b; +Boolean CInt64_Equal(CInt64 lhs, CInt64 rhs) { + return lhs.hi == rhs.hi && lhs.lo == rhs.lo; } -unsigned char CInt64_NotEqual(CInt64 lhs, CInt64 rhs) { - return lhs.a != rhs.a || lhs.b != rhs.b; +Boolean CInt64_NotEqual(CInt64 lhs, CInt64 rhs) { + return lhs.hi != rhs.hi || lhs.lo != rhs.lo; } -unsigned char CInt64_IsInRange(CInt64 value, short len) { +Boolean CInt64_IsInRange(CInt64 value, short len) { CInt64 bound; - if (value.a & 0x80000000) { + if (value.hi & 0x80000000) { switch (len) { case 1: - bound.b = 0xFFFFFF80; - bound.a = 0xFFFFFFFF; + bound.lo = 0xFFFFFF80; + bound.hi = 0xFFFFFFFF; break; case 2: - bound.b = 0xFFFF8000; - bound.a = 0xFFFFFFFF; + bound.lo = 0xFFFF8000; + bound.hi = 0xFFFFFFFF; break; case 4: - bound.b = 0x80000000; - bound.a = 0xFFFFFFFF; + bound.lo = 0x80000000; + bound.hi = 0xFFFFFFFF; break; case 8: return 1; @@ -396,16 +395,16 @@ unsigned char CInt64_IsInRange(CInt64 value, short len) { } else { switch (len) { case 1: - bound.b = 0x7F; - bound.a = 0; + bound.lo = 0x7F; + bound.hi = 0; break; case 2: - bound.b = 0x7FFF; - bound.a = 0; + bound.lo = 0x7FFF; + bound.hi = 0; break; case 4: - bound.b = 0x7FFFFFFF; - bound.a = 0; + bound.lo = 0x7FFFFFFF; + bound.hi = 0; break; case 8: return 1; @@ -416,14 +415,14 @@ unsigned char CInt64_IsInRange(CInt64 value, short len) { } } -unsigned char CInt64_IsInURange(CInt64 value, short len) { +Boolean CInt64_IsInURange(CInt64 value, short len) { switch (len) { case 1: - return value.a == 0 && (value.b & 0xFFFFFF00) == 0; + return value.hi == 0 && (value.lo & 0xFFFFFF00) == 0; case 2: - return value.a == 0 && (value.b & 0xFFFF0000) == 0; + return value.hi == 0 && (value.lo & 0xFFFF0000) == 0; case 4: - return value.a == 0; + return value.hi == 0; case 8: return 1; default: @@ -432,20 +431,20 @@ unsigned char CInt64_IsInURange(CInt64 value, short len) { } CInt64 CInt64_And(CInt64 lhs, CInt64 rhs) { - lhs.a &= rhs.a; - lhs.b &= rhs.b; + lhs.hi &= rhs.hi; + lhs.lo &= rhs.lo; return lhs; } CInt64 CInt64_Xor(CInt64 lhs, CInt64 rhs) { - lhs.a ^= rhs.a; - lhs.b ^= rhs.b; + lhs.hi ^= rhs.hi; + lhs.lo ^= rhs.lo; return lhs; } CInt64 CInt64_Or(CInt64 lhs, CInt64 rhs) { - lhs.a |= rhs.a; - lhs.b |= rhs.b; + lhs.hi |= rhs.hi; + lhs.lo |= rhs.lo; return lhs; } @@ -454,43 +453,43 @@ void CInt64_ConvertInt32(CInt64 *i) { } void CInt64_ConvertUInt32(CInt64 *i) { - CInt64_SetULong(i, (unsigned long) i->b); + CInt64_SetULong(i, (UInt32) i->lo); } void CInt64_ConvertInt16(CInt64 *i) { - i->b = (short) i->b; + i->lo = (SInt32) i->lo; CInt64_Extend32(i); } void CInt64_ConvertUInt16(CInt64 *i) { - CInt64_SetULong(i, (unsigned short) i->b); + CInt64_SetULong(i, (UInt16) i->lo); } void CInt64_ConvertInt8(CInt64 *i) { - i->b = (char) i->b; + i->lo = (SInt8) i->lo; CInt64_Extend32(i); } void CInt64_ConvertUInt8(CInt64 *i) { - CInt64_SetULong(i, (unsigned char) i->b); + CInt64_SetULong(i, (UInt8) i->lo); } void CInt64_ConvertUFromLongDouble(CInt64 *pResult, double value) { - union { float f; unsigned long l; } cvt; - unsigned long a, b; + union { float f; UInt32 l; } cvt; + UInt32 a, b; float threshold; int bits; if (value <= 0.0) { - pResult->a = 0; - pResult->b = 0; + pResult->hi = 0; + pResult->lo = 0; return; } cvt.l = 0x5F800000; if (value >= cvt.f) { - pResult->a = 0xFFFFFFFF; - pResult->b = 0xFFFFFFFF; + pResult->hi = 0xFFFFFFFF; + pResult->lo = 0xFFFFFFFF; return; } @@ -514,8 +513,8 @@ void CInt64_ConvertUFromLongDouble(CInt64 *pResult, double value) { } } - pResult->a = a; - pResult->b = b; + pResult->hi = a; + pResult->lo = b; } void CInt64_ConvertFromLongDouble(CInt64 *pResult, double value) { @@ -528,18 +527,18 @@ void CInt64_ConvertFromLongDouble(CInt64 *pResult, double value) { } double CInt64_ConvertUToLongDouble(const CInt64 *value) { - unsigned char bad; - unsigned long work; + Boolean bad; + UInt32 work; int counter; double result; - bad = (value->a == 0) && (value->b == 0); + bad = (value->hi == 0) && (value->lo == 0); if (bad) { return 0.0; } else { result = 0.0; - work = value->a; + work = value->hi; if (work != 0) { for (counter = 0; counter < 32; counter++) { result += result; @@ -550,7 +549,7 @@ double CInt64_ConvertUToLongDouble(const CInt64 *value) { } counter = 0; - work = value->b; + work = value->lo; for (; counter < 32; counter++) { result += result; if (work & 0x80000000) @@ -564,7 +563,7 @@ double CInt64_ConvertUToLongDouble(const CInt64 *value) { double CInt64_ConvertToLongDouble(const CInt64 *value) { CInt64 tmp; - if (value->a & 0x80000000) { + if (value->hi & 0x80000000) { tmp = CInt64_Neg(*value); return -CInt64_ConvertUToLongDouble(&tmp); } else { @@ -572,18 +571,18 @@ double CInt64_ConvertToLongDouble(const CInt64 *value) { } } -char *CInt64_ScanOctString(CInt64 *pResult, char *str, unsigned char *pFail) { +char *CInt64_ScanOctString(CInt64 *pResult, char *str, Boolean *pFail) { int ch; CInt64 tmp; - unsigned long a; - unsigned long b; + UInt32 a; + UInt32 b; *pFail = 0; - pResult->a = pResult->b = 0; + pResult->hi = pResult->lo = 0; while ((ch = *str) >= '0' && *str <= '7') { - a = pResult->a; - b = pResult->b; + a = pResult->hi; + b = pResult->lo; if (a & 0xE0000000) *pFail = 1; @@ -591,8 +590,8 @@ char *CInt64_ScanOctString(CInt64 *pResult, char *str, unsigned char *pFail) { SHIFT_LEFT_ONE(a, b); SHIFT_LEFT_ONE(a, b); - pResult->a = a; - pResult->b = b; + pResult->hi = a; + pResult->lo = b; CInt64_SetLong(&tmp, ch - '0'); *pResult = CInt64_Add(*pResult, tmp); @@ -602,28 +601,28 @@ char *CInt64_ScanOctString(CInt64 *pResult, char *str, unsigned char *pFail) { return str; } -char *CInt64_ScanDecString(CInt64 *pResult, char *str, unsigned char *pFail) { +char *CInt64_ScanDecString(CInt64 *pResult, char *str, Boolean *pFail) { int ch; CInt64 tmp; - unsigned long a; - unsigned long b; + UInt32 a; + UInt32 b; *pFail = 0; - pResult->a = pResult->b = 0; + pResult->hi = pResult->lo = 0; while ((ch = *str) >= '0' && *str <= '9') { - a = pResult->a; - b = pResult->b; + a = pResult->hi; + b = pResult->lo; if (a & 0xE0000000) *pFail = 1; SHIFT_LEFT_ONE(a, b); - tmp.a = a; - tmp.b = b; + tmp.hi = a; + tmp.lo = b; SHIFT_LEFT_ONE(a, b); SHIFT_LEFT_ONE(a, b); - pResult->a = a; - pResult->b = b; + pResult->hi = a; + pResult->lo = b; if (CInt64_IsNegative(pResult)) { *pResult = CInt64_Add(*pResult, tmp); @@ -648,15 +647,15 @@ char *CInt64_ScanDecString(CInt64 *pResult, char *str, unsigned char *pFail) { return str; } -char *CInt64_ScanHexString(CInt64 *pResult, char *str, unsigned char *pFail) { +char *CInt64_ScanHexString(CInt64 *pResult, char *str, Boolean *pFail) { /* NOT MATCHING */ int digit; CInt64 tmp; - unsigned long a; - unsigned long b; + UInt32 a; + UInt32 b; *pFail = 0; - pResult->a = pResult->b = 0; + pResult->hi = pResult->lo = 0; for (;;) { if ((digit = str[0]) >= '0' && digit <= '9') @@ -668,8 +667,8 @@ char *CInt64_ScanHexString(CInt64 *pResult, char *str, unsigned char *pFail) { else break; - a = pResult->a; - b = pResult->b; + a = pResult->hi; + b = pResult->lo; ++str; if (a & 0xF0000000) @@ -680,8 +679,8 @@ char *CInt64_ScanHexString(CInt64 *pResult, char *str, unsigned char *pFail) { SHIFT_LEFT_ONE(a, b); SHIFT_LEFT_ONE(a, b); - pResult->a = a; - pResult->b = b; + pResult->hi = a; + pResult->lo = b; CInt64_SetLong(&tmp, (char) digit); *pResult = CInt64_Add(*pResult, tmp); @@ -690,13 +689,13 @@ char *CInt64_ScanHexString(CInt64 *pResult, char *str, unsigned char *pFail) { return str; } -char *CInt64_ScanBinString(CInt64 *pResult, char *str, unsigned char *pFail) { +char *CInt64_ScanBinString(CInt64 *pResult, char *str, Boolean *pFail) { char digit; - unsigned long a; - unsigned long b; + UInt32 a; + UInt32 b; *pFail = 0; - pResult->a = pResult->b = 0; + pResult->hi = pResult->lo = 0; for (;;) { if (*str == '0') @@ -706,8 +705,8 @@ char *CInt64_ScanBinString(CInt64 *pResult, char *str, unsigned char *pFail) { else break; - a = pResult->a; - b = pResult->b; + a = pResult->hi; + b = pResult->lo; ++str; if (a & 0x80000000) @@ -715,8 +714,8 @@ char *CInt64_ScanBinString(CInt64 *pResult, char *str, unsigned char *pFail) { SHIFT_LEFT_ONE(a, b); - pResult->a = a; - pResult->b = b; + pResult->hi = a; + pResult->lo = b; if (digit == 1) *pResult = CInt64_Add(*pResult, cint64_one); @@ -725,11 +724,11 @@ char *CInt64_ScanBinString(CInt64 *pResult, char *str, unsigned char *pFail) { return str; } -char *CInt64_ScanAsmNumber(CInt64 *pResult, char *str, unsigned char *pFail) { - unsigned char isMaybeBin; - unsigned char isOct; - unsigned char isMaybeDec; - unsigned char isBin; +char *CInt64_ScanAsmNumber(CInt64 *pResult, char *str, Boolean *pFail) { + Boolean isMaybeBin; + Boolean isOct; + Boolean isMaybeDec; + Boolean isBin; char *p; isMaybeBin = 1; @@ -794,13 +793,13 @@ int CInt64_PrintDec(char *output, CInt64 value) { } if (!CInt64_IsZero(&value)) { - divisor.b = 10; - divisor.a = 0; + divisor.lo = 10; + divisor.hi = 0; bufp = buf; for (;;) { rem = CInt64_ModU(value, divisor); - *(bufp++) = rem.b + '0'; + *(bufp++) = rem.lo + '0'; value = CInt64_DivU(value, divisor); if (CInt64_IsZero(&value) != 0) break; @@ -829,18 +828,18 @@ int CInt64_PrintHex(char *output, CInt64 value) { length = 0; if (!CInt64_IsZero(&value)) { - shift.b = 4; - shift.a = 0; - mask.b = 0xF; - mask.a = 0; + shift.lo = 4; + shift.hi = 0; + mask.lo = 0xF; + mask.hi = 0; bufp = buf; for (;;) { rem = CInt64_And(value, mask); - if ((long) rem.b >= 10) - *(bufp++) = rem.b + 'A'; + if ((SInt32) rem.lo >= 10) + *(bufp++) = rem.lo + 'A'; else - *(bufp++) = rem.b + '0'; + *(bufp++) = rem.lo + '0'; value = CInt64_ShrU(value, shift); if (CInt64_IsZero(&value) != 0) break; |