• How is decimal arithmetic actually performed?

    From Thomas Koenig@21:1/5 to All on Sun Jan 28 18:34:08 2024
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MitchAlsup1@21:1/5 to Thomas Koenig on Sun Jan 28 21:04:58 2024
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Levine@21:1/5 to All on Sun Jan 28 22:09:13 2024
    According to Thomas Koenig <[email protected]>:
    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, [email protected], Primary Perpetrator of "The Internet for Dummies",
    Please consider the environment before reading this e-mail. https://jl.ly

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Quadibloc@21:1/5 to Thomas Koenig on Sun Jan 28 23:17:39 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Thomas Koenig on Mon Jan 29 15:31:57 2024
    Thomas Koenig <[email protected]> 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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)