From 6779ce8c51ed965085805cd5c1b1f7a0e7833ffe Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 10 Feb 2018 12:42:31 +0100 Subject: replace expand with lookup map --- parse.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/parse.go b/parse.go index 3a6bd8d..a117f93 100644 --- a/parse.go +++ b/parse.go @@ -75,8 +75,8 @@ func newALU(v uint16) ALU { TtoN: v&(1<<7) != 0, TtoR: v&(1<<6) != 0, NtoAtT: v&(1<<5) != 0, - Rdir: expand((v >> 2) & 3), - Ddir: expand(v & 3), + Rdir: expand[(v>>2)&3], + Ddir: expand[v&3], } } @@ -101,12 +101,8 @@ func (v ALU) value() uint16 { func (v ALU) compile() uint16 { return v.value() | (3 << 13) } -func expand(v uint16) int8 { - if v&2 != 0 { - v |= 0xfc - } - return int8(v) -} +// expand 2 bit unsigned to 8 bit signed +var expand = map[uint16]int8{0: 0, 1: 1, 2: -2, 3: -1} const ( opT = iota // 0 -- cgit v1.2.3