Skip to content

Instantly share code, notes, and snippets.

@CapacitorSet
Created September 10, 2019 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CapacitorSet/db9993e7a7bb97b6dc860e603cb34cb9 to your computer and use it in GitHub Desktop.
Save CapacitorSet/db9993e7a7bb97b6dc860e603cb34cb9 to your computer and use it in GitHub Desktop.
8 bit adder for Glovebox
void add8(gb::bitvec<8> out, bit_t overflow, const gb::bitvec<8> a,
const gb::bitvec<8> b) {
bit_t _00_ = make_bit();
_nor(_00_, a[7], b[7]);
bit_t _01_ = make_bit();
_nand(_01_, a[6], b[6]);
bit_t _02_ = make_bit();
_nand(_02_, a[5], b[5]);
bit_t _03_ = make_bit();
_nand(_03_, a[4], b[4]);
bit_t _04_ = make_bit();
_nand(_04_, a[3], b[3]);
bit_t _05_ = make_bit();
_nand(_05_, a[2], b[2]);
bit_t _06_ = make_bit();
_nand(_06_, a[1], b[1]);
bit_t _07_ = make_bit();
_and(_07_, a[0], b[0]);
bit_t _08_ = make_bit();
_xor(_08_, a[1], b[1]);
bit_t _09_ = make_bit();
_nand(_09_, _07_, _08_);
bit_t _10_ = make_bit();
_nand(_10_, _06_, _09_);
_xor(_06_, a[2], b[2]);
_nand(_09_, _10_, _06_);
bit_t _13_ = make_bit();
_nand(_13_, _05_, _09_);
_xor(_05_, a[3], b[3]);
_nand(_09_, _13_, _05_);
bit_t _16_ = make_bit();
_nand(_16_, _04_, _09_);
_xor(_04_, a[4], b[4]);
_nand(_09_, _16_, _04_);
bit_t _19_ = make_bit();
_nand(_19_, _03_, _09_);
_xor(_03_, a[5], b[5]);
_nand(_09_, _19_, _03_);
bit_t _22_ = make_bit();
_nand(_22_, _02_, _09_);
_xor(_02_, a[6], b[6]);
_nand(_09_, _22_, _02_);
bit_t _25_ = make_bit();
_and(_25_, _01_, _09_);
_and(_01_, a[7], b[7]);
_xor(_09_, a[7], b[7]);
_xnor(out[7], _25_, _09_);
_mux(overflow, _25_, _01_, _00_);
_xor(out[0], a[0], b[0]);
_xor(out[1], _07_, _08_);
_xor(out[2], _10_, _06_);
_xor(out[3], _13_, _05_);
_xor(out[4], _16_, _04_);
_xor(out[5], _19_, _03_);
_xor(out[6], _22_, _02_);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment