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

Index Nav: Message Nav: [Date Index] [Subject Index] [Author Index] [Thread Index] [Date Prev] [Date Next] [Thread Prev] [Thread Next] [Raw text]

# Re: Algol Front end

• 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

Something like this for the 32-bit case?

int32_t
{
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

union uParts {
unsigned      iSum;
unsigned char b;
};

uParts   x;

unsigned carry;

unsigned result;

PACKED_DECIMAL_DIGIT pack1, pack2;

uParts const static sum[] = { 0x0000, ... };    // precomputed result of

x.iSum = sum[pack1 + pack1]

carry =  (unsigned) x.b;  // assuming that b has the carry.

result = (unsigned) x.b;  // assuming that b 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: Message Nav: [Date Index] [Subject Index] [Author Index] [Thread Index] [Date Prev] [Date Next] [Thread Prev] [Thread Next]