mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
More divider cleanup
This commit is contained in:
parent
5e6b2490cb
commit
0c08a7c05c
35
wally-pipelined/src/generic/adder.sv
Normal file
35
wally-pipelined/src/generic/adder.sv
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
///////////////////////////////////////////
|
||||||
|
// adder.sv
|
||||||
|
//
|
||||||
|
// Written: David_Harris@hmc.edu 2 October 2021
|
||||||
|
// Modified:
|
||||||
|
//
|
||||||
|
// Purpose: Adder
|
||||||
|
//
|
||||||
|
// A component of the Wally configurable RISC-V project.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
|
||||||
|
// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
|
||||||
|
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
|
||||||
|
// is furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||||
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||||
|
// OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
///////////////////////////////////////////
|
||||||
|
|
||||||
|
`include "wally-config.vh"
|
||||||
|
|
||||||
|
module adder #(parameter WIDTH=8) (
|
||||||
|
input logic [WIDTH-1:0] a, b,
|
||||||
|
output logic [WIDTH-1:0] y);
|
||||||
|
|
||||||
|
assign y = a + b;
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
|
@ -278,13 +278,14 @@ module otf #(parameter WIDTH=8)
|
|||||||
assign QMstar = R1Q;
|
assign QMstar = R1Q;
|
||||||
|
|
||||||
endmodule // otf8
|
endmodule // otf8
|
||||||
|
/*
|
||||||
module adder #(parameter WIDTH=8) (input logic [WIDTH-1:0] a, b,
|
module adder #(parameter WIDTH=8) (input logic [WIDTH-1:0] a, b,
|
||||||
output logic [WIDTH-1:0] y);
|
output logic [WIDTH-1:0] y);
|
||||||
|
|
||||||
assign y = a + b;
|
assign y = a + b;
|
||||||
|
|
||||||
endmodule // adder
|
endmodule // adder
|
||||||
|
*/
|
||||||
|
|
||||||
module fa (input logic a, b, c, output logic sum, carry);
|
module fa (input logic a, b, c, output logic sum, carry);
|
||||||
|
|
||||||
|
@ -61,15 +61,12 @@ module intdivrestoring (
|
|||||||
flopenrc #(1) SignXMReg(clk, reset, FlushM, ~StallM, SignXE, SignXM);
|
flopenrc #(1) SignXMReg(clk, reset, FlushM, ~StallM, SignXE, SignXM);
|
||||||
flopenrc #(`XLEN) XSavedMReg(clk, reset, FlushM, ~StallM, XSavedE, XSavedM); // is this truly necessary?
|
flopenrc #(`XLEN) XSavedMReg(clk, reset, FlushM, ~StallM, XSavedE, XSavedM); // is this truly necessary?
|
||||||
|
|
||||||
// Take absolute value for signed operations
|
// Take absolute value for signed operations, and negate D to handle subtraction in divider stages
|
||||||
neg #(`XLEN) negd(DSavedE, DnE);
|
neg #(`XLEN) negd(DSavedE, DnE);
|
||||||
mux2 #(`XLEN) dabsmux(DnE, DSavedE, SignedDivideE & SignDE, DAbsB); // take absolute value for signed operations, and negate for subtraction setp
|
mux2 #(`XLEN) dabsmux(DnE, DSavedE, SignedDivideE & SignDE, DAbsB); // take absolute value for signed operations, and negate for subtraction setp
|
||||||
neg #(`XLEN) negx(XSavedE, XnE);
|
neg #(`XLEN) negx(XSavedE, XnE);
|
||||||
mux2 #(`XLEN) xabsmux(XSavedE, XnE, SignedDivideE & SignXE, Xinit); // need original X as remainder if doing divide by 0
|
mux2 #(`XLEN) xabsmux(XSavedE, XnE, SignedDivideE & SignXE, Xinit); // need original X as remainder if doing divide by 0
|
||||||
|
|
||||||
// Negate D for subtraction
|
|
||||||
//assign DAbsB = ~Din;
|
|
||||||
// *** merge this into dabsmux if possible
|
|
||||||
// Put suffixes on Xinit, init->DivInitE, Wn, XQn
|
// Put suffixes on Xinit, init->DivInitE, Wn, XQn
|
||||||
|
|
||||||
// initialization multiplexers on first cycle of operation (one cycle after start is asserted)
|
// initialization multiplexers on first cycle of operation (one cycle after start is asserted)
|
||||||
|
@ -33,7 +33,8 @@ module intdivrestoringstep(
|
|||||||
logic qi, qib;
|
logic qi, qib;
|
||||||
|
|
||||||
assign {WShift, XQOut} = {W[`XLEN-2:0], XQ, qi};
|
assign {WShift, XQOut} = {W[`XLEN-2:0], XQ, qi};
|
||||||
assign {qib, WPrime} = {1'b0, WShift} + {1'b1, DAbsB} /*+ 1*/; // subtractor, carry out determines quotient bit ***replace with add
|
adder #(`XLEN+1) wdsub({1'b0, WShift}, {1'b1, DAbsB}, {qib, WPrime});
|
||||||
|
//assign {qib, WPrime} = {1'b0, WShift} + {1'b1, DAbsB}; // effective subtractor, carry out determines quotient bit
|
||||||
assign qi = ~qib;
|
assign qi = ~qib;
|
||||||
mux2 #(`XLEN) wrestoremux(WShift, WPrime, qi, WOut);
|
mux2 #(`XLEN) wrestoremux(WShift, WPrime, qi, WOut);
|
||||||
endmodule
|
endmodule
|
||||||
|
Loading…
Reference in New Issue
Block a user