1 |
2 |
dgisselq |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Filename: wbudecompress.v
|
4 |
|
|
//
|
5 |
|
|
// Project: XuLA2 board
|
6 |
|
|
//
|
7 |
|
|
// Purpose: Compression via this interface is simply a lookup table.
|
8 |
|
|
// When writing, if requested, rather than writing a new 36-bit
|
9 |
|
|
// word, we may be asked to repeat a word that's been written recently.
|
10 |
|
|
// That's the goal of this routine: if given a word's (relative) address
|
11 |
|
|
// in the write stream, we use that address, else we expect a full 32-bit
|
12 |
|
|
// word to come in to be written.
|
13 |
|
|
//
|
14 |
|
|
//
|
15 |
|
|
// Creator: Dan Gisselquist, Ph.D.
|
16 |
|
|
// Gisselquist Technology, LLC
|
17 |
|
|
//
|
18 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
//
|
20 |
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
21 |
|
|
//
|
22 |
|
|
// This program is free software (firmware): you can redistribute it and/or
|
23 |
|
|
// modify it under the terms of the GNU General Public License as published
|
24 |
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
25 |
|
|
// your option) any later version.
|
26 |
|
|
//
|
27 |
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
28 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
29 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
30 |
|
|
// for more details.
|
31 |
|
|
//
|
32 |
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
33 |
|
|
// http://www.gnu.org/licenses/gpl.html
|
34 |
|
|
//
|
35 |
|
|
//
|
36 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
//
|
38 |
|
|
//
|
39 |
|
|
module wbudecompress(i_clk, i_stb, i_word, o_stb, o_word);
|
40 |
|
|
input i_clk, i_stb;
|
41 |
|
|
input [35:0] i_word;
|
42 |
|
|
output reg o_stb;
|
43 |
|
|
output reg [35:0] o_word;
|
44 |
|
|
|
45 |
|
|
wire cmd_write_not_compressed = (i_word[35:33] == 3'h3);
|
46 |
|
|
|
47 |
|
|
reg [7:0] wr_addr;
|
48 |
|
|
initial wr_addr = 8'h0;
|
49 |
|
|
always @(posedge i_clk)
|
50 |
|
|
if ((i_stb)&&(cmd_write_not_compressed))
|
51 |
|
|
wr_addr <= wr_addr + 8'h1;
|
52 |
|
|
|
53 |
|
|
reg [31:0] compression_tbl [0:255];
|
54 |
|
|
always @(posedge i_clk)
|
55 |
|
|
compression_tbl[wr_addr] <= { i_word[32:31], i_word[29:0] };
|
56 |
|
|
|
57 |
|
|
// Clock 0, calculate the table address ... 1 is the smallest address
|
58 |
|
|
wire [7:0] cmd_addr;
|
59 |
|
|
assign cmd_addr = wr_addr - { i_word[32:31], i_word[29:24] };
|
60 |
|
|
|
61 |
|
|
// Clock one, read the table value
|
62 |
|
|
reg [31:0] cword;
|
63 |
|
|
always @(posedge i_clk)
|
64 |
|
|
cword <= compression_tbl[cmd_addr];
|
65 |
|
|
|
66 |
|
|
// Let's also calculate the address, in case this is a compressed
|
67 |
|
|
// address word
|
68 |
|
|
reg [24:0] r_addr;
|
69 |
|
|
always @(posedge i_clk)
|
70 |
|
|
case(i_word[32:30])
|
71 |
|
|
3'b000: r_addr <= { 19'h0, i_word[29:24] };
|
72 |
|
|
3'b010: r_addr <= { 13'h0, i_word[29:18] };
|
73 |
|
|
3'b100: r_addr <= { 7'h0, i_word[29:12] };
|
74 |
|
|
3'b110: r_addr <= { 1'h0, i_word[29: 6] };
|
75 |
|
|
3'b001: r_addr <= { {(19){ i_word[29]}}, i_word[29:24] };
|
76 |
|
|
3'b011: r_addr <= { {(13){ i_word[29]}}, i_word[29:18] };
|
77 |
|
|
3'b101: r_addr <= { {( 7){ i_word[29]}}, i_word[29:12] };
|
78 |
|
|
3'b111: r_addr <= { {( 1){ i_word[29]}}, i_word[29: 6] };
|
79 |
|
|
endcase
|
80 |
|
|
wire [31:0] w_addr;
|
81 |
|
|
assign w_addr = { {(7){r_addr[24]}}, r_addr };
|
82 |
|
|
|
83 |
|
|
reg [9:0] rd_len;
|
84 |
|
|
always @(posedge i_clk)
|
85 |
|
|
if (~i_word[34])
|
86 |
|
|
rd_len <= 10'h01 + { 6'h00, i_word[33:31] };
|
87 |
|
|
else
|
88 |
|
|
rd_len <= 10'h08 + { 1'b0, i_word[33:31], i_word[29:24] };
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
// Clock one, copy the input strobe, and input word
|
92 |
|
|
reg r_stb;
|
93 |
|
|
reg [35:0] r_word;
|
94 |
|
|
always @(posedge i_clk)
|
95 |
|
|
r_stb <= i_stb;
|
96 |
|
|
always @(posedge i_clk)
|
97 |
|
|
r_word <= i_word;
|
98 |
|
|
|
99 |
|
|
// Clock two, now that the table value is valid, let's set our output
|
100 |
|
|
// word.
|
101 |
|
|
always @(posedge i_clk)
|
102 |
|
|
o_stb <= r_stb;
|
103 |
|
|
always @(posedge i_clk)
|
104 |
|
|
if (r_word[35:30] == 6'b101110)
|
105 |
|
|
o_word <= r_word;
|
106 |
|
|
else casez(r_word[35:30])
|
107 |
|
|
6'b001??0: o_word <= { 4'h0, w_addr[31:0] };
|
108 |
|
|
6'b001??1: o_word <= { 3'h1, w_addr[31:30], 1'b1, w_addr[29:0] };
|
109 |
|
|
6'b010???: o_word <=
|
110 |
|
|
{ 3'h3, cword[31:30], r_word[30], cword[29:0] };
|
111 |
|
|
6'b10????: o_word <= { 5'b11000, r_word[30],
|
112 |
|
|
20'h00, rd_len };
|
113 |
|
|
6'b11????: o_word <= { 5'b11000, r_word[30],
|
114 |
|
|
20'h00, rd_len };
|
115 |
|
|
default: o_word <= r_word;
|
116 |
|
|
endcase
|
117 |
|
|
endmodule
|
118 |
|
|
|