# [Libre-soc-bugs] [Bug 656] add v3.0B BCD instructions to simulator

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed Jul 28 11:20:46 BST 2021

```https://bugs.libre-soc.org/show_bug.cgi?id=656

--- Comment #1 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
dmitry the pseudocode for cdtbcd and cbcdtd uses a couple of helper functions
which need to be added before they can "work".  addg6s on the other hand
you can do straight away without this.

i found in "v3.0B p787 Book I Appendix B.1 and B.2" the following
pseudocode:

B.1 BCD-to-DPD Translation
The translation from a 3-digit BCD number to a 10-bit
DPD can be performed through the following Boolean
operations.

p = (f & a & i & Â¬e) | (j & a & Â¬i) | (b & Â¬a)
q = (g & a & i & Â¬e) | (k & a & Â¬i) | (c & Â¬a)
r = d
s = (j  &  Â¬a & e & Â¬i) | (f & Â¬i & Â¬e) |
(f &  Â¬a & Â¬e) | (e & i)
t = (k  &  Â¬a & e & Â¬i) | (g & Â¬i & Â¬e) |
(g &  Â¬a & Â¬e) | (a & i)
u = h
v = a | e | i
w = (Â¬e & j & Â¬i) | (e & i) | a
x = (Â¬a & k & Â¬i) | (a & i) | e
y = m

B.2 DPD-to-BCD Translation

The translation from a 10-bit DPD to a 3-digit BCD
number can be performed through the following Bool-
ean operations.

a =  (Â¬s & v & w) | (t & v & w & s) | (v & w & Â¬x)
b =  (p & s & x & Â¬t) | (p & Â¬w) | (p & Â¬v)
c =  (q & s & x & Â¬t) | (q & Â¬w) | (q & Â¬v)
d =  r
e = (v & Â¬w & x) | (s & v & w & x) |
(Â¬t & v & x & w)
f = (p & t & v & w & x & Â¬s) | (s & Â¬x & v) |
(s & Â¬v)
g = (q & t & w & v & x & Â¬s) | (t & Â¬x & v) |
(t & Â¬v)
h = u
i = (t  & v & w & x) | (s & v & w & x) |
(v & Â¬w & Â¬x)
j = (p  & Â¬s & Â¬t & w & v) | (s & v & Â¬w & x) |
(p & w & Â¬x & v) | (w & Â¬v)
k = (q  & Â¬s & Â¬t & v & w) | (t & v & Â¬w & x) |
(q & v & w & Â¬x) | (x & Â¬v)
m = y

after removing the silliness of *yet another* non-ASCII symbol for "¬"
being used, those will need to go into openpower/isafunctions/bcd.mdwn,
along with comments saying where they come from.  see here for example
to cut/paste:

then you can run "pyfnwriter" to generate the actual python code

then, in pywriter.py you will need to *add* those helper functions
*manually* (at the moment, really they should be done automatically)

from openpower.decoder.isafunctions.bcd import BCD_TO_DPD, DPD_TO_BCD

then re-run pywriter noall bcd in order to get the decoder/isa/bcd.py
to be re-compiled with the import of the helper function added.

or, cheat, and manually edit decoder/isa/bcd.py :)

--
You are receiving this mail because:
You are on the CC list for the bug.
```