BCD in C - adding a little substance

Dick Dunn rcd at opus.UUCP
Wed Dec 19 16:30:15 AEST 1984


The "should C have a BCD type?" discussion has been going on in net.lang.c
for a while.  There are some related hardware issues...
> 	Mr. Messinger writes at length and with marvellous sarcasm
> about how much slower BCD arithmetic is than binary arithmetic.  This
> is all very true IF THE MACHINE IN QUESTION DOES NOT SUPPORT BCD
> ARITHMETIC.  On IBM mainframes, however, BCD arithmetic is supported
> in HARDWARE and is as fast as binary arithmetic...

(The author of the above article doesn't actually advocate BCD in C,
however.)

BCD arithmetic is only as fast as binary arithmetic if BCD is given pretty
hefty hardware/microcode support at the expense of binary.  In fact, it is
generally quite a bit slower even on machines with substantial microcode
support for it.

Here, a couple of excerpts from "Analysis and Performance of Computer
Instruction Sets" by Leonard Jay Shustek--SLAC Report 205, and apparently a
thesis done under Forrest Basket:

In discussing the performance of a COBOL test case in the suite of test
programs, "...the average execution rate in millions of instructions per
second for [COBOL test case]...is drastically smaller than the average for
all the programs..."  The actual difference was more than a factor of 4.
Some attached charts show that although the DP instruction ("packed-decimal"
or BCD divide) has both static and dynamic frequency of occurrence below
2% of the program, the execution time devoted to this one opcode was 18.7%
of total program execution time on a 370/168 and an amazing 32.8% on an
Amdahl 470 V/6.  Also speaking of decimal instructions, he says, "In view
of the poor performance of many of the variable operand length
instructions, their inclusion in the architecture of a high-performance
computer is questionable...the arithmetic which must occur before these
instructions begin their data transfer suggests that it is quite difficult
to optimize them for short operands..."  He goes on to suggest that it
might be better to build in instructions from which the BCD operations
could be synthesized.

Later, in his set of conclusions, he states simply, "Eliminate Decimal
Instructions."  He questions the rationalization of decimal instructions on
the basis of cost of conversion to/from binary.

My point is that the hardware case for BCD is far from closed, let alone
the software case for anything other than a business language.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Nothing left to do but smile, smile, smile.



More information about the Comp.lang.c mailing list