Skip to content
Snippets Groups Projects
Commit 11e594f0 authored by XiaoanHe's avatar XiaoanHe
Browse files

Data Extraction Debugged

parent 64cbdfcc
Branches
No related tags found
1 merge request!117/11/2022 23/11/2022
Showing
with 2541 additions and 33 deletions
{H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Posit_Extraction.sv} {1 {vlog -work work -sv -stats=none {H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Posit_Extraction.sv}
Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
-- Compiling package Posit_Extraction_sv_unit
-- Compiling module Data_Extraction
Top level modules:
Data_Extraction
} {} {}} {H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Leading_Bit_Detector.sv} {1 {vlog -work work -sv -stats=none {H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Leading_Bit_Detector.sv}
Model Technology ModelSim PE Student Edition vlog 10.4a Compiler 2015.03 Apr 7 2015
-- Compiling module Leading_Bit_Detector
Top level modules:
Leading_Bit_Detector
} {} {}}
This diff is collapsed.
/////////////////////////////////////////////////////////////////////
// Design unit: Leading Bit Detector
// :
// File name : Leading_Bit_Detector.sv
// :
// Description: Given the first bit of the regime bit
// find the first bit different from it
// :
// Limitations: None
// :
// System : SystemVerilog IEEE 1800-2005
// :
// Author : Xiaoan He (Jasper)
// : xh2g20@ecs.soton.ac.uk
//
// Revision : Version 1.0 21/11/2022
/////////////////////////////////////////////////////////////////////
module Leading_Bit_Detector #( parameter N = 8, parameter ES = 3, parameter RS = log2(N))
(
input logic signed [N-2:0] InRemain,
output logic signed [RS:0] EndPosition,
output logic RegimeCheck
);
function [31:0] log2;
input reg [31:0] value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
//logic RegimeCheck;
int i;
always_comb
begin
RegimeCheck = InRemain[N-2]; //the MSB of InRemain (In[6])is the number to be checked
EndPosition = '0;
EndPosition = EndPosition + 1'b1; // initial EP starts from InRemain[1] as InRemain[0] is RC
for(i = 1; i < (N-2); i++)
begin
/*
compareing MSB of InRemain to the follwing bits
until the different bit turns up
*/
if (RegimeCheck == InRemain[((N-2)-i)])
//begin
EndPosition = EndPosition + 1'b1;
//end
else
break;
end
end
endmodule
\ No newline at end of file
/////////////////////////////////////////////////////////////////////
// Design unit: DataExtraction
// :
// File name : Posit_Extraction.sv
// :
// Description: Extracting posit element from n bits binary number
// :
// Limitations: None
// :
// System : SystemVerilog IEEE 1800-2005
// :
// Author : Xiaoan He (Jasper)
// : xh2g20@ecs.soton.ac.uk
//
// Revision : Version 1.0 19/11/2022
/////////////////////////////////////////////////////////////////////
// `ifndef log_2
// `define log_2
// `include "log_2.sv"
function [31:0] log2;
input reg [31:0] value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
module Data_Extraction #( parameter N = 8, parameter ES = 3, parameter RS = log2(N))
(
input logic signed [N-1:0] In,
output logic Sign,
output logic signed [RS-1:0] RegimeValue,
output logic [ES-1:0] Exponent,
output logic [N-ES+2:0] Mantissa
);
logic signed [N-2:0] InRemain;
logic RegimeCheck;
logic [RS:0] EndPosition;
logic signed [N-2:0] ShiftedRemain;
int i;
Leading_Bit_Detector #(.N(N), .ES(ES)) LBD1 (.*);
always_comb
begin
// Sign Bit Extraction
Sign = In[N-1];
// if sign bit is true, then 2's compliment
InRemain = Sign ? (~In[N-2:0] + 1'b1) : In[N-2:0];
// Regime Bits Extraction
if(RegimeCheck == 1'b1)
RegimeValue = EndPosition - 1;
else if (RegimeCheck == 0)
RegimeValue = -EndPosition;
//Exponent Bits Extraction
ShiftedRemain = InRemain << (EndPosition + 1 );
Exponent = ShiftedRemain[N-1:((N-1)-ES)];
//Mantissa Bits Extraction
Mantissa = {1'b1, ShiftedRemain[N-ES-2]};
end
endmodule
\ No newline at end of file
/////////////////////////////////////////////////////////////////////
// Design unit: TestDataExtraction
// :
// File name : testExtract.sv
// :
// Description: Testbench for extracting posit element
// from n bits binary number
// :
// Limitations: None
// :
// System : SystemVerilog IEEE 1800-2005
// :
// Author : Xiaoan He (Jasper)
// : xh2g20@ecs.soton.ac.uk
//
// Revision : Version 1.0 21/11/2022
/////////////////////////////////////////////////////////////////////
function [31:0] log2;
input reg [31:0] value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
module Test_Data_Extraction;
parameter N = 8, RS = log2(N), ES = 3;
//input logic
logic signed [N-1:0]In;
//output logic
logic Sign;
logic signed [RS:0] RegimeValue;
logic [ES-1:0] Exponent;
logic [N-ES+2:0] Mantissa;
Data_Extraction #(.N(N), .ES(ES)) extract1 (.*);
initial
begin
// initial input is nothing
#10ns In = 8'b0_0000000;
// sign=0 regime=10 exponent=1001,mant=1
#50ns In = 8'b1_01_1000_0;
// 0_10_1000_0
end
endmodule
\ No newline at end of file
/////////////////////////////////////////////////////////////////////
// Design unit: Logarithm Base 2
// :
// File name : log_2.sv
// :
// Description: Just be used to compute the Regime Size (RS)
// : which is equal to log2(the number of total bits)
// :
// Limitations: None
// :
// System : SystemVerilog IEEE 1800-2005
// :
// Author : Xiaoan He (Jasper)
// : xh2g20@ecs.soton.ac.uk
//
// Revision : Version 1.0 19/11/2022
/////////////////////////////////////////////////////////////////////
#ifndef log_2
#define log_2
function [31:0] log2;
input logic [31:0] value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
\ No newline at end of file
m255
K4
z2
13
!s112 1.1
!i10d 8192
!i10e 25
!i10f 100
cModel Technology
dd:/modelsim/examples
vData_Extraction
Z0 DXx6 sv_std 3 std 0 22 WmjPaeP=7F5?QFXzJ>D[Q2
DXx4 work 24 Posit_Extraction_sv_unit 0 22 Ik5d90Sbo;Z_5B[6;nN?c3
!i10b 1
Z1 VDg1SIo80bB@j0V0VzS_@n1
r1
!s85 0
31
!s100 :9jDL8fgjON>>ZZzI=UH]1
IX?9gdS@<E5GRYXNjTL2OY0
!s105 Posit_Extraction_sv_unit
S1
Z2 dH:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction
Z3 w1669058108
Z4 8H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Posit_Extraction.sv
Z5 FH:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Posit_Extraction.sv
L0 31
Z6 OP;L;10.4a;61
Z7 !s108 1669058622.000000
Z8 !s107 H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Posit_Extraction.sv|
Z9 !s90 -reportprogress|300|-work|work|-sv|-stats=none|H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Posit_Extraction.sv|
!s101 -O0
!i113 1
Z10 o-work work -sv -L mtiAvm -L mtiRnm -L mtiOvm -L mtiUvm -L mtiUPF -L infact -O0
n@data_@extraction
vLeading_Bit_Detector
R0
!i10b 1
R1
r1
!s85 0
31
!s100 RGaB4Z:d;NgXmE1MinB4=3
I6CV7iYKKRNiPVe<:Jd7OZ3
!s105 Leading_Bit_Detector_sv_unit
S1
R2
w1669057534
8H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Leading_Bit_Detector.sv
FH:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Leading_Bit_Detector.sv
L0 19
R6
R7
!s107 H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Leading_Bit_Detector.sv|
!s90 -reportprogress|300|-work|work|-sv|-stats=none|H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Leading_Bit_Detector.sv|
!s101 -O0
!i113 1
R10
n@leading_@bit_@detector
XPosit_Extraction_sv_unit
R0
!i10b 1
VIk5d90Sbo;Z_5B[6;nN?c3
r1
!s85 0
31
!s100 6V1A`S@cEfY:22eJ`[9ie0
IIk5d90Sbo;Z_5B[6;nN?c3
!i103 1
S1
R2
R3
R4
R5
L0 22
R6
R7
R8
R9
!s101 -O0
!i113 1
R10
n@posit_@extraction_sv_unit
vTest_Data_Extraction
R0
DXx4 work 28 Test_Data_Extraction_sv_unit 0 22 eO`G7lR:hj`hW^[elH1aV3
R1
r1
!s85 0
31
!i10b 1
!s100 3RPk2ZiH_2bbhhGLnk:DO1
I63^h:jSFcYooFdfcf]]f60
!s105 Test_Data_Extraction_sv_unit
S1
R2
Z11 w1669058862
Z12 8H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Test_Data_Extraction.sv
Z13 FH:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Test_Data_Extraction.sv
L0 27
R6
Z14 !s108 1669058866.000000
Z15 !s107 H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Test_Data_Extraction.sv|
Z16 !s90 -reportprogress|300|-work|work|-sv|-stats=none|H:/INDIVIDUAL PROJECT/Posit/Individual_Project/Data Extraction/Test_Data_Extraction.sv|
!s101 -O0
!i113 1
R10
n@test_@data_@extraction
XTest_Data_Extraction_sv_unit
R0
VeO`G7lR:hj`hW^[elH1aV3
r1
!s85 0
31
!i10b 1
!s100 DNiobLRHe5470J9VAIX`k1
IeO`G7lR:hj`hW^[elH1aV3
!i103 1
S1
R2
R11
R12
R13
L0 18
R6
R14
R15
R16
!s101 -O0
!i113 1
R10
n@test_@data_@extraction_sv_unit
File added
File added
File added
File added
m255
K4
z0
cModel Technology
......@@ -28,49 +28,54 @@ function [31:0] log2;
end
endfunction
Module Data_Extraction #( parameter N = 8, parameter ES = 3, parameter RS = log2(N))
module Data_Extraction #( parameter N = 8, parameter ES = 3, parameter RS = log2(N))
(
input logic signed [N-1:0] In,
output logic Sign,
output logic signed [RS-1:0] Regime,
output logic signed [RS-1:0] RegimeValue,
output logic [ES-1:0] Exponent,
output logic [N-ES+2:0] Mantissa
)
);
// Sign Bit Extraction
logic signed [N-2:0] InRemain;
always_comb
begin
// Sign Bit Extraction
logic signed [N-2:0] InRemain;
Sign = In[N-1];
if(Sign = 1) // if sign bit is 1, then 2's compliment
InRemain = ~In[N-2:0] + 1'b1;
else
InRemain = In[N-2:0];
Sign = In[N-1];
if(Sign = 1) // if sign bit is 1, then 2's compliment
InRemain = ~In[N-2:0] + 1'b1;
else
InRemain = In[N-2:0];
// Regime Bits Extraction
logic RegimeCheck = InRemain{N-2}; //the MSB of InRemain is the number to be checked
// Regime Bits Extraction
logic RegimeCheck = InRemain[N-2]; //the MSB of InRemain (In[6])is the number to be checked
logic [RS-1:0] EndPosition = 1; // initial EP starts from 2nd element
logic [RS-1:0] EndPosition = 1; // initial EP starts from InRemain[1] as InRemain[0] is RC
for(int i = 1; i < N-2; i++)
begin
/*
compareing MSB of InRemain to the follwing bits
until the different bit turns up
*/
if(RegimeCheck == InRemain[((N-2)-i)])
EndPosition = EndPositon + 1;
else
break;
end
for(int i = 1; i < N-2; i++)
begin
/*
compareing MSB of InRemain to the follwing bits
until the different bit turns up
*/
if(RegimeCheck == InRemain[((N-2)-i)])
EndPosition = EndPositon + 1;
else
break;
end
// logic RegimeValue;
if(RegimeCheck == 1)
RegimeValue = EndPosition - 1;
else if (RegimeCheck == 0)
RegimeValue = -EndPositon;
// if(RegimeCheck = 1)
// RegimeValue = EndPosition - 1;
// else
// RegimeValue = -EndPositon;
//Exponent Bits Extraction
logic signed [N-2:0] ShiftedRemain;
ShiftedRemain = InRemain << (EndPosition + 1 );
Exponent = ShiftedRemain[N-1:((N-1)-ES)];
// Exponent Bits Extraction
logic signed [N-2:0] ShiftedRemain;
ShiftedRemain = InRemain << (EndPosition + )
//Mantissa Bits Extraction
Mantissa = {1'b1, ShiftedRemain[N-ES-2]};
end
endmodule
\ No newline at end of file
/////////////////////////////////////////////////////////////////////
// Design unit: TestDataExtraction
// :
// File name : testExtract.sv
// :
// Description: Testbench for extracting posit element
// from n bits binary number
// :
// Limitations: None
// :
// System : SystemVerilog IEEE 1800-2005
// :
// Author : Xiaoan He (Jasper)
// : xh2g20@ecs.soton.ac.uk
//
// Revision : Version 1.0 14/11/2022
/////////////////////////////////////////////////////////////////////
module testExtract;
function [31:0] log2;
input reg [31:0] value;
begin
value = value-1;
for (log2=0; value>0; log2=log2+1)
value = value>>1;
end
endfunction
parameter N = 8, Bs = log2(N), es = 3;
//input logic
logic signed [N-1:0]In;
//output logic
logic Sign;
logic [ES-1:0]Exponent;
logic signed [Es-1:0]Regime;
logic [N-ES+2:0]Mantissa;
Data_Extraction extract1 (.*);
initial
begin
// initial input is nothing
#10ns in = 8'b0_0000000;
// sign=0 regime=10 exponent=1001,mant=1
#50ns in = 8'b1_01_1000_0;
// 0_10_1000_0
end
endmodule
\ No newline at end of file
module data_extract #(parameter N=8, parameter Bs=log2(N), parameter es=4, parameter Rmax = N-1, parameter Rmin = -(N-1))
module data_extract #(parameter N=8, parameter Bs=log2(N),
parameter es=4, parameter Rmax = N-1, parameter Rmin = -(N-1))
(input logic signed [N-1:0] in,
output logic Sin,
output logic [es-1:0] exp,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment