X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2FBit.java;h=992c729594837db2747256e550b167f86d2cdb7a;hb=c18c04011cab0040c2287608eeefc9c3cc4536c2;hp=8010ca760b852ad3cf99f4018f48a93549c233e2;hpb=62bde086cd9895a0de2b0c3d242e546c263ea5a0;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/Bit.java b/era.mi/src/era/mi/logic/Bit.java index 8010ca76..992c7295 100644 --- a/era.mi/src/era/mi/logic/Bit.java +++ b/era.mi/src/era/mi/logic/Bit.java @@ -5,35 +5,44 @@ import java.util.Arrays; /** * stdlogic according to IEEE 1164 */ -public enum Bit { +public enum Bit +{ U, X, ZERO, ONE, Z; - public static Bit and(Bit a, Bit b) { + public static Bit and(Bit a, Bit b) + { return a.and(b); } - public Bit and(Bit other) { + public Bit and(Bit other) + { return fromTable(AND_TABLE, this, other); } - public static Bit or(Bit a, Bit b) { + public static Bit or(Bit a, Bit b) + { return a.or(b); } - public Bit or(Bit other) { + public Bit or(Bit other) + { return fromTable(OR_TABLE, this, other); } - public static Bit xor(Bit a, Bit b) { + public static Bit xor(Bit a, Bit b) + { return a.xor(b); } - public Bit xor(Bit other) { + public Bit xor(Bit other) + { return fromTable(XOR_TABLE, this, other); } - public Bit not() { - switch (this) { + public Bit not() + { + switch (this) + { case U: return U; case ONE: @@ -45,47 +54,51 @@ public enum Bit { } } - public Bit[] makeArray(int length) { + public Bit[] makeArray(int length) + { Bit[] bits = new Bit[length]; Arrays.fill(bits, this); return bits; } - public Bit combineWith(Bit other) { + public Bit combineWith(Bit other) + { return fromTable(JOIN_TABLE, this, other); } - public static Bit combine(Bit a, Bit b) { + public static Bit combine(Bit a, Bit b) + { return a.combineWith(b); } - private static Bit fromTable(Bit[][] table, Bit a, Bit b) { + private static Bit fromTable(Bit[][] table, Bit a, Bit b) + { return table[a.ordinal()][b.ordinal()]; } // @formatter:off - private static Bit[][] JOIN_TABLE = + private static final Bit[][] JOIN_TABLE = { { U, U, U, U, U }, { U, X, X, X, X }, { U, X, ZERO, X, ZERO }, { U, X, X, ONE, ONE }, { U, X, ZERO, ONE, Z } }; - private static Bit[][] AND_TABLE = + private static final Bit[][] AND_TABLE = { { U, U, ZERO, U, U }, { U, X, ZERO, X, X }, { ZERO, ZERO, ZERO, ZERO, ZERO }, { U, X, ZERO, ONE, X }, { U, X, ZERO, X, X } }; - private static Bit[][] OR_TABLE = + private static final Bit[][] OR_TABLE = { { U, U, U, ONE, U }, { U, X, X, ONE, X }, { U, X, ZERO, ONE, X }, { ONE, ONE, ONE, ONE, ONE }, { U, X, X, ONE, X } }; - private static Bit[][] XOR_TABLE = + private static final Bit[][] XOR_TABLE = { { U, U, U, U, U }, { U, X, X, X, X }, { U, X, ZERO, ONE, X },