Bluespec SystemVerilog language preview
1. Euclidean GCD
atomic rules racing to swap or subtract each cycle
horizon-dark
interface ArithIO;
method Action start(Bit#(32) n, Bit#(32) m);
method Bit#(32) result;
endinterface
module mkGCD(ArithIO);
Reg#(Bit#(32)) n <- mkRegU;
Reg#(Bit#(32)) m <- mkRegU;
rule swap (n > m && m != 0);
n <= m;
m <= n;
endrule
rule sub (n <= m && m != 0);
m <= m - n;
endrule
method Action start(Bit#(32) in_n, Bit#(32) in_m) if (m == 0);
n <= in_n;
m <= in_m;
endmethod
method Bit#(32) result if (m == 0);
return n;
endmethod
endmodule atom-one-dark
interface ArithIO;
method Action start(Bit#(32) n, Bit#(32) m);
method Bit#(32) result;
endinterface
module mkGCD(ArithIO);
Reg#(Bit#(32)) n <- mkRegU;
Reg#(Bit#(32)) m <- mkRegU;
rule swap (n > m && m != 0);
n <= m;
m <= n;
endrule
rule sub (n <= m && m != 0);
m <= m - n;
endrule
method Action start(Bit#(32) in_n, Bit#(32) in_m) if (m == 0);
n <= in_n;
m <= in_m;
endmethod
method Bit#(32) result if (m == 0);
return n;
endmethod
endmodule github-dark
interface ArithIO;
method Action start(Bit#(32) n, Bit#(32) m);
method Bit#(32) result;
endinterface
module mkGCD(ArithIO);
Reg#(Bit#(32)) n <- mkRegU;
Reg#(Bit#(32)) m <- mkRegU;
rule swap (n > m && m != 0);
n <= m;
m <= n;
endrule
rule sub (n <= m && m != 0);
m <= m - n;
endrule
method Action start(Bit#(32) in_n, Bit#(32) in_m) if (m == 0);
n <= in_n;
m <= in_m;
endmethod
method Bit#(32) result if (m == 0);
return n;
endmethod
endmodule dracula
interface ArithIO;
method Action start(Bit#(32) n, Bit#(32) m);
method Bit#(32) result;
endinterface
module mkGCD(ArithIO);
Reg#(Bit#(32)) n <- mkRegU;
Reg#(Bit#(32)) m <- mkRegU;
rule swap (n > m && m != 0);
n <= m;
m <= n;
endrule
rule sub (n <= m && m != 0);
m <= m - n;
endrule
method Action start(Bit#(32) in_n, Bit#(32) in_m) if (m == 0);
n <= in_n;
m <= in_m;
endmethod
method Bit#(32) result if (m == 0);
return n;
endmethod
endmodule nord
interface ArithIO;
method Action start(Bit#(32) n, Bit#(32) m);
method Bit#(32) result;
endinterface
module mkGCD(ArithIO);
Reg#(Bit#(32)) n <- mkRegU;
Reg#(Bit#(32)) m <- mkRegU;
rule swap (n > m && m != 0);
n <= m;
m <= n;
endrule
rule sub (n <= m && m != 0);
m <= m - n;
endrule
method Action start(Bit#(32) in_n, Bit#(32) in_m) if (m == 0);
n <= in_n;
m <= in_m;
endmethod
method Bit#(32) result if (m == 0);
return n;
endmethod
endmodule github
interface ArithIO;
method Action start(Bit#(32) n, Bit#(32) m);
method Bit#(32) result;
endinterface
module mkGCD(ArithIO);
Reg#(Bit#(32)) n <- mkRegU;
Reg#(Bit#(32)) m <- mkRegU;
rule swap (n > m && m != 0);
n <= m;
m <= n;
endrule
rule sub (n <= m && m != 0);
m <= m - n;
endrule
method Action start(Bit#(32) in_n, Bit#(32) in_m) if (m == 0);
n <= in_n;
m <= in_m;
endmethod
method Bit#(32) result if (m == 0);
return n;
endmethod
endmodule 2. ActionValue counter
a method that both mutates state and returns a value
horizon-dark
interface Counter;
method Action increment;
method ActionValue#(Bit#(32)) read;
endinterface
module mkCounter(Counter);
Reg#(Bit#(32)) count <- mkReg(0);
method Action increment;
count <= count + 1;
endmethod
method ActionValue#(Bit#(32)) read;
return count;
endmethod
endmodule atom-one-dark
interface Counter;
method Action increment;
method ActionValue#(Bit#(32)) read;
endinterface
module mkCounter(Counter);
Reg#(Bit#(32)) count <- mkReg(0);
method Action increment;
count <= count + 1;
endmethod
method ActionValue#(Bit#(32)) read;
return count;
endmethod
endmodule github-dark
interface Counter;
method Action increment;
method ActionValue#(Bit#(32)) read;
endinterface
module mkCounter(Counter);
Reg#(Bit#(32)) count <- mkReg(0);
method Action increment;
count <= count + 1;
endmethod
method ActionValue#(Bit#(32)) read;
return count;
endmethod
endmodule dracula
interface Counter;
method Action increment;
method ActionValue#(Bit#(32)) read;
endinterface
module mkCounter(Counter);
Reg#(Bit#(32)) count <- mkReg(0);
method Action increment;
count <= count + 1;
endmethod
method ActionValue#(Bit#(32)) read;
return count;
endmethod
endmodule nord
interface Counter;
method Action increment;
method ActionValue#(Bit#(32)) read;
endinterface
module mkCounter(Counter);
Reg#(Bit#(32)) count <- mkReg(0);
method Action increment;
count <= count + 1;
endmethod
method ActionValue#(Bit#(32)) read;
return count;
endmethod
endmodule github
interface Counter;
method Action increment;
method ActionValue#(Bit#(32)) read;
endinterface
module mkCounter(Counter);
Reg#(Bit#(32)) count <- mkReg(0);
method Action increment;
count <= count + 1;
endmethod
method ActionValue#(Bit#(32)) read;
return count;
endmethod
endmodule 3. Struct with deriving
a packed instruction word decoded by a pure function
horizon-dark
typedef struct {
Bit#(8) opcode;
Bit#(24) payload;
} Instruction deriving (Bits, Eq);
function Bool isNop(Instruction instr);
return instr.opcode == 0;
endfunction atom-one-dark
typedef struct {
Bit#(8) opcode;
Bit#(24) payload;
} Instruction deriving (Bits, Eq);
function Bool isNop(Instruction instr);
return instr.opcode == 0;
endfunction github-dark
typedef struct {
Bit#(8) opcode;
Bit#(24) payload;
} Instruction deriving (Bits, Eq);
function Bool isNop(Instruction instr);
return instr.opcode == 0;
endfunction dracula
typedef struct {
Bit#(8) opcode;
Bit#(24) payload;
} Instruction deriving (Bits, Eq);
function Bool isNop(Instruction instr);
return instr.opcode == 0;
endfunction nord
typedef struct {
Bit#(8) opcode;
Bit#(24) payload;
} Instruction deriving (Bits, Eq);
function Bool isNop(Instruction instr);
return instr.opcode == 0;
endfunction github
typedef struct {
Bit#(8) opcode;
Bit#(24) payload;
} Instruction deriving (Bits, Eq);
function Bool isNop(Instruction instr);
return instr.opcode == 0;
endfunction