Line 1... |
Line 1... |
|
// ============================================================================
|
|
// __
|
|
// \\__/ o\ (C) 2020 Robert Finch, Waterloo
|
|
// \ __ / All rights reserved.
|
|
// \/_// robfinch<remove>@finitron.ca
|
|
// ||
|
|
//
|
|
// intToPosit.sv
|
|
// - integer to posit number converter
|
|
// - parameterized width
|
|
//
|
|
//
|
|
// BSD 3-Clause License
|
|
// Redistribution and use in source and binary forms, with or without
|
|
// modification, are permitted provided that the following conditions are met:
|
|
//
|
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
|
// list of conditions and the following disclaimer.
|
|
//
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
// and/or other materials provided with the distribution.
|
|
//
|
|
// 3. Neither the name of the copyright holder nor the names of its
|
|
// contributors may be used to endorse or promote products derived from
|
|
// this software without specific prior written permission.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
// ============================================================================
|
|
//
|
`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
module intToPosit_tb_v;
|
module intToPosit_tb_v;
|
|
|
function [31:0] log2;
|
function [31:0] log2;
|
input reg [31:0] value;
|
input reg [31:0] value;
|
Line 11... |
Line 50... |
endfunction
|
endfunction
|
|
|
parameter N=32;
|
parameter N=32;
|
parameter E=8;
|
parameter E=8;
|
parameter Bs=log2(N);
|
parameter Bs=log2(N);
|
parameter es = 4;
|
parameter es = 2;
|
|
|
reg clk;
|
reg clk;
|
reg [5:0] cnt;
|
reg [5:0] cnt;
|
|
|
wire [N-1:0] out;
|
wire [N-1:0] out, outi;
|
|
|
reg [N-1:0] a;
|
reg [N-1:0] a, a1;
|
|
|
// Instantiate the Unit Under Test (UUT)
|
// Instantiate the Unit Under Test (UUT)
|
intToPosit #(.PSTWID(N), .es(es)) u2 (.i(a), .o(out));
|
intToPosit #(.PSTWID(N), .es(es)) u2 (.i(a), .o(out));
|
|
positToInt #(.PSTWID(N), .es(es)) u3 (.i(out), .o(outi));
|
|
|
//FP_to_posit #(.N(32), .E(8), .es(es)) u3 (in, out3);
|
//FP_to_posit #(.N(32), .E(8), .es(es)) u3 (in, out3);
|
//Posit_to_FP #(.N(32), .E(8), .es(es)) u5 (out, out3);
|
//Posit_to_FP #(.N(32), .E(8), .es(es)) u5 (out, out3);
|
|
|
|
|
Line 40... |
Line 80... |
$finish;
|
$finish;
|
end
|
end
|
|
|
always #5 clk=~clk;
|
always #5 clk=~clk;
|
always @(posedge clk) begin
|
always @(posedge clk) begin
|
a = $urandom();
|
a <= $urandom();
|
cnt = cnt + 1;
|
cnt <= cnt + 1;
|
case (cnt)
|
case (cnt)
|
1: a = 8192;
|
1: a <= 8192;
|
2: a = 10;
|
2: a <= 10;
|
3: a = -1;
|
3: a <= -1;
|
4: a = -10;
|
4: a <= -10;
|
default: a = $urandom();
|
5: a <= 100;
|
|
default: a <= $urandom();
|
endcase
|
endcase
|
end
|
end
|
|
|
integer outfile;
|
integer outfile;
|
initial outfile = $fopen("d:/cores5/Gambit/v5/rtl/cpu/fpu/test_bench/intToPosit_tvo32.txt", "wb");
|
initial outfile = $fopen("d:/cores2020/rtf64/v2/rtl/verilog/cpu/pau/test_bench/intToPosit_tvo32.txt", "wb");
|
always @(negedge clk) begin
|
always @(posedge clk) begin
|
$fwrite(outfile, "%d\t%h\n",a,out);
|
$fwrite(outfile, "%d\t%h\t%d\n",a,out,outi);
|
end
|
end
|
|
|
endmodule
|
endmodule
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|