source: vis_dev/vis-2.1/examples/minmax/minMax.v @ 11

Last change on this file since 11 was 11, checked in by cecile, 13 years ago

Add vis

File size: 1.4 KB
Line 
1// MinMax circuit. Translated into Verilog from the LDS description in
2// "Verification of Sequential Machines Using Boolean Functional Vectors"
3// by Coudert, Berthet, and Madre.
4//
5// Author: Fabio Somenzi <Fabio@Colorado.EDU>
6
7module minMax (clock,clear,enable,reset,in,out);
8    parameter      MSB = 29;    // index of the MSB
9    input          clock;
10    input          clear;
11    input          enable;
12    input          reset;
13    input [MSB:0]  in;
14    output [MSB:0] out;
15   
16    reg [MSB:0]    min;
17    reg [MSB:0]    last;
18    reg [MSB:0]    max;
19   
20    wire [MSB:0]   sup;
21    wire [MSB:0]   inf;
22    wire [MSB:0]   avg;
23    wire           aux;
24
25    initial begin
26        min = {MSB+1{1'b1}};    // fill min with all ones.
27        max = 0;
28        last = {MSB+1{1'bx}};
29    end
30
31    // Next state logic.
32    assign {avg,aux} = {1'b0,sup} + {1'b0,inf}; // average of min and max
33    assign sup = (in > max) ? in : max;         // unsigned comparison
34    assign inf = (in < min) ? in : min;
35
36    always @ (posedge clock) begin
37        if (clear) begin
38            last = 0; max = 0; min = {MSB+1{1'b1}};
39        end else begin
40            if (!enable) begin
41                max = 0; min = {MSB+1{1'b1}};
42            end else begin
43                last = in;
44                if (reset) begin
45                    max = 0; min = {MSB+1{1'b1}};
46                end else begin
47                    max = sup; min = inf;
48                end
49            end
50        end
51    end
52
53    // Output logic.
54    assign out = clear ?  0 :
55        !enable ?  last :
56        reset ?  in : avg;
57   
58endmodule // minMax
Note: See TracBrowser for help on using the repository browser.