CodeMirror: Verilog mode

/* Verilog demo code */
1
/* Verilog demo code */
2
 
3
module butterfly
4
  #(
5
    parameter WIDTH = 32,
6
    parameter MWIDTH = 1
7
    )
8
   (
9
    input wire                     clk,
10
    input wire                     rst_n,
11
    // m_in contains data that passes through this block with no change.
12
    input wire [MWIDTH-1:0]        m_in,
13
    // The twiddle factor.
14
    input wire signed [WIDTH-1:0]  w,
15
    // XA
16
    input wire signed [WIDTH-1:0]  xa,
17
    // XB
18
    input wire signed [WIDTH-1:0]  xb,
19
    // Set to 1 when new data is present on inputs.
20
    input wire                     x_nd,
21
    // delayed version of m_in.
22
    output reg [MWIDTH-1:0]        m_out,
23
    // YA = XA + W*XB
24
    // YB = XA - W*XB
25
    output wire signed [WIDTH-1:0] ya,
26
    output wire signed [WIDTH-1:0] yb,
27
    output reg                     y_nd,
28
    output reg                     error
29
    );
30
 
31
   // Set wire to the real and imag parts for convenience.
32
   wire signed [WIDTH/2-1:0]        xa_re;
33
   wire signed [WIDTH/2-1:0]        xa_im;
34
   assign xa_re = xa[WIDTH-1:WIDTH/2];
35
   assign xa_im = xa[WIDTH/2-1:0];
36
   wire signed [WIDTH/2-1: 0]       ya_re;
37
   wire signed [WIDTH/2-1: 0]       ya_im;
38
   assign ya = {ya_re, ya_im};
39
   wire signed [WIDTH/2-1: 0]       yb_re;
40
   wire signed [WIDTH/2-1: 0]       yb_im;
41
   assign yb = {yb_re, yb_im};
42
 
43
   // Delayed stuff.
44
   reg signed [WIDTH/2-1:0]         xa_re_z;
45
   reg signed [WIDTH/2-1:0]         xa_im_z;
46
   // Output of multiplier
47
   wire signed [WIDTH-1:0]          xbw;
48
   wire signed [WIDTH/2-1:0]        xbw_re;
49
   wire signed [WIDTH/2-1:0]        xbw_im;
50
   assign xbw_re = xbw[WIDTH-1:WIDTH/2];
51
   assign xbw_im = xbw[WIDTH/2-1:0];
52
   // Do summing
53
   // I don't think we should get overflow here because of the
54
   // size of the twiddle factors.
55
   // If we do testing should catch it.
56
   assign ya_re = xa_re_z + xbw_re;
57
   assign ya_im = xa_im_z + xbw_im;
58
   assign yb_re = xa_re_z - xbw_re;
59
   assign yb_im = xa_im_z - xbw_im;
60
   
61
   // Create the multiply module.
62
   multiply_complex #(WIDTH) multiply_complex_0
63
     (.clk(clk),
64
      .rst_n(rst_n),
65
      .x(xb),
66
      .y(w),
67
      .z(xbw)
68
      );
69
 
70
  always @ (posedge clk)
71
    begin
72
       if (!rst_n)
73
         begin
74
            y_nd <= 1'b0;
75
            error <= 1'b0;
76
         end
77
       else
78
         begin
79
            // Set delay for x_nd_old and m.
80
            y_nd <= x_nd;
81
            m_out <= m_in;
82
            if (x_nd)
83
              begin
84
                 xa_re_z <= xa_re/2;
85
                 xa_im_z <= xa_im/2;
86
              end
87
         end
88
    end
89
   
90
endmodule
91
 
 

Simple mode that tries to handle Verilog-like languages as well as it can. Takes one configuration parameters: keywords, an object whose property names are the keywords in the language.

MIME types defined: text/x-verilog (Verilog code).