]> Witch of Git - nan-gate/blob - techlib.sv
Fix errors in the synth_nan help message
[nan-gate] / techlib.sv
1 `define POS0 3'b000
2 `define NEG0 3'b100
3 `define POS1 3'b001
4 `define NEG1 3'b101
5 `define PINF 3'b010
6 `define NINF 3'b110
7 `define PNAN 3'b011
8 `define NNAN 3'b111
9 `define ANAN 3'b?11
10 `define ANYF 3'b???
11
12 // A NaN gate! Computes `Inf - max(x+y, -Inf)`.
13 // See http://tom7.org/nand/
14 module nan(
15 input [2:0] A,
16 input [2:0] B, output reg [2:0] Y
17 );
18
19 always begin
20 casez ({A, B})
21 {`ANYF, `ANAN}, {`ANAN, `ANYF}: Y = `PINF;
22 {`PINF, `NINF}, {`NINF, `PINF}: Y = `PINF;
23 {`ANYF, `PINF}, {`PINF, `ANYF}: Y = `PNAN;
24 default: Y = `PINF;
25 endcase
26 end
27 endmodule
28
29 // Convert a bit into an fp3
30 module bit_to_fp3(input A, output [2:0] Y);
31 assign Y = A ? `PNAN : `PINF;
32 endmodule
33
34 // Convert an fp3 into a bit
35 module fp3_to_bit(input [2:0] A, output reg Y);
36 always begin
37 case (A)
38 `PNAN, `NNAN: Y = 1'b1;
39 default: Y = 1'b0;
40 endcase
41 end
42 endmodule
43