Attention
This documentation is a work in progress. Expect to see errors and unfinished things.
doublediff1 Source File
1`timescale 1ns / 1ns
2
3module doublediff1(
4 input clk,
5 input reset,
6 input [dw-1:0] d_in,
7 input [gw-1:0] g_in,
8 output [dw-1:0] d_out,
9 output [gw-1:0] g_out
10);
11parameter dw=28;
12parameter gw=1;
13parameter dsr_len=4;
14
15reg signed [dw-1:0] d1=0, d2=0;
16wire [gw-1:0] valid1, valid2;
17wire [dw-1:0] dpass1, dpass2;
18
19reg_delay #(.dw(dw), .len(dsr_len))
20 s1(.clk(clk), .gate(g_in[0]), .din(d_in), .dout(dpass1), .reset(reset));
21
22reg_delay #(.dw(dw), .len(dsr_len))
23 s2(.clk(clk), .gate(valid1[0]), .din(d1), .dout(dpass2), .reset(reset));
24
25reg_delay #(.dw(gw), .len(1))
26 reg_delay_g1(.clk(clk), .gate(1'b1), .din(g_in), .dout(valid1), .reset(reset));
27
28reg_delay #(.dw(gw), .len(1))
29 reg_delay_g2(.clk(clk), .gate(1'b1), .din(valid1), .dout(valid2), .reset(reset));
30
31always @(posedge clk) begin
32 d1 <= reset ? {dw{1'b0}} : (g_in[0] ? d_in - dpass1 : d1);
33 d2 <= reset ? {dw{1'b0}} : (valid1[0] ? d1 - dpass2 : d2);
34end
35assign d_out = d2;
36assign g_out = valid2;
37endmodule