OpenCores
URL https://opencores.org/ocsvn/ft816float/ft816float/trunk

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [posit_test_bench/] [intToPosit_tb.v] - Blame information for rev 45

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 45 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      intToPosit.sv
9
//    - integer to posit number converter
10
//    - parameterized width
11
//
12
//
13
// BSD 3-Clause License
14
// Redistribution and use in source and binary forms, with or without
15
// modification, are permitted provided that the following conditions are met:
16
//
17
// 1. Redistributions of source code must retain the above copyright notice, this
18
//    list of conditions and the following disclaimer.
19
//
20
// 2. Redistributions in binary form must reproduce the above copyright notice,
21
//    this list of conditions and the following disclaimer in the documentation
22
//    and/or other materials provided with the distribution.
23
//
24
// 3. Neither the name of the copyright holder nor the names of its
25
//    contributors may be used to endorse or promote products derived from
26
//    this software without specific prior written permission.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
// ============================================================================
39
//
40 36 robfinch
`timescale 1ns / 1ps
41
module intToPosit_tb_v;
42
 
43
function [31:0] log2;
44
input reg [31:0] value;
45
        begin
46
        value = value-1;
47
        for (log2=0; value>0; log2=log2+1)
48
                value = value>>1;
49
        end
50
endfunction
51
 
52
parameter N=32;
53
parameter E=8;
54
parameter Bs=log2(N);
55 45 robfinch
parameter es = 2;
56 36 robfinch
 
57
reg clk;
58
reg [5:0] cnt;
59
 
60 45 robfinch
wire [N-1:0] out, outi;
61 36 robfinch
 
62 45 robfinch
reg [N-1:0] a, a1;
63 36 robfinch
 
64
// Instantiate the Unit Under Test (UUT)
65
intToPosit #(.PSTWID(N), .es(es)) u2 (.i(a), .o(out));
66 45 robfinch
positToInt #(.PSTWID(N), .es(es)) u3 (.i(out), .o(outi));
67 36 robfinch
 
68
//FP_to_posit #(.N(32), .E(8), .es(es)) u3 (in, out3);
69
//Posit_to_FP #(.N(32), .E(8), .es(es)) u5 (out, out3);
70
 
71
 
72
        initial begin
73
          a = $urandom(1);
74
                // Initialize Inputs
75
                clk = 1;
76
                cnt = 0;
77
                // Wait 100 ns for global reset to finish
78
                #325150
79
                $fclose(outfile);
80
                $finish;
81
        end
82
 
83
always #5 clk=~clk;
84
always @(posedge clk) begin
85 45 robfinch
  a <= $urandom();
86
  cnt <= cnt + 1;
87 36 robfinch
  case (cnt)
88 45 robfinch
  1:  a <= 8192;
89
  2:  a <= 10;
90
  3:  a <= -1;
91
  4:  a <= -10;
92
  5:  a <= 100;
93
  default:   a <= $urandom();
94 36 robfinch
  endcase
95
end
96
 
97
integer outfile;
98 45 robfinch
initial outfile = $fopen("d:/cores2020/rtf64/v2/rtl/verilog/cpu/pau/test_bench/intToPosit_tvo32.txt", "wb");
99
  always @(posedge clk) begin
100
     $fwrite(outfile, "%d\t%h\t%d\n",a,out,outi);
101 36 robfinch
  end
102
 
103
endmodule
104
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.