module modecomp 
title 'Control PLD for Mode-Dependent Comparator' 
"MODECOMP device 'P16V8'; 

" Input and output pins 
M0, M1, EQ2_L, GT2_L, EQ0_L, GT0_L           pin 1..6; 
EQ1_L, GT1_L, EQ3_L, GT3_L, X0, X1, Y0, Y1   pin 7..9, 10, 15..18; 
XEQY, XGTY                                   pin 19, 12 istype 'com';

" Active-level conversions
EQ3 = !EQ3_L; EQ2 = !EQ2_L; EQ1 = !EQ1_L; EQ0 = !EQ0_L; 
GT3 = !GT3_L; GT2 = !GT2_L; GT1 = !GT1_L; GT0 = !GT0_L;

" Mode definitions
MODE32 = ([M1,M0] == [0,0]); " 32-bit comparison
MODE31 = ([M1,M0] == [0,1]); " 31-bit comparison
MODE30 = ([M1,M0] == [1,.X.]); " 30-bit comparison
MODEXX = ([M1,M0] == [1,1]); " Unused

" Expressions for 30-bit equal and greater-than 
EQ30 = EQ3 & EQ2 & EQ1 & EQ0;
GT30 = GT3  #  EQ3 & GT2  #  EQ3 & EQ2 & GT1  #  EQ3 & EQ2 & EQ1 & GT0;


equations

WHEN MODE32 THEN {
  XEQY = EQ30 & (X1==Y1) & (X0==Y0);
  XGTY = GT30  #  EQ30 & (X1>Y1)  #  EQ30 & (X1==Y1) & (X0>Y0);
  }
ELSE WHEN MODE31 THEN {
  XEQY = EQ30 & (X1==Y1);
  XGTY = GT30  #  EQ30 & (X1>Y1);
  }
ELSE WHEN MODE30 THEN {
  XEQY = EQ30;
  XGTY = GT30;
  }

end modecomp
