Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!pyramid!prls!mips!earl From: earl@mips.COM (Earl Killian) Newsgroups: comp.arch Subject: Re: More than 32 bits needed where? Message-ID: <1638@gumby.mips.COM> Date: 20 Feb 88 02:34:30 GMT References: <235@unicom.UUCP> <28200089@ccvaxa> <3104@watcgl.waterloo.edu> <3671@diku.dk> Lines: 40 In article <3671@diku.dk>, keld@diku.dk (Keld J|rn Simonsen) writes: > There is a problem with C that long ints are usually not more > than 32 bits, even if the hardware is capable of doing 64 bits > adds and subtracts. This I foresee to cause severe problems for > C-based accounting software! Comments? Actually, it's trivial to do some 64-bit arithmetic in C today. However, lest I appear to be arguing against 64-bit support, let me first say that, in my opinion, every architecture designed after the early 90s will be a 64-bit architecture. Even PCs will probably use 64-bit architectures by the end of the 90s. 64 bit addresses and integers are too important. Anyway, here are some macros that I use for doing 64-bit addition and subtraction in C. People commonly assume you need to use an add with carry instruction to do this stuff, which is not so. All you need is an unsigned comparison. 64-bit multiply/divide are the ones that can't be done trivially in C. /* dw.h */ typedef unsigned dw[2]; #define ZERO(_dw) \ {_dw[0] = 0; _dw[1] = 0;} #define INC1(_dw) \ {_dw[0] += 1; if (_dw[0] == 0) _dw[1] += 1;} #define INC(_dw, _i) \ {_dw[0] += _i; if (_dw[0] < (unsigned)_i) _dw[1] += 1;} /* be careful that _a is not the same location as _c in the following */ #define ADD(_a, _b, _c) \ {_a[0] = _b[0] + _c[0]; _a[1] = _b[1] + _c[1] + (_a[0] < _c[0]);} #define SUB(_a, _b, _c) \ {register unsigned _borrow = (_b[0] < _c[0]); _a[0] = _b[0] - _c[0]; _a[1] = _b[1] - _c[1] - _borrow;} #define DOUBLE(_dw) \ ((double)_dw[0] + (double)_dw[1] * 4294967296.0)