#ifndef abits
#define abits 4
#endif
#ifndef bbits
#define bbits 4
#endif
#define LSH(x) ((x){-2:0}@false)
#define RSH(x) (((x){-1})@(x){:1})
#define BvIntPlus(n,x,y) ((bv)((int)(x) + (int)(y))){n-1:}
#define BvIntMinus(n,x,y) ((bv)((int)(x) - (int)(y))){n-1:}
module Monitor(int[abits] a, int[bbits] b,
int[abits+bbits] &p,&q, event &correct)
implements MonitorSpec(correct) {
next(q) = a*b;
BoothMult01((bv)a,(bv)b,(bv)p);
if(p==q) emit correct;
}
spec MonitorSpec(event correct) {
IsCorrect : A F correct;
}
module BoothMult01(bv[abits] a, bv[bbits] b, bv[abits+bbits] &p) {
bv[abits] x, bv[bbits] y, bool y_old;
x = a;
y = b;
p = {false::abits+bbits};
y_old = false;
sequence(int i=1 .. bbits) {
let (p1 = p{:-abits} )
let (p2 = p{-1-abits:1} ) {
if(y_old & !y{0})
next(p) = BvIntPlus(abits+1,p1,x)@p2;
else if(!y_old & y{0})
next(p) = BvIntMinus(abits+1,p1,x)@p2;
else
next(p) = RSH(p);
next(y_old) = y{0};
next(y) = RSH(y);
}
pause;
}
}