Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

Science is what happens when preconception meets verification.


devel / comp.arch / Re: How is decimal arithmetic actually performed?

SubjectAuthor
* How is decimal arithmetic actually performed?Thomas Koenig
+- Re: How is decimal arithmetic actually performed?BGB
+- Re: How is decimal arithmetic actually performed?MitchAlsup1
+- Re: How is decimal arithmetic actually performed?John Levine
+- Re: How is decimal arithmetic actually performed?Quadibloc
`- Re: How is decimal arithmetic actually performed?Scott Lurndal

1
How is decimal arithmetic actually performed?

<up66n0$38fvr$1@newsreader4.netcologne.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=37140&group=comp.arch#37140

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!news.chmurka.net!news.szaf.org!3.eu.feeder.erje.net!feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2a0a-a540-3e2c-0-bb72-8a7f-ea47-95b7.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.arch
Subject: How is decimal arithmetic actually performed?
Date: Sun, 28 Jan 2024 18:34:08 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <up66n0$38fvr$1@newsreader4.netcologne.de>
Injection-Date: Sun, 28 Jan 2024 18:34:08 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2a0a-a540-3e2c-0-bb72-8a7f-ea47-95b7.ipv6dyn.netcologne.de:2a0a:a540:3e2c:0:bb72:8a7f:ea47:95b7";
logging-data="3424251"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Sun, 28 Jan 2024 18:34 UTC

How do computers nowadays actually perform decimal arithmetic,
and how did they do it in the past?

For adding, the first microprocessors used the "if the result of
A+B is larger than nine, then add six to the result and set carry"
method. If one wanted to speed this up with today's possibilities,
then the two additions could be done in parallel, with the carry
of A+B+6 selecting the result. This could then be integrated into
a conditional sum adder. If A+B+6 could be calculated efficiently
with a modified carry lookahead method, this method could work well.

For multiplication... I am not sure that the method outlined above
for addition would be efficient.

My (uninformed) guess would be that people would re-encode the BCD
numbers to something with different weights than the traditional
8-4-2-1 (maybe 4-2-2-1) and then make modified Wallace or Dadda
trees, which would deliver the indificual digits in that encoding,
from which they could then be converted to BCD or another format
as desired.

Does anybody know how this is actually done?

Re: How is decimal arithmetic actually performed?

<up6c2o$2lt2$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=37143&group=comp.arch#37143

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: cr88192@gmail.com (BGB)
Newsgroups: comp.arch
Subject: Re: How is decimal arithmetic actually performed?
Date: Sun, 28 Jan 2024 14:05:40 -0600
Organization: A noiseless patient Spider
Lines: 117
Message-ID: <up6c2o$2lt2$1@dont-email.me>
References: <up66n0$38fvr$1@newsreader4.netcologne.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 28 Jan 2024 20:05:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="771232ff2909cdba78ba264eb936eee4";
logging-data="87970"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18W9iD/yxXCjlA01/eI+piB"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:uncGh23g07pJX+kci0bw8pVpAgQ=
In-Reply-To: <up66n0$38fvr$1@newsreader4.netcologne.de>
Content-Language: en-US
 by: BGB - Sun, 28 Jan 2024 20:05 UTC

On 1/28/2024 12:34 PM, Thomas Koenig wrote:
> How do computers nowadays actually perform decimal arithmetic,
> and how did they do it in the past?
>
> For adding, the first microprocessors used the "if the result of
> A+B is larger than nine, then add six to the result and set carry"
> method. If one wanted to speed this up with today's possibilities,
> then the two additions could be done in parallel, with the carry
> of A+B+6 selecting the result. This could then be integrated into
> a conditional sum adder. If A+B+6 could be calculated efficiently
> with a modified carry lookahead method, this method could work well.
>
> For multiplication... I am not sure that the method outlined above
> for addition would be efficient.
>
> My (uninformed) guess would be that people would re-encode the BCD
> numbers to something with different weights than the traditional
> 8-4-2-1 (maybe 4-2-2-1) and then make modified Wallace or Dadda
> trees, which would deliver the indificual digits in that encoding,
> from which they could then be converted to BCD or another format
> as desired.
>
> Does anybody know how this is actually done?

Dunno about others, but I had experimentally implemented it as:
BCDADC/BCDSBB instructions, which add a group of 16 BCD digits in 64
bits, using SR.T as a CarryIn/CarryOut flag.

For each digit, IIRC:
First do a 4-bit add with a carry in/out;
If result was > 9 (res[3]&((res[2]|res[1]))),
Subtract 10 from result, and set carry.
Then chain 16 of these units together to form a full-width BCD adder.

The BCDSBB logic was similar, just adding a lookup table on the input
side to complement the value.

Say:
If SBB=0, RHS digit passed in as-is;
If SBB=1, RHS digit is complemented, carry-in is inverted.

For multiply, IIRC (in software):
Could use shift-and-add, just using a BCD adder.
For divide, IIRC:
Could use shift-and-subtract, just using a BCD subtract.

Multiplying/dividing by a power of 10 can be done with a plain shift.

I have a vague memory of naive shift-add happening to still work with
BCD, provided the BCD operations were still used for the main ADD/SUB
part (rather than needing to resort to a more complex long-division
algorithm). I suspect that the factor is that each multiple of 4 bits
happens to map exactly to a power of 10, and each group of 4 bits
doesn't go outside of the allowed range.

Not sure of a full hardware multiplier, I didn't implement one for BCD.

There was the nifty trick that one could do fastish binary to decimal:
Rotate-with-carry-left the binary value by 1 bit;
Do a BCDADC with the value of itself (adds the bit from the binary value);
Repeat for each bit of the input value.

For signed values, had used a wonky/modified version of 9s complement.
Top digit:
0..7: Positive
8/9: Negative
But, otherwise the same.

This variant mostly added the property that normal integer comparisons
could be used on the values, and would still give the same relative
ordering.

IIRC, there were also some ops to pack/unpack DPD values (DPD being
wonky, but not too difficult for hardware to pack/unpack).

I think my thinking was that with BCD, this minimized the amount of
"additional" logic needed to support BCD (could add BCDADC/BCDSBB, and
pretty much everything else could still leverage normal integer
instructions).

But, practically, not a whole lot of use-case for BCD in the stuff I am
doing...

Say, I am not imagining embedded/DSP style use-cases are going to have
much use for BCD or decimal arithmetic.

I guess one other possible scheme could be do add a version of decimal
math where, say, each group of 10 bits is understood as a value between
000 and 999, with each 64-bit register understood to hold 18 or 19
decimal digits (top 4 bits being special).

Multiplying/dividing would be a bit more complicated (I don't imagine
shift/add or shift/subtract will give the desired results). Would likely
need to use a form of (mod 1000) long multiply and long division.

To make this effective, the hardware support would need to be a bit more
involved, with special instructions needed to help facilitate multiply
and similar, etc. Vs just being able to get along entirely with ADD/SUB
helpers.

There is also the 30-bit 000000000..999999999 scheme, but this makes
more sense for a plain software implementation (can mostly leverage
normal integer operations without too much overhead). Would be less
viable for direct hardware support.

....

Re: How is decimal arithmetic actually performed?

<b748b2a0ce93a0e5f7ff92eda064ba85@www.novabbs.org>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=37144&group=comp.arch#37144

  copy link   Newsgroups: comp.arch
Date: Sun, 28 Jan 2024 21:04:58 +0000
Subject: Re: How is decimal arithmetic actually performed?
From: mitchalsup@aol.com (MitchAlsup1)
Newsgroups: comp.arch
X-Rslight-Site: $2y$10$2Y8KQ/x3jxE4gGr7bG/dCONSwqLxg2u3N4RXOlZN7MXvz4/.DypR.
X-Rslight-Posting-User: ac58ceb75ea22753186dae54d967fed894c3dce8
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
User-Agent: Rocksolid Light
References: <up66n0$38fvr$1@newsreader4.netcologne.de>
Organization: Rocksolid Light
Message-ID: <b748b2a0ce93a0e5f7ff92eda064ba85@www.novabbs.org>
 by: MitchAlsup1 - Sun, 28 Jan 2024 21:04 UTC

Thomas Koenig wrote:

> How do computers nowadays actually perform decimal arithmetic,
> and how did they do it in the past?

> For adding, the first microprocessors used the "if the result of
> A+B is larger than nine, then add six to the result and set carry"
> method. If one wanted to speed this up with today's possibilities,
> then the two additions could be done in parallel, with the carry
> of A+B+6 selecting the result. This could then be integrated into
> a conditional sum adder. If A+B+6 could be calculated efficiently
> with a modified carry lookahead method, this method could work well.

The above describes a suite of methods applicable to decimal arithmetic.

> For multiplication... I am not sure that the method outlined above
> for addition would be efficient.

Basically, you make a decimal multiplier cell 2×4-bits in 8-bits out
and feed these into a 3-input decimal carry save adder. By restricting
the input values to the set {0..9} instead of {0..15} you save a whole
bunch of gates. It is equivalent to a 100 cell ROM after the Verilog
gate muncher gets rid of excess logic.

{ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } // [*,0]
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } // [*,1]
{ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18 } // [*,2]
{ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27 } // [*,3]
...
{ 0, 9, 18, 27, 26, 45, 54, 63, 72, 81 } // [*,9]
}

You route the leading digit to the next column of significance.
You route the trailing digit to this column of significance.

> My (uninformed) guess would be that people would re-encode the BCD
> numbers to something with different weights than the traditional
> 8-4-2-1 (maybe 4-2-2-1) and then make modified Wallace or Dadda
> trees, which would deliver the indificual digits in that encoding,
> from which they could then be converted to BCD or another format
> as desired.

TI has a bunch of patents circa mid 1980s on decimal multiplication.

> Does anybody know how this is actually done?

Re: How is decimal arithmetic actually performed?

<up6ja9$2mf7$1@gal.iecc.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=37146&group=comp.arch#37146

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!news.iecc.com!.POSTED.news.iecc.com!not-for-mail
From: johnl@taugh.com (John Levine)
Newsgroups: comp.arch
Subject: Re: How is decimal arithmetic actually performed?
Date: Sun, 28 Jan 2024 22:09:13 -0000 (UTC)
Organization: Taughannock Networks
Message-ID: <up6ja9$2mf7$1@gal.iecc.com>
References: <up66n0$38fvr$1@newsreader4.netcologne.de>
Injection-Date: Sun, 28 Jan 2024 22:09:13 -0000 (UTC)
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970";
logging-data="88551"; mail-complaints-to="abuse@iecc.com"
In-Reply-To: <up66n0$38fvr$1@newsreader4.netcologne.de>
Cleverness: some
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: johnl@iecc.com (John Levine)
 by: John Levine - Sun, 28 Jan 2024 22:09 UTC

According to Thomas Koenig <tkoenig@netcologne.de>:
>How do computers nowadays actually perform decimal arithmetic,
>and how did they do it in the past?

Here's some papers from IBM about the implemenation of decimal arithmetic
in mainframes. Decimal floating point has a compressed format that puts
three digits into ten bits, but they say they unpack it into BCD to do
the arithmeitc. The actual arithmetic is still largely digit by digit,
with multiplication somewhat parallel adding up partial products.

https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=7c68c318aa6f98ae5a23163ff6f246180a782331
https://speleotrove.com/mfc/files/schwarz2009-decimalFP-on-z10.pdf

I get the impression the arithmetic algorithms haven't changed much
even though modern systems wrap fancier stuff around it like DFP and
vector registers. (No, I do not know what people do with decimal
vector registers, but they must do something since IBM added them
recently.)

--
Regards,
John Levine, johnl@taugh.com, Primary Perpetrator of "The Internet for Dummies",
Please consider the environment before reading this e-mail. https://jl.ly

Re: How is decimal arithmetic actually performed?

<up6naj$4ge6$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=37147&group=comp.arch#37147

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: quadibloc@servername.invalid (Quadibloc)
Newsgroups: comp.arch
Subject: Re: How is decimal arithmetic actually performed?
Date: Sun, 28 Jan 2024 23:17:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <up6naj$4ge6$1@dont-email.me>
References: <up66n0$38fvr$1@newsreader4.netcologne.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 28 Jan 2024 23:17:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa4bb1da54f4330e7814997011d1d27b";
logging-data="147910"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Fp9HF2/kOlEEeOV7uL7pEZkSYvNSEE2A="
User-Agent: Pan/0.146 (Hic habitat felicitas; d7a48b4
gitlab.gnome.org/GNOME/pan.git)
Cancel-Lock: sha1:rwipBtzieTrT0HIhkdk+v49oCpc=
 by: Quadibloc - Sun, 28 Jan 2024 23:17 UTC

On Sun, 28 Jan 2024 18:34:08 +0000, Thomas Koenig wrote:

> How do computers nowadays actually perform decimal arithmetic,
> and how did they do it in the past?

There are many ways to perform decimal arithmetic.

Let's start with a decimal adder. If decimal digits
are represented as BCD, it's possible to put together
a logic circuit that takes two BCD digits and a carry
bit as input, and produces one BCD digit and a carry
bit as an output.

This logic circuit can then be put in a larger circuit
in the same way that a binary adder can be. So you
can speed up addition with a carry-select adder, for
example.

If you scroll down about 7/8 of the way, on my page at

http://www.quadibloc.com/comp/cp0202.htm

I show a logic diagram for a decimal carry-save adder.

My scheme, though, is crude and simplistic, and better
designs are possible; the page mentions a paper from
1974 discussing a decimal carry-save adder.

So most of the techniques used in computers to speed up
binary arithmetic are also applicable to decimal arithmetic.

In the past, some very simple methods were used to implement
decimal arithmetic cheaply. For example, representing decimal
digits in "excess-3" notation meant that the carry out from
adding two decimal digits would occur when a normal binary
carry out would occur, so less special circuitry for decimal
is needed. One has to either add or subtract three, depending
on whether there was or wasn't a carry, to correct the digits
for future arithmetic afterwards.

John Savard

Re: How is decimal arithmetic actually performed?

<NxPtN.258091$7sbb.83316@fx16.iad>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=37149&group=comp.arch#37149

  copy link   Newsgroups: comp.arch
Path: i2pn2.org!rocksolid2!news.neodome.net!tncsrv06.tnetconsulting.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: How is decimal arithmetic actually performed?
Newsgroups: comp.arch
Distribution: world
References: <up66n0$38fvr$1@newsreader4.netcologne.de>
Lines: 8
Message-ID: <NxPtN.258091$7sbb.83316@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 29 Jan 2024 15:31:57 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 29 Jan 2024 15:31:57 GMT
X-Received-Bytes: 885
 by: Scott Lurndal - Mon, 29 Jan 2024 15:31 UTC

Thomas Koenig <tkoenig@netcologne.de> writes:
>How do computers nowadays actually perform decimal arithmetic,
>and how did they do it in the past?

http://bitsavers.org/pdf/burroughs/MediumSystems/B2500_B3500/1025475_B2500_B3500_RefMan_Oct69.pdf

Starting at page 5-10.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor