This is the mail archive of the
`gcc@gcc.gnu.org`
mailing list for the GCC project.

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |

Other format: | [Raw text] |

*From*: "Arthur I Schwarz" <Arthur_I_Schwarz at raytheon dot com>*To*: gcc at gcc dot gnu dot org*Date*: Wed, 8 May 2002 11:39:42 -0700*Subject*: Re: Algol Front end

dewar@gnat.com (Robert Dewar) writes: > Table lookup is not the way to go for packed decimal addition. > > Basically you want to do a standard addition, and then deal with the > carries. > > There are two cases of carries > > 1. Where there is a carry out of the four bits. Two subcases here > 100? + 100? => overflow, easily detected by an AND > > 1001 + 0111 (or vice versa), detectable by some sequence of > logical fiddling > > 2. Where the carry is within the four bits, i.e. the result is 11?? > or 101? (again detectable by some logical fiddling) > > That's as far as I have time to get right now, but starting from > this, you can figure out a series of logical operations to effect > the carry adjust. Something like this for the 32-bit case? int32_t add (int32_t x, int32_t y) { int32_t z = x + y; int32_t c; /* Carry out of the four bits, subcase 1. */ c = (x >> 3) & (y >> 3); /* Carry out of the four bits, subcase 2. */ c |= (x >> 3) & x & (y >> 2) & (y >> 1) & y; c |= (y >> 3) & y & (x >> 2) & (x >> 1) & x; /* Carry within the four bits. */ c |= (z >> 3) & ((z >> 2) | (z >> 1)); return z + 6 * (c & 0x11111111); } -- Lars Brinkhoff http://lars.nocrew.org/ Linux, GCC, PDP-10, Brinkhoff Consulting http://www.brinkhoff.se/ HTTP programming ------------------------------------------------------------------------------------- Thank you both. Not to belabor it but so that I better understand the issues, what about: union uParts { unsigned iSum; unsigned char b[2]; }; uParts x; unsigned carry; unsigned result; PACKED_DECIMAL_DIGIT pack1, pack2; uParts const static sum[] = { 0x0000, ... }; // precomputed result of addition x.iSum = sum[pack1 + pack1] carry = (unsigned) x.b[0]; // assuming that b[0] has the carry. result = (unsigned) x.b[1]; // assuming that b[1] contains the packed sum If this works I would assume that it takes less time and less space than the algorithmic solution. What I don't understand is what's wrong with the approach? It is unnecessary to execute an algorithm to detect carries and the resultant sum is always correct. All of the operations performed at run time algorithmically are performed off-line and stored in a table. At run time execution is truncated by indexing into an existing array containing precomputed results. So what am I missing? art

Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|

Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |