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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [icarus_version/] [rtl/] [Module_VectorALU.v] - Diff between revs 178 and 188

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 178 Rev 188
`timescale 1ns / 1ps
`timescale 1ns / 1ps
`include "aDefinitions.v"
`include "aDefinitions.v"
`ifdef VERILATOR
`ifdef VERILATOR
`include "Module_Swizzle.v"
`include "Module_Swizzle.v"
`include "Module_ArithmeticComparison.v"
`include "Module_ArithmeticComparison.v"
`include "Module_RadixRMul.v"
`include "Module_RadixRMul.v"
`include "Module_FixedPointDivision.v"
`include "Module_FixedPointDivision.v"
`include "Module_FixedPointSquareRoot.v"
`include "Module_FixedPointSquareRoot.v"
`endif
`endif
/**********************************************************************************
/**********************************************************************************
Theia, Ray Cast Programable graphic Processing Unit.
Theia, Ray Cast Programable graphic Processing Unit.
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
Copyright (C) 2010  Diego Valverde (diego.valverde.g@gmail.com)
 
 
This program is free software; you can redistribute it and/or
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
of the License, or (at your option) any later version.
 
 
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
GNU General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 
***********************************************************************************/
***********************************************************************************/
 
 
 
 
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
module VectorALU
module VectorALU
(
(
 input wire                                   Clock,
 input wire                                   Clock,
 input wire                                   Reset,
 input wire                                   Reset,
 input  wire[`INSTRUCTION_OP_LENGTH-1:0]      iOperation,
 input  wire[`INSTRUCTION_OP_LENGTH-1:0]      iOperation,
 input  wire[`WIDTH-1:0]                      iChannel_Ax,
 input  wire[`WIDTH-1:0]                      iChannel_Ax,
 input  wire[`WIDTH-1:0]                      iChannel_Bx,
 input  wire[`WIDTH-1:0]                      iChannel_Bx,
 input  wire[`WIDTH-1:0]                      iChannel_Ay,
 input  wire[`WIDTH-1:0]                      iChannel_Ay,
 input  wire[`WIDTH-1:0]                      iChannel_By,
 input  wire[`WIDTH-1:0]                      iChannel_By,
 input  wire[`WIDTH-1:0]                      iChannel_Az,
 input  wire[`WIDTH-1:0]                      iChannel_Az,
 input  wire[`WIDTH-1:0]                      iChannel_Bz,
 input  wire[`WIDTH-1:0]                      iChannel_Bz,
 output wire [`WIDTH-1:0]                     oResultA,
 output wire [`WIDTH-1:0]                     oResultA,
 output wire [`WIDTH-1:0]                     oResultB,
 output wire [`WIDTH-1:0]                     oResultB,
 output wire [`WIDTH-1:0]                     oResultC,
 output wire [`WIDTH-1:0]                     oResultC,
 input  wire                                  iInputReady,
 input  wire                                  iInputReady,
 output reg                                   oBranchTaken,
 output reg                                   oBranchTaken,
 output reg                                   oBranchNotTaken,
 output reg                                   oBranchNotTaken,
 output reg                                   oReturnFromSub,
 output reg                                   oReturnFromSub,
 input wire [`ROM_ADDRESS_WIDTH-1:0]          iCurrentIP,
 input wire [`ROM_ADDRESS_WIDTH-1:0]          iCurrentIP,
 
 
 //Connections to the O Memory
 //Connections to the O Memory
 output wire [`DATA_ROW_WIDTH-1:0]            oOMEMWriteAddress,
 output wire [`DATA_ROW_WIDTH-1:0]            oOMEMWriteAddress,
 output wire [`DATA_ROW_WIDTH-1:0]            oOMEMWriteData,
 output wire [`DATA_ROW_WIDTH-1:0]            oOMEMWriteData,
 output wire                                  oOMEM_WriteEnable,
 output wire                                  oOMEM_WriteEnable,
 //Connections to the R Memory
 //Connections to the R Memory
 output wire [`DATA_ROW_WIDTH-1:0]            oTMEMReadAddress,
 output wire [`DATA_ROW_WIDTH-1:0]            oTMEMReadAddress,
 input wire [`DATA_ROW_WIDTH-1:0]             iTMEMReadData,
 input wire [`DATA_ROW_WIDTH-1:0]             iTMEMReadData,
 input wire                                   iTMEMDataAvailable,
 input wire                                   iTMEMDataAvailable,
 output wire                                  oTMEMDataRequest,
 output wire                                  oTMEMDataRequest,
 output reg                                   OutputReady
 output reg                                   OutputReady
 
 
);
);
 
 
 
 
 
 
 
 
 
 
wire wMultiplcationUnscaled;
wire wMultiplcationUnscaled;
assign wMultiplcationUnscaled = (iOperation == `IMUL) ? 1'b1 : 1'b0;
assign wMultiplcationUnscaled = (iOperation == `IMUL) ? 1'b1 : 1'b0;
 
 
//--------------------------------------------------------------
//--------------------------------------------------------------
 
 
reg [7:0]  InputReadyA,InputReadyB,InputReadyC;
reg [7:0]  InputReadyA,InputReadyB,InputReadyC;
 
 
//------------------------------------------------------
//------------------------------------------------------
/*
/*
 This is the block that takes care of all tha arithmetic
 This is the block that takes care of all tha arithmetic
 comparisons. Supported operations are <,>,<=,>=,==,!=
 comparisons. Supported operations are <,>,<=,>=,==,!=
 
 
*/
*/
//------------------------------------------------------
//------------------------------------------------------
reg [`WIDTH-1:0] wMultiplicationA_Ax;
reg [`WIDTH-1:0] wMultiplicationA_Ax;
reg  [`WIDTH-1:0] wMultiplicationA_Bx;
reg  [`WIDTH-1:0] wMultiplicationA_Bx;
wire [`LONG_WIDTH-1:0] wMultiplicationA_Result;
wire [`LONG_WIDTH-1:0] wMultiplicationA_Result;
wire  wMultiplicationA_InputReady;
wire  wMultiplicationA_InputReady;
wire wMultiplicationA_OutputReady;
wire wMultiplicationA_OutputReady;
wire wMultiplicationOutputReady, wMultiplicationOutputReadyA,
wire wMultiplicationOutputReady, wMultiplicationOutputReadyA,
wMultiplicationOutputReadyB,wMultiplicationOutputReadyC,wMultiplicationOutputReadyD;
wMultiplicationOutputReadyB,wMultiplicationOutputReadyC,wMultiplicationOutputReadyD;
 
 
wire wAddSubAOutputReady,wAddSubBOutputReady,wAddSubCOutputReady;
wire wAddSubAOutputReady,wAddSubBOutputReady,wAddSubCOutputReady;
wire [`INSTRUCTION_OP_LENGTH-1:0] wOperation;
wire [`INSTRUCTION_OP_LENGTH-1:0] wOperation;
wire [`WIDTH-1:0] wSwizzleOutputX,wSwizzleOutputY,wSwizzleOutputZ;
wire [`WIDTH-1:0] wSwizzleOutputX,wSwizzleOutputY,wSwizzleOutputZ;
 
 
//--------------------------------------------------------------------
//--------------------------------------------------------------------
reg [`WIDTH-1:0] ResultA,ResultB,ResultC;
reg [`WIDTH-1:0] ResultA,ResultB,ResultC;
 
 
//Output Flip Flops,
//Output Flip Flops,
//This flip flop will control the outputs so that the
//This flip flop will control the outputs so that the
//values of the outputs change ONLY when when there is 
//values of the outputs change ONLY when when there is 
//a positive edge of OutputReady
//a positive edge of OutputReady
 
 
FFD32_POSEDGE ResultAFFD
FFD32_POSEDGE ResultAFFD
(
(
 .Clock( OutputReady ),
 .Clock( OutputReady ),
 .D( ResultA ),
 .D( ResultA ),
 .Q( oResultA )
 .Q( oResultA )
);
);
 
 
FFD32_POSEDGE ResultBFFD
FFD32_POSEDGE ResultBFFD
(
(
 .Clock( OutputReady ),
 .Clock( OutputReady ),
 .D( ResultB ),
 .D( ResultB ),
 .Q( oResultB )
 .Q( oResultB )
);
);
 
 
FFD32_POSEDGE ResultCFFD
FFD32_POSEDGE ResultCFFD
(
(
 .Clock( OutputReady ),
 .Clock( OutputReady ),
 .D( ResultC ),
 .D( ResultC ),
 .Q( oResultC )
 .Q( oResultC )
);
);
//--------------------------------------------------------------------
//--------------------------------------------------------------------
 
 
 
 
 
 
Swizzle3D Swizzle1
Swizzle3D Swizzle1
(
(
 .Source0_X( iChannel_Bx ),
 .Source0_X( iChannel_Bx ),
 .Source0_Y( iChannel_By ),
 .Source0_Y( iChannel_By ),
 .Source0_Z( iChannel_Bz ),
 .Source0_Z( iChannel_Bz ),
 .iOperation( iChannel_Ax ),
 .iOperation( iChannel_Ax ),
 
 
 .SwizzleX( wSwizzleOutputX ),
 .SwizzleX( wSwizzleOutputX ),
 .SwizzleY( wSwizzleOutputY ),
 .SwizzleY( wSwizzleOutputY ),
 .SwizzleZ( wSwizzleOutputZ )
 .SwizzleZ( wSwizzleOutputZ )
);
);
//---------------------------------------------------------------------
//---------------------------------------------------------------------
wire [`LONG_WIDTH-1:0] wModulus2N_ResultA,wModulus2N_ResultB,wModulus2N_ResultC;
wire [`LONG_WIDTH-1:0] wModulus2N_ResultA,wModulus2N_ResultB,wModulus2N_ResultC;
 
 
//---------------------------------------------------------------------(
//---------------------------------------------------------------------(
 
 
wire IOW_Operation,wOMEM_We;
wire IOW_Operation,wOMEM_We;
assign IOW_Operation = (iOperation == `OMWRITE);
assign IOW_Operation = (iOperation == `OMWRITE);
 
 
always @ ( * )
always @ ( * )
begin
begin
 if (iOperation == `RET)
 if (iOperation == `RET)
  oReturnFromSub = OutputReady;
  oReturnFromSub = OutputReady;
 else
 else
  oReturnFromSub = 1'b0;
  oReturnFromSub = 1'b0;
 
 
end
end
 
 
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1_AWE
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1_AWE
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset),
 .Reset( Reset),
 .Enable( 1'b1 ),
 .Enable( 1'b1 ),
 .D( IOW_Operation ),
 .D( IOW_Operation ),
 .Q( wOMEM_We )
 .Q( wOMEM_We )
);
);
 
 
assign oOMEM_WriteEnable = wOMEM_We & IOW_Operation;
assign oOMEM_WriteEnable = wOMEM_We & IOW_Operation;
 
 
FFD_POSEDGE_SYNCRONOUS_RESET # ( `DATA_ROW_WIDTH ) FFD1_A
FFD_POSEDGE_SYNCRONOUS_RESET # ( `DATA_ROW_WIDTH ) FFD1_A
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset),
 .Reset( Reset),
 .Enable( iInputReady ),
 .Enable( iInputReady ),
 .D( {iChannel_Ax,iChannel_Ay,iChannel_Az} ),
 .D( {iChannel_Ax,iChannel_Ay,iChannel_Az} ),
 .Q( oOMEMWriteAddress)
 .Q( oOMEMWriteAddress)
);
);
FFD_POSEDGE_SYNCRONOUS_RESET # ( `DATA_ROW_WIDTH ) FFD2_B
FFD_POSEDGE_SYNCRONOUS_RESET # ( `DATA_ROW_WIDTH ) FFD2_B
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset),
 .Reset( Reset),
 .Enable( iInputReady ),
 .Enable( iInputReady ),
 .D( {iChannel_Bx,iChannel_By,iChannel_Bz} ),
 .D( {iChannel_Bx,iChannel_By,iChannel_Bz} ),
 .Q( oOMEMWriteData )
 .Q( oOMEMWriteData )
);
);
 
 
 
 
 
 
wire wTMReadOutputReady;
wire wTMReadOutputReady;
assign wTMReadOutputReady = iTMEMDataAvailable;
assign wTMReadOutputReady = iTMEMDataAvailable;
/*
/*
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1_ARE
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1_ARE
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset),
 .Reset( Reset),
 .Enable( 1'b1 ),
 .Enable( 1'b1 ),
 .D( iTMEMDataAvailable ),
 .D( iTMEMDataAvailable ),
 .Q( wTMReadOutputReady )
 .Q( wTMReadOutputReady )
);
);
*/
*/
//assign oTMEMReadAddress = {iChannel_Ax,iChannel_Ay,iChannel_Az};
//assign oTMEMReadAddress = {iChannel_Ax,iChannel_Ay,iChannel_Az};
 
 
//We wait 1 clock cycle before be send the data read request, because
//We wait 1 clock cycle before be send the data read request, because
//we need to lathc the values at the output
//we need to lathc the values at the output
 
 
wire wOpTRead;
wire wOpTRead;
assign wOpTRead = ( iOperation == `TMREAD ) ? 1'b1 : 1'b0;
assign wOpTRead = ( iOperation == `TMREAD ) ? 1'b1 : 1'b0;
wire wTMEMRequest;
wire wTMEMRequest;
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1_ARE123
FFD_POSEDGE_SYNCRONOUS_RESET # ( 1 ) FFD1_ARE123
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset),
 .Reset( Reset),
 .Enable( 1'b1 ),
 .Enable( 1'b1 ),
 .D( wOpTRead ),
 .D( wOpTRead ),
 .Q( wTMEMRequest )
 .Q( wTMEMRequest )
);
);
assign oTMEMDataRequest = wTMEMRequest & wOpTRead;
assign oTMEMDataRequest = wTMEMRequest & wOpTRead;
FFD_POSEDGE_SYNCRONOUS_RESET # ( `DATA_ROW_WIDTH ) FFD2_B445
FFD_POSEDGE_SYNCRONOUS_RESET # ( `DATA_ROW_WIDTH ) FFD2_B445
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset),
 .Reset( Reset),
 .Enable( iInputReady & wOpTRead ),
 .Enable( iInputReady & wOpTRead ),
 .D( {iChannel_Ax,iChannel_Ay,iChannel_Az} ),
 .D( {iChannel_Ax,iChannel_Ay,iChannel_Az} ),
 .Q( oTMEMReadAddress )
 .Q( oTMEMReadAddress )
);
);
 
 
/*
/*
 This MUX will select the apropiated X,Y or Z depending on
 This MUX will select the apropiated X,Y or Z depending on
 wheter it is XYZ iOperation. This gets defined by the bits 3 and 4
 wheter it is XYZ iOperation. This gets defined by the bits 3 and 4
 of iOperation, and only applies for oBranchTaken and Store operations.
 of iOperation, and only applies for oBranchTaken and Store operations.
*/
*/
 
 
wire      wArithmeticComparison_Result;
wire      wArithmeticComparison_Result;
wire      ArithmeticComparison_InputReady;
wire      ArithmeticComparison_InputReady;
wire      ArithmeticComparison_OutputReady;
wire      ArithmeticComparison_OutputReady;
reg[`WIDTH-1:0]  ArithmeticComparison_A,ArithmeticComparison_B;
reg[`WIDTH-1:0]  ArithmeticComparison_A,ArithmeticComparison_B;
 
 
 
 
always @ ( * )
always @ ( * )
begin
begin
 case ( {iOperation[4],iOperation[3]} )
 case ( {iOperation[4],iOperation[3]} )
  2'b01:   ArithmeticComparison_A = iChannel_Ax;
  2'b01:   ArithmeticComparison_A = iChannel_Ax;
  2'b10:   ArithmeticComparison_A = iChannel_Ay;
  2'b10:   ArithmeticComparison_A = iChannel_Ay;
  2'b11:  ArithmeticComparison_A = iChannel_Az;
  2'b11:  ArithmeticComparison_A = iChannel_Az;
  default: ArithmeticComparison_A = 0; //Should never happen
  default: ArithmeticComparison_A = 0; //Should never happen
 endcase
 endcase
end
end
//---------------------------------------------------------------------
//---------------------------------------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case ( {iOperation[4],iOperation[3]} )
 case ( {iOperation[4],iOperation[3]} )
  2'b01:   ArithmeticComparison_B = iChannel_Bx;
  2'b01:   ArithmeticComparison_B = iChannel_Bx;
  2'b10:   ArithmeticComparison_B = iChannel_By;
  2'b10:   ArithmeticComparison_B = iChannel_By;
  2'b11:  ArithmeticComparison_B = iChannel_Bz;
  2'b11:  ArithmeticComparison_B = iChannel_Bz;
  default: ArithmeticComparison_B = 0; //Should never happen
  default: ArithmeticComparison_B = 0; //Should never happen
 endcase
 endcase
end
end
 
 
//---------------------------------------------------------------------
//---------------------------------------------------------------------
/*
/*
 The onbly instance of Aritmetic comparison in the ALU,
 The onbly instance of Aritmetic comparison in the ALU,
 ArithmeticComparison operations matches the 3 LSB of
 ArithmeticComparison operations matches the 3 LSB of
 Global ALU iOperation for oBranchTaken Instruction family
 Global ALU iOperation for oBranchTaken Instruction family
*/
*/
 
 
assign ArithmeticComparison_InputReady = iInputReady;
assign ArithmeticComparison_InputReady = iInputReady;
 
 
wire wArithmeticComparisonResult;
wire wArithmeticComparisonResult;
 
 
ArithmeticComparison ArithmeticComparison_1
ArithmeticComparison ArithmeticComparison_1
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .X( ArithmeticComparison_A ),
 .X( ArithmeticComparison_A ),
 .Y( ArithmeticComparison_B ),
 .Y( ArithmeticComparison_B ),
 .iOperation( iOperation[2:0] ),
 .iOperation( iOperation[2:0] ),
 .iInputReady( ArithmeticComparison_InputReady ),
 .iInputReady( ArithmeticComparison_InputReady ),
 .OutputReady( ArithmeticComparison_OutputReady ),
 .OutputReady( ArithmeticComparison_OutputReady ),
 .Result( wArithmeticComparisonResult )
 .Result( wArithmeticComparisonResult )
);
);
 
 
 
 
assign  wArithmeticComparison_Result = wArithmeticComparisonResult && OutputReady;
assign  wArithmeticComparison_Result = wArithmeticComparisonResult && OutputReady;
//--------------------------------------------------------------------
//--------------------------------------------------------------------
 RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_A
 RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_A
(
(
 
 
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .A( wMultiplicationA_Ax ),
 .A( wMultiplicationA_Ax ),
 .B( wMultiplicationA_Bx ),
 .B( wMultiplicationA_Bx ),
 .R( wMultiplicationA_Result ),
 .R( wMultiplicationA_Result ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iInputReady( wMultiplicationA_InputReady ),
 .iInputReady( wMultiplicationA_InputReady ),
 .OutputReady( wMultiplicationA_OutputReady )
 .OutputReady( wMultiplicationA_OutputReady )
);
);
 
 
//--------------------------------------------------------------------
//--------------------------------------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS:   wMultiplicationA_Ax = iChannel_Ay; // Ay * Bz
 `CROSS:   wMultiplicationA_Ax = iChannel_Ay; // Ay * Bz
 `MAG:   wMultiplicationA_Ax = iChannel_Ax;
 `MAG:   wMultiplicationA_Ax = iChannel_Ax;
 `MULP:  wMultiplicationA_Ax = iChannel_Ax; //Az = Ax * Ay
 `MULP:  wMultiplicationA_Ax = iChannel_Ax; //Az = Ax * Ay
 default:  wMultiplicationA_Ax = iChannel_Ax; // Ax * Bx
 default:  wMultiplicationA_Ax = iChannel_Ax; // Ax * Bx
 endcase
 endcase
end
end
//--------------------------------------------------------------------
//--------------------------------------------------------------------
 
 
//assign wMultiplicationA_Ax = iChannel_Ax;
//assign wMultiplicationA_Ax = iChannel_Ax;
 
 
assign wMultiplicationA_InputReady
assign wMultiplicationA_InputReady
 = (iOperation == `CROSS ||
 = (iOperation == `CROSS ||
  iOperation == `DOT ||
  iOperation == `DOT ||
  iOperation == `MUL  ||
  iOperation == `MUL  ||
  iOperation == `IMUL  ||
  iOperation == `IMUL  ||
  iOperation == `MAG ||
  iOperation == `MAG ||
  iOperation == `MULP
  iOperation == `MULP
  ) ? iInputReady : 0;
  ) ? iInputReady : 0;
 
 
//--------------------------------------------------------------------
//--------------------------------------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `MUL,`IMUL:   wMultiplicationA_Bx = iChannel_Bx; //Ax*Bx
 `MUL,`IMUL:   wMultiplicationA_Bx = iChannel_Bx; //Ax*Bx
 `MAG:   wMultiplicationA_Bx = iChannel_Ax; //Ax^2
 `MAG:   wMultiplicationA_Bx = iChannel_Ax; //Ax^2
 `DOT:   wMultiplicationA_Bx = iChannel_Bx; //Ax*Bx
 `DOT:   wMultiplicationA_Bx = iChannel_Bx; //Ax*Bx
 `CROSS:  wMultiplicationA_Bx = iChannel_Bz; // Ay * Bz
 `CROSS:  wMultiplicationA_Bx = iChannel_Bz; // Ay * Bz
 `MULP:  wMultiplicationA_Bx = iChannel_Ay;  //Az = Ax * Ay
 `MULP:  wMultiplicationA_Bx = iChannel_Ay;  //Az = Ax * Ay
 default:  wMultiplicationA_Bx = 32'b0;
 default:  wMultiplicationA_Bx = 32'b0;
 endcase
 endcase
end
end
//--------------------------------------------------------------------
//--------------------------------------------------------------------
 
 
//------------------------------------------------------
//------------------------------------------------------
 
 
reg [`WIDTH-1:0] wMultiplicationB_Ay;
reg [`WIDTH-1:0] wMultiplicationB_Ay;
reg [`WIDTH-1:0]  wMultiplicationB_By;
reg [`WIDTH-1:0]  wMultiplicationB_By;
wire [`LONG_WIDTH-1:0] wMultiplicationB_Result;
wire [`LONG_WIDTH-1:0] wMultiplicationB_Result;
wire wMultiplicationB_InputReady;
wire wMultiplicationB_InputReady;
wire wMultiplicationB_OutputReady;
wire wMultiplicationB_OutputReady;
 
 
 
 
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_B
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_B
(
(
 
 
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .A( wMultiplicationB_Ay ),
 .A( wMultiplicationB_Ay ),
 .B( wMultiplicationB_By ),
 .B( wMultiplicationB_By ),
 .R( wMultiplicationB_Result ),
 .R( wMultiplicationB_Result ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iInputReady( wMultiplicationB_InputReady ),
 .iInputReady( wMultiplicationB_InputReady ),
 .OutputReady( wMultiplicationB_OutputReady )
 .OutputReady( wMultiplicationB_OutputReady )
);
);
 
 
 
 
//----------------------------------------------------
//----------------------------------------------------
 
 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
  `CROSS:  wMultiplicationB_Ay = iChannel_Az; // Az * By
  `CROSS:  wMultiplicationB_Ay = iChannel_Az; // Az * By
  `MAG:  wMultiplicationB_Ay = iChannel_Ay;
  `MAG:  wMultiplicationB_Ay = iChannel_Ay;
  default: wMultiplicationB_Ay = iChannel_Ay; // Ay * By
  default: wMultiplicationB_Ay = iChannel_Ay; // Ay * By
 endcase
 endcase
end
end
//----------------------------------------------------
//----------------------------------------------------
assign wMultiplicationB_InputReady
assign wMultiplicationB_InputReady
 = (iOperation == `CROSS    ||
 = (iOperation == `CROSS    ||
  iOperation == `DOT ||
  iOperation == `DOT ||
  iOperation == `MUL   ||
  iOperation == `MUL   ||
  iOperation == `IMUL   ||
  iOperation == `IMUL   ||
  iOperation == `MAG ) ? iInputReady : 0;
  iOperation == `MAG ) ? iInputReady : 0;
 
 
//----------------------------------------------------
//----------------------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `MUL,`IMUL:   wMultiplicationB_By = iChannel_By; //Ay*By
 `MUL,`IMUL:   wMultiplicationB_By = iChannel_By; //Ay*By
 `MAG:   wMultiplicationB_By = iChannel_Ay; //Ay^2
 `MAG:   wMultiplicationB_By = iChannel_Ay; //Ay^2
 `DOT:   wMultiplicationB_By = iChannel_By; //Ay*By
 `DOT:   wMultiplicationB_By = iChannel_By; //Ay*By
 `CROSS:  wMultiplicationB_By = iChannel_By; // Az * By
 `CROSS:  wMultiplicationB_By = iChannel_By; // Az * By
 default:  wMultiplicationB_By = 32'b0;
 default:  wMultiplicationB_By = 32'b0;
 endcase
 endcase
end
end
//----------------------------------------------------
//----------------------------------------------------
 
 
//------------------------------------------------------
//------------------------------------------------------
reg [`WIDTH-1:0] wMultiplicationC_Az;
reg [`WIDTH-1:0] wMultiplicationC_Az;
reg  [`WIDTH-1:0] wMultiplicationC_Bz;
reg  [`WIDTH-1:0] wMultiplicationC_Bz;
wire [`LONG_WIDTH-1:0] wMultiplicationC_Result;
wire [`LONG_WIDTH-1:0] wMultiplicationC_Result;
wire wMultiplicationC_InputReady;
wire wMultiplicationC_InputReady;
wire wMultiplicationC_OutputReady;
wire wMultiplicationC_OutputReady;
 
 
 
 
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_C
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_C
(
(
 
 
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .A( wMultiplicationC_Az ),
 .A( wMultiplicationC_Az ),
 .B( wMultiplicationC_Bz ),
 .B( wMultiplicationC_Bz ),
 .R( wMultiplicationC_Result ),
 .R( wMultiplicationC_Result ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iInputReady( wMultiplicationC_InputReady ),
 .iInputReady( wMultiplicationC_InputReady ),
 .OutputReady( wMultiplicationC_OutputReady )
 .OutputReady( wMultiplicationC_OutputReady )
);
);
 
 
 
 
//----------------------------------------------------
//----------------------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
  `CROSS:  wMultiplicationC_Az = iChannel_Az;  //Az*Bx
  `CROSS:  wMultiplicationC_Az = iChannel_Az;  //Az*Bx
  `MAG:  wMultiplicationC_Az = iChannel_Az;
  `MAG:  wMultiplicationC_Az = iChannel_Az;
  default:     wMultiplicationC_Az = iChannel_Az; //Az*Bz
  default:     wMultiplicationC_Az = iChannel_Az; //Az*Bz
 endcase
 endcase
end
end
//----------------------------------------------------
//----------------------------------------------------
 
 
assign wMultiplicationC_InputReady
assign wMultiplicationC_InputReady
 = (
 = (
  iOperation == `CROSS    ||
  iOperation == `CROSS    ||
  iOperation == `DOT ||
  iOperation == `DOT ||
  iOperation == `MUL   ||
  iOperation == `MUL   ||
  iOperation == `IMUL   ||
  iOperation == `IMUL   ||
  iOperation == `MAG
  iOperation == `MAG
  ) ? iInputReady : 0;
  ) ? iInputReady : 0;
 
 
//----------------------------------------------------
//----------------------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `MUL,`IMUL:   wMultiplicationC_Bz = iChannel_Bz; //Az*Bz
 `MUL,`IMUL:   wMultiplicationC_Bz = iChannel_Bz; //Az*Bz
 `MAG:   wMultiplicationC_Bz = iChannel_Az; //Ay^2
 `MAG:   wMultiplicationC_Bz = iChannel_Az; //Ay^2
 `DOT:   wMultiplicationC_Bz = iChannel_Bz; //Az*Bz
 `DOT:   wMultiplicationC_Bz = iChannel_Bz; //Az*Bz
 `CROSS:  wMultiplicationC_Bz = iChannel_Bx; //Az*Bx
 `CROSS:  wMultiplicationC_Bz = iChannel_Bx; //Az*Bx
 default:  wMultiplicationC_Bz = 32'b0;
 default:  wMultiplicationC_Bz = 32'b0;
 endcase
 endcase
end
end
//---------------------------------------------------- 
//---------------------------------------------------- 
 
 
reg [`WIDTH-1:0] wMultiplicationD_Aw;
reg [`WIDTH-1:0] wMultiplicationD_Aw;
reg  [`WIDTH-1:0] wMultiplicationD_Bw;
reg  [`WIDTH-1:0] wMultiplicationD_Bw;
wire [`LONG_WIDTH-1:0] wMultiplicationD_Result;
wire [`LONG_WIDTH-1:0] wMultiplicationD_Result;
wire wMultiplicationD_InputReady;
wire wMultiplicationD_InputReady;
wire wMultiplicationD_OutputReady;
wire wMultiplicationD_OutputReady;
 
 
 
 
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_D
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_D
(
(
 
 
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .A( wMultiplicationD_Aw ),
 .A( wMultiplicationD_Aw ),
 .B( wMultiplicationD_Bw ),
 .B( wMultiplicationD_Bw ),
 .R( wMultiplicationD_Result ),
 .R( wMultiplicationD_Result ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iInputReady( wMultiplicationD_InputReady ),
 .iInputReady( wMultiplicationD_InputReady ),
 .OutputReady( wMultiplicationD_OutputReady )
 .OutputReady( wMultiplicationD_OutputReady )
);
);
 
 
assign wMultiplicationD_InputReady
assign wMultiplicationD_InputReady
 = (iOperation == `CROSS ) ? iInputReady : 0;
 = (iOperation == `CROSS ) ? iInputReady : 0;
 
 
 
 
//---------------------------------------------------- 
//---------------------------------------------------- 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS:   wMultiplicationD_Aw = iChannel_Ax; //Ax*Bz
 `CROSS:   wMultiplicationD_Aw = iChannel_Ax; //Ax*Bz
 default:       wMultiplicationD_Aw = 32'b0;
 default:       wMultiplicationD_Aw = 32'b0;
 endcase
 endcase
end
end
//---------------------------------------------------- 
//---------------------------------------------------- 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS:   wMultiplicationD_Bw = iChannel_Bz; //Ax*Bz
 `CROSS:   wMultiplicationD_Bw = iChannel_Bz; //Ax*Bz
 default:       wMultiplicationD_Bw = 32'b0;
 default:       wMultiplicationD_Bw = 32'b0;
 endcase
 endcase
end
end
//---------------------------------------------------- 
//---------------------------------------------------- 
reg [`WIDTH-1:0] wMultiplicationE_Ak;
reg [`WIDTH-1:0] wMultiplicationE_Ak;
reg  [`WIDTH-1:0] wMultiplicationE_Bk;
reg  [`WIDTH-1:0] wMultiplicationE_Bk;
wire [`LONG_WIDTH-1:0] wMultiplicationE_Result;
wire [`LONG_WIDTH-1:0] wMultiplicationE_Result;
wire wMultiplicationE_InputReady;
wire wMultiplicationE_InputReady;
wire wMultiplicationE_OutputReady;
wire wMultiplicationE_OutputReady;
 
 
 
 
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_E
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_E
(
(
 
 
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .A( wMultiplicationE_Ak ),
 .A( wMultiplicationE_Ak ),
 .B( wMultiplicationE_Bk ),
 .B( wMultiplicationE_Bk ),
 .R( wMultiplicationE_Result ),
 .R( wMultiplicationE_Result ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iInputReady( wMultiplicationE_InputReady ),
 .iInputReady( wMultiplicationE_InputReady ),
 .OutputReady( wMultiplicationE_OutputReady )
 .OutputReady( wMultiplicationE_OutputReady )
);
);
 
 
assign wMultiplicationE_InputReady
assign wMultiplicationE_InputReady
 = (iOperation == `CROSS ) ? iInputReady : 0;
 = (iOperation == `CROSS ) ? iInputReady : 0;
 
 
 
 
//---------------------------------------------------- 
//---------------------------------------------------- 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS:   wMultiplicationE_Ak = iChannel_Ax; //Ax*By
 `CROSS:   wMultiplicationE_Ak = iChannel_Ax; //Ax*By
 default:   wMultiplicationE_Ak = 32'b0;
 default:   wMultiplicationE_Ak = 32'b0;
 endcase
 endcase
end
end
//---------------------------------------------------- 
//---------------------------------------------------- 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS:   wMultiplicationE_Bk = iChannel_By; //Ax*By
 `CROSS:   wMultiplicationE_Bk = iChannel_By; //Ax*By
 default:   wMultiplicationE_Bk = 32'b0;
 default:   wMultiplicationE_Bk = 32'b0;
 endcase
 endcase
end
end
 
 
//----------------------------------------------------  
//----------------------------------------------------  
reg [`WIDTH-1:0] wMultiplicationF_Al;
reg [`WIDTH-1:0] wMultiplicationF_Al;
reg  [`WIDTH-1:0] wMultiplicationF_Bl;
reg  [`WIDTH-1:0] wMultiplicationF_Bl;
wire [`LONG_WIDTH-1:0] wMultiplicationF_Result;
wire [`LONG_WIDTH-1:0] wMultiplicationF_Result;
wire wMultiplicationF_InputReady;
wire wMultiplicationF_InputReady;
wire wMultiplicationF_OutputReady;
wire wMultiplicationF_OutputReady;
 
 
 
 
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_F
RADIX_R_MUL_32_FULL_PARALLEL MultiplicationChannel_F
(
(
 
 
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .A( wMultiplicationF_Al ),
 .A( wMultiplicationF_Al ),
 .B( wMultiplicationF_Bl ),
 .B( wMultiplicationF_Bl ),
 .R( wMultiplicationF_Result ),
 .R( wMultiplicationF_Result ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iUnscaled( wMultiplcationUnscaled ),
 .iInputReady( wMultiplicationF_InputReady ),
 .iInputReady( wMultiplicationF_InputReady ),
 .OutputReady( wMultiplicationF_OutputReady )
 .OutputReady( wMultiplicationF_OutputReady )
);
);
assign wMultiplicationF_InputReady
assign wMultiplicationF_InputReady
 = (iOperation == `CROSS ) ? iInputReady : 0;
 = (iOperation == `CROSS ) ? iInputReady : 0;
 
 
 
 
//---------------------------------------------------- 
//---------------------------------------------------- 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS:   wMultiplicationF_Al = iChannel_Ay; //Ay*Bx
 `CROSS:   wMultiplicationF_Al = iChannel_Ay; //Ay*Bx
 default:   wMultiplicationF_Al = 32'b0;
 default:   wMultiplicationF_Al = 32'b0;
 endcase
 endcase
end
end
//---------------------------------------------------- 
//---------------------------------------------------- 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS:   wMultiplicationF_Bl = iChannel_Bx; //Ay*Bx
 `CROSS:   wMultiplicationF_Bl = iChannel_Bx; //Ay*Bx
 default:   wMultiplicationF_Bl = 32'b0;
 default:   wMultiplicationF_Bl = 32'b0;
 endcase
 endcase
end
end
//------------------------------------------------------
//------------------------------------------------------
wire [`WIDTH-1:0] wDivisionA_Result;
wire [`WIDTH-1:0] wDivisionA_Result;
wire wDivisionA_OutputReady;
wire wDivisionA_OutputReady;
wire wDivisionA_InputReady;
wire wDivisionA_InputReady;
 
 
assign wDivisionA_InputReady =
assign wDivisionA_InputReady =
 ( iOperation == `DIV) ? iInputReady : 0;
 ( iOperation == `DIV) ? iInputReady : 0;
 
 
SignedIntegerDivision DivisionChannel_A
SignedIntegerDivision DivisionChannel_A
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( Reset ),
.Reset( Reset ),
.iDividend( iChannel_Ax ),
.iDividend( iChannel_Ax ),
.iDivisor(  iChannel_Bx ),
.iDivisor(  iChannel_Bx ),
.oQuotient( wDivisionA_Result[`WIDTH-1:0] ),
.oQuotient( wDivisionA_Result[`WIDTH-1:0] ),
.iInputReady( wDivisionA_InputReady ),
.iInputReady( wDivisionA_InputReady ),
.OutputReady( wDivisionA_OutputReady )
.OutputReady( wDivisionA_OutputReady )
 
 
);
);
//------------------------------------------------------
//------------------------------------------------------
wire [`WIDTH-1:0] wDivisionB_Result;
wire [`WIDTH-1:0] wDivisionB_Result;
wire wDivisionB_OutputReady;
wire wDivisionB_OutputReady;
wire wDivisionB_InputReady;
wire wDivisionB_InputReady;
 
 
assign wDivisionB_InputReady =
assign wDivisionB_InputReady =
 ( iOperation == `DIV) ? iInputReady : 0;
 ( iOperation == `DIV) ? iInputReady : 0;
 
 
SignedIntegerDivision DivisionChannel_B
SignedIntegerDivision DivisionChannel_B
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( Reset ),
.Reset( Reset ),
.iDividend( iChannel_Ay ),
.iDividend( iChannel_Ay ),
.iDivisor( iChannel_By ),
.iDivisor( iChannel_By ),
.oQuotient( wDivisionB_Result[`WIDTH-1:0] ),
.oQuotient( wDivisionB_Result[`WIDTH-1:0] ),
.iInputReady( wDivisionB_InputReady ),
.iInputReady( wDivisionB_InputReady ),
.OutputReady( wDivisionB_OutputReady )
.OutputReady( wDivisionB_OutputReady )
 
 
);
);
//------------------------------------------------------
//------------------------------------------------------
wire [`WIDTH-1:0] wDivisionC_Result;
wire [`WIDTH-1:0] wDivisionC_Result;
wire wDivisionC_OutputReady;
wire wDivisionC_OutputReady;
wire wDivisionC_InputReady;
wire wDivisionC_InputReady;
 
 
 
 
assign wDivisionC_InputReady =
assign wDivisionC_InputReady =
 ( iOperation == `DIV) ? iInputReady : 0;
 ( iOperation == `DIV) ? iInputReady : 0;
 
 
SignedIntegerDivision DivisionChannel_C
SignedIntegerDivision DivisionChannel_C
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( Reset ),
.Reset( Reset ),
.iDividend( iChannel_Az ),
.iDividend( iChannel_Az ),
.iDivisor( iChannel_Bz ),
.iDivisor( iChannel_Bz ),
.oQuotient( wDivisionC_Result[`WIDTH-1:0] ),
.oQuotient( wDivisionC_Result[`WIDTH-1:0] ),
.iInputReady( wDivisionC_InputReady ),
.iInputReady( wDivisionC_InputReady ),
.OutputReady( wDivisionC_OutputReady )
.OutputReady( wDivisionC_OutputReady )
 
 
);
);
//--------------------------------------------------------------
//--------------------------------------------------------------
/*
/*
 First addtion block instance goes here.
 First addtion block instance goes here.
 Note that all inputs/outputs to the block
 Note that all inputs/outputs to the block
 are wires. It has two MUXES one for each entry.
 are wires. It has two MUXES one for each entry.
*/
*/
reg [`LONG_WIDTH-1:0] wAddSubA_Ax,wAddSubA_Bx;
reg [`LONG_WIDTH-1:0] wAddSubA_Ax,wAddSubA_Bx;
wire [`LONG_WIDTH-1:0] wAddSubA_Result;
wire [`LONG_WIDTH-1:0] wAddSubA_Result;
wire wAddSubA_Operation; //Either addition or substraction
wire wAddSubA_Operation; //Either addition or substraction
reg wAddSubA_InputReady;
reg wAddSubA_InputReady;
wire wAddSubA_OutputReady;
wire wAddSubA_OutputReady;
 
 
assign wAddSubA_Operation
assign wAddSubA_Operation
 = (
 = (
  iOperation == `SUB
  iOperation == `SUB
  || iOperation == `CROSS
  || iOperation == `CROSS
  || iOperation == `DEC
  || iOperation == `DEC
  || iOperation == `MOD
  || iOperation == `MOD
 ) ? 1 : 0;
 ) ? 1 : 0;
 
 
FixedAddSub AddSubChannel_A
FixedAddSub AddSubChannel_A
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( Reset ),
.Reset( Reset ),
.A( wAddSubA_Ax ),
.A( wAddSubA_Ax ),
.B( wAddSubA_Bx ),
.B( wAddSubA_Bx ),
.R( wAddSubA_Result ),
.R( wAddSubA_Result ),
.iOperation( wAddSubA_Operation ),
.iOperation( wAddSubA_Operation ),
.iInputReady( wAddSubA_InputReady ),
.iInputReady( wAddSubA_InputReady ),
.OutputReady( wAddSubA_OutputReady )
.OutputReady( wAddSubA_OutputReady )
);
);
//Diego
//Diego
 
 
 
 
//----------------------------
//----------------------------
 
 
//InpuReady Mux A
//InpuReady Mux A
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `ADD:  wAddSubA_InputReady = iInputReady;
 `ADD:  wAddSubA_InputReady = iInputReady;
 `SUB:  wAddSubA_InputReady = iInputReady;
 `SUB:  wAddSubA_InputReady = iInputReady;
 `INC,`INCX,`INCY,`INCZ:  wAddSubA_InputReady = iInputReady;
 `INC,`INCX,`INCY,`INCZ:  wAddSubA_InputReady = iInputReady;
 `DEC:  wAddSubA_InputReady = iInputReady;
 `DEC:  wAddSubA_InputReady = iInputReady;
 `MOD:  wAddSubA_InputReady = iInputReady;
 `MOD:  wAddSubA_InputReady = iInputReady;
 
 
 `MAG:  wAddSubA_InputReady = wMultiplicationOutputReadyA &&
 `MAG:  wAddSubA_InputReady = wMultiplicationOutputReadyA &&
            wMultiplicationOutputReadyB;
            wMultiplicationOutputReadyB;
          //wMultiplicationA_OutputReady 
          //wMultiplicationA_OutputReady 
          //&& wMultiplicationB_OutputReady;
          //&& wMultiplicationB_OutputReady;
 
 
 `DOT:  wAddSubA_InputReady =
 `DOT:  wAddSubA_InputReady =
           wMultiplicationOutputReadyA &&
           wMultiplicationOutputReadyA &&
           wMultiplicationOutputReadyB;
           wMultiplicationOutputReadyB;
          //wMultiplicationA_OutputReady 
          //wMultiplicationA_OutputReady 
          //&& wMultiplicationB_OutputReady;
          //&& wMultiplicationB_OutputReady;
 
 
 `CROSS: wAddSubA_InputReady =
 `CROSS: wAddSubA_InputReady =
          wMultiplicationOutputReadyA &&
          wMultiplicationOutputReadyA &&
          wMultiplicationOutputReadyB;
          wMultiplicationOutputReadyB;
          // wMultiplicationA_OutputReady
          // wMultiplicationA_OutputReady
          //&& wMultiplicationB_OutputReady;
          //&& wMultiplicationB_OutputReady;
 
 
 default: wAddSubA_InputReady = 1'b0;
 default: wAddSubA_InputReady = 1'b0;
 endcase
 endcase
end
end
//----------------------------
//----------------------------
 
 
//wAddSubA_Bx 2:1 input Mux
//wAddSubA_Bx 2:1 input Mux
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 
 
 `ADD:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `ADD:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `SUB:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `SUB:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `INC,`INCX,`INCY,`INCZ:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `INC,`INCX,`INCY,`INCZ:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `DEC:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `DEC:  wAddSubA_Ax = ( iChannel_Ax[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ax } : { 32'b0, iChannel_Ax };
 `MOD:  wAddSubA_Ax = ( iChannel_Bx[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Bx } : { 32'b0, iChannel_Bx };
 `MOD:  wAddSubA_Ax = ( iChannel_Bx[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Bx } : { 32'b0, iChannel_Bx };
 
 
 `MAG:  wAddSubA_Ax = wMultiplicationA_Result;
 `MAG:  wAddSubA_Ax = wMultiplicationA_Result;
 `DOT:  wAddSubA_Ax = wMultiplicationA_Result;
 `DOT:  wAddSubA_Ax = wMultiplicationA_Result;
 `CROSS: wAddSubA_Ax = wMultiplicationA_Result;
 `CROSS: wAddSubA_Ax = wMultiplicationA_Result;
 default: wAddSubA_Ax = 64'b0;
 default: wAddSubA_Ax = 64'b0;
 endcase
 endcase
end
end
//----------------------------
//----------------------------
//wAddSubA_Bx 2:1 input Mux
//wAddSubA_Bx 2:1 input Mux
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `ADD: wAddSubA_Bx = ( iChannel_Bx[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Bx } : { 32'b0, iChannel_Bx };
 `ADD: wAddSubA_Bx = ( iChannel_Bx[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Bx } : { 32'b0, iChannel_Bx };
 `SUB: wAddSubA_Bx = ( iChannel_Bx[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Bx } : { 32'b0, iChannel_Bx };
 `SUB: wAddSubA_Bx = ( iChannel_Bx[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Bx } : { 32'b0, iChannel_Bx };
 `INC,`INCX: wAddSubA_Bx = (`LONG_WIDTH'd1 << `SCALE);
 `INC,`INCX: wAddSubA_Bx = (`LONG_WIDTH'd1 << `SCALE);
 `INCY,`INCZ: wAddSubA_Bx = `LONG_WIDTH'd0;
 `INCY,`INCZ: wAddSubA_Bx = `LONG_WIDTH'd0;
 `DEC: wAddSubA_Bx = (`LONG_WIDTH'd1 << `SCALE);
 `DEC: wAddSubA_Bx = (`LONG_WIDTH'd1 << `SCALE);
 `MOD: wAddSubA_Bx = (`LONG_WIDTH'd1 << `SCALE);
 `MOD: wAddSubA_Bx = (`LONG_WIDTH'd1 << `SCALE);
 
 
 `MAG:  wAddSubA_Bx = wMultiplicationB_Result;
 `MAG:  wAddSubA_Bx = wMultiplicationB_Result;
 `DOT:  wAddSubA_Bx = wMultiplicationB_Result;
 `DOT:  wAddSubA_Bx = wMultiplicationB_Result;
 `CROSS: wAddSubA_Bx = wMultiplicationB_Result;
 `CROSS: wAddSubA_Bx = wMultiplicationB_Result;
 default: wAddSubA_Bx = 64'b0;
 default: wAddSubA_Bx = 64'b0;
 endcase
 endcase
end
end
//--------------------------------------------------------------
//--------------------------------------------------------------
/*
/*
 Second addtion block instance goes here.
 Second addtion block instance goes here.
 Note that all inputs/outputs to the block
 Note that all inputs/outputs to the block
 are wires. It has two MUXES one for each entry.
 are wires. It has two MUXES one for each entry.
*/
*/
 
 
wire [`LONG_WIDTH-1:0] wAddSubB_Result;
wire [`LONG_WIDTH-1:0] wAddSubB_Result;
 
 
 
 
wire wAddSubB_Operation; //Either addition or substraction
wire wAddSubB_Operation; //Either addition or substraction
reg  wAddSubB_InputReady;
reg  wAddSubB_InputReady;
wire wAddSubB_OutputReady;
wire wAddSubB_OutputReady;
 
 
reg [`LONG_WIDTH-1:0] wAddSubB_Ay,wAddSubB_By;
reg [`LONG_WIDTH-1:0] wAddSubB_Ay,wAddSubB_By;
 
 
assign wAddSubB_Operation =
assign wAddSubB_Operation =
 ( iOperation == `SUB
 ( iOperation == `SUB
   || iOperation == `CROSS
   || iOperation == `CROSS
   || iOperation == `DEC
   || iOperation == `DEC
   || iOperation == `MOD
   || iOperation == `MOD
   ) ? 1 : 0;
   ) ? 1 : 0;
 
 
FixedAddSub AddSubChannel_B
FixedAddSub AddSubChannel_B
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( Reset ),
.Reset( Reset ),
.A( wAddSubB_Ay ),
.A( wAddSubB_Ay ),
.B( wAddSubB_By ),
.B( wAddSubB_By ),
.R( wAddSubB_Result ),
.R( wAddSubB_Result ),
.iOperation( wAddSubB_Operation ),
.iOperation( wAddSubB_Operation ),
.iInputReady( wAddSubB_InputReady ),
.iInputReady( wAddSubB_InputReady ),
.OutputReady( wAddSubB_OutputReady )
.OutputReady( wAddSubB_OutputReady )
);
);
//----------------------------
//----------------------------
wire wMultiplicationOutputReadyC_Dealy1;
wire wMultiplicationOutputReadyC_Dealy1;
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFwMultiplicationOutputReadyC_Dealy1
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFwMultiplicationOutputReadyC_Dealy1
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .Enable(1'b1 ),
 .Enable(1'b1 ),
 .D( wMultiplicationOutputReadyC ),
 .D( wMultiplicationOutputReadyC ),
 .Q( wMultiplicationOutputReadyC_Dealy1 )
 .Q( wMultiplicationOutputReadyC_Dealy1 )
);
);
 
 
 
 
 
 
 
 
 
 
//InpuReady Mux B
//InpuReady Mux B
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `ADD:  wAddSubB_InputReady = iInputReady;
 `ADD:  wAddSubB_InputReady = iInputReady;
 `SUB:  wAddSubB_InputReady = iInputReady;
 `SUB:  wAddSubB_InputReady = iInputReady;
 `INC,`INCX,`INCY,`INCZ:  wAddSubB_InputReady = iInputReady;
 `INC,`INCX,`INCY,`INCZ:  wAddSubB_InputReady = iInputReady;
 `DEC:  wAddSubB_InputReady = iInputReady;
 `DEC:  wAddSubB_InputReady = iInputReady;
 `MOD:  wAddSubB_InputReady = iInputReady;
 `MOD:  wAddSubB_InputReady = iInputReady;
 
 
 `MAG:  wAddSubB_InputReady = wAddSubAOutputReady
 `MAG:  wAddSubB_InputReady = wAddSubAOutputReady
           && wMultiplicationOutputReadyC_Dealy1;
           && wMultiplicationOutputReadyC_Dealy1;
          //&& wMultiplicationC_OutputReady;
          //&& wMultiplicationC_OutputReady;
 
 
 `DOT:  wAddSubB_InputReady = wAddSubAOutputReady
 `DOT:  wAddSubB_InputReady = wAddSubAOutputReady
          && wMultiplicationOutputReadyC_Dealy1;
          && wMultiplicationOutputReadyC_Dealy1;
          //&& wMultiplicationC_OutputReady;
          //&& wMultiplicationC_OutputReady;
 
 
 `CROSS: wAddSubB_InputReady = wMultiplicationOutputReadyC &&
 `CROSS: wAddSubB_InputReady = wMultiplicationOutputReadyC &&
            wMultiplicationOutputReadyD;
            wMultiplicationOutputReadyD;
          // wMultiplicationC_OutputReady
          // wMultiplicationC_OutputReady
          //&& wMultiplicationD_OutputReady;
          //&& wMultiplicationD_OutputReady;
 
 
 default: wAddSubB_InputReady = 1'b0;
 default: wAddSubB_InputReady = 1'b0;
 
 
 endcase
 endcase
end
end
//----------------------------
//----------------------------
// wAddSubB_Ay 2:1 input Mux
// wAddSubB_Ay 2:1 input Mux
// If the iOperation is ADD or SUB, it will simply take the inputs from
// If the iOperation is ADD or SUB, it will simply take the inputs from
// ALU Channels. If it is a VECTOR_MAGNITUDE, it take the input from the
// ALU Channels. If it is a VECTOR_MAGNITUDE, it take the input from the
// previus ADDER_A, same for dot product.
// previus ADDER_A, same for dot product.
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `ADD:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `ADD:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `SUB:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `SUB:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `INC,`INCX,`INCY,`INCZ:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `INC,`INCX,`INCY,`INCZ:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `DEC:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `DEC:  wAddSubB_Ay = (iChannel_Ay[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_Ay} : {32'b0,iChannel_Ay};  //Ay
 `MOD:  wAddSubB_Ay = (iChannel_By[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_By} : {32'b0,iChannel_By};  //Ay
 `MOD:  wAddSubB_Ay = (iChannel_By[31] == 1'b1) ? {32'hFFFFFFFF, iChannel_By} : {32'b0,iChannel_By};  //Ay
 `MAG:  wAddSubB_Ay = wAddSubA_Result; //A^2+B^2
 `MAG:  wAddSubB_Ay = wAddSubA_Result; //A^2+B^2
 `DOT:  wAddSubB_Ay = wAddSubA_Result;   //Ax*Bx + Ay*By
 `DOT:  wAddSubB_Ay = wAddSubA_Result;   //Ax*Bx + Ay*By
 `CROSS: wAddSubB_Ay = wMultiplicationC_Result;
 `CROSS: wAddSubB_Ay = wMultiplicationC_Result;
 default: wAddSubB_Ay = 64'b0;
 default: wAddSubB_Ay = 64'b0;
 endcase
 endcase
end
end
//----------------------------
//----------------------------
//wAddSubB_By 2:1 input Mux
//wAddSubB_By 2:1 input Mux
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `ADD:  wAddSubB_By = (iChannel_By[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_By } : {32'b0,iChannel_By};    //By
 `ADD:  wAddSubB_By = (iChannel_By[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_By } : {32'b0,iChannel_By};    //By
 `SUB:  wAddSubB_By = (iChannel_By[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_By } : {32'b0,iChannel_By}; //{32'b0,iChannel_By};    //By
 `SUB:  wAddSubB_By = (iChannel_By[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_By } : {32'b0,iChannel_By}; //{32'b0,iChannel_By};    //By
 `INC,`INCY:  wAddSubB_By = (`LONG_WIDTH'd1 << `SCALE);
 `INC,`INCY:  wAddSubB_By = (`LONG_WIDTH'd1 << `SCALE);
 `INCX,`INCZ:   wAddSubB_By = `LONG_WIDTH'd0;
 `INCX,`INCZ:   wAddSubB_By = `LONG_WIDTH'd0;
 `DEC:  wAddSubB_By = (`LONG_WIDTH'd1 << `SCALE);
 `DEC:  wAddSubB_By = (`LONG_WIDTH'd1 << `SCALE);
 `MOD:  wAddSubB_By = (`LONG_WIDTH'd1 << `SCALE);
 `MOD:  wAddSubB_By = (`LONG_WIDTH'd1 << `SCALE);
 `MAG:  wAddSubB_By = wMultiplicationC_Result; //C^2
 `MAG:  wAddSubB_By = wMultiplicationC_Result; //C^2
 `DOT:  wAddSubB_By = wMultiplicationC_Result; //Az * Bz
 `DOT:  wAddSubB_By = wMultiplicationC_Result; //Az * Bz
 `CROSS: wAddSubB_By = wMultiplicationD_Result;
 `CROSS: wAddSubB_By = wMultiplicationD_Result;
 default: wAddSubB_By = `LONG_WIDTH'b0;
 default: wAddSubB_By = `LONG_WIDTH'b0;
 endcase
 endcase
end
end
//--------------------------------------------------------------
//--------------------------------------------------------------
wire [`LONG_WIDTH-1:0] wAddSubC_Result;
wire [`LONG_WIDTH-1:0] wAddSubC_Result;
reg [`LONG_WIDTH-1:0] wAddSubC_Az,wAddSubC_Bz;
reg [`LONG_WIDTH-1:0] wAddSubC_Az,wAddSubC_Bz;
 
 
wire wAddSubC_Operation; //Either addition or substraction
wire wAddSubC_Operation; //Either addition or substraction
reg wAddSubC_InputReady;
reg wAddSubC_InputReady;
wire wAddSubC_OutputReady;
wire wAddSubC_OutputReady;
 
 
reg [`LONG_WIDTH-1:0] AddSubC_Az,AddSubB_Bz;
reg [`LONG_WIDTH-1:0] AddSubC_Az,AddSubB_Bz;
 
 
//-----------------------------------------
//-----------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
  `CROSS:  wAddSubC_Az = wMultiplicationE_Result;
  `CROSS:  wAddSubC_Az = wMultiplicationE_Result;
  `MOD: wAddSubC_Az = (iChannel_Bz[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_Bz} : {32'b0,iChannel_Bz};
  `MOD: wAddSubC_Az = (iChannel_Bz[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_Bz} : {32'b0,iChannel_Bz};
  default:     wAddSubC_Az = (iChannel_Az[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_Az} : {32'b0,iChannel_Az};
  default:     wAddSubC_Az = (iChannel_Az[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_Az} : {32'b0,iChannel_Az};
 endcase
 endcase
end
end
//-----------------------------------------
//-----------------------------------------
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
  `CROSS:  wAddSubC_Bz = wMultiplicationF_Result;
  `CROSS:  wAddSubC_Bz = wMultiplicationF_Result;
  `INC,`INCZ:  wAddSubC_Bz = (`LONG_WIDTH'd1 << `SCALE);
  `INC,`INCZ:  wAddSubC_Bz = (`LONG_WIDTH'd1 << `SCALE);
  `INCX,`INCY:   wAddSubC_Bz = `LONG_WIDTH'd0;
  `INCX,`INCY:   wAddSubC_Bz = `LONG_WIDTH'd0;
  `DEC:  wAddSubC_Bz = (`LONG_WIDTH'd1 << `SCALE);
  `DEC:  wAddSubC_Bz = (`LONG_WIDTH'd1 << `SCALE);
  `MOD:  wAddSubC_Bz = (`LONG_WIDTH'd1 << `SCALE);
  `MOD:  wAddSubC_Bz = (`LONG_WIDTH'd1 << `SCALE);
  default:     wAddSubC_Bz = (iChannel_Bz[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_Bz} : {32'b0,iChannel_Bz};
  default:     wAddSubC_Bz = (iChannel_Bz[31] == 1'b1) ? {32'hFFFFFFFF,iChannel_Bz} : {32'b0,iChannel_Bz};
 endcase
 endcase
end
end
//-----------------------------------------
//-----------------------------------------
 
 
assign wAddSubC_Operation
assign wAddSubC_Operation
 = (
 = (
  iOperation == `SUB
  iOperation == `SUB
  || iOperation == `CROSS
  || iOperation == `CROSS
  || iOperation == `DEC
  || iOperation == `DEC
  || iOperation == `MOD
  || iOperation == `MOD
  ) ? 1 : 0;
  ) ? 1 : 0;
 
 
FixedAddSub AddSubChannel_C
FixedAddSub AddSubChannel_C
(
(
.Clock( Clock ),
.Clock( Clock ),
.Reset( Reset ),
.Reset( Reset ),
.A( wAddSubC_Az ),
.A( wAddSubC_Az ),
.B( wAddSubC_Bz ),
.B( wAddSubC_Bz ),
.R( wAddSubC_Result ),
.R( wAddSubC_Result ),
.iOperation( wAddSubC_Operation ),
.iOperation( wAddSubC_Operation ),
.iInputReady( wAddSubC_InputReady ),
.iInputReady( wAddSubC_InputReady ),
.OutputReady( wAddSubC_OutputReady )
.OutputReady( wAddSubC_OutputReady )
);
);
 
 
 
 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `CROSS: wAddSubC_InputReady = wMultiplicationE_OutputReady &&
 `CROSS: wAddSubC_InputReady = wMultiplicationE_OutputReady &&
  wMultiplicationF_OutputReady;
  wMultiplicationF_OutputReady;
 
 
 default: wAddSubC_InputReady = iInputReady;
 default: wAddSubC_InputReady = iInputReady;
 endcase
 endcase
end
end
 
 
//------------------------------------------------------
//------------------------------------------------------
wire [`WIDTH-1:0] wSquareRoot_Result;
wire [`WIDTH-1:0] wSquareRoot_Result;
wire wSquareRoot_OutputReady;
wire wSquareRoot_OutputReady;
 
 
 
 
FixedPointSquareRoot SQROOT1
FixedPointSquareRoot SQROOT1
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .Operand( wAddSubB_Result ),
 .Operand( wAddSubB_Result ),
 .iInputReady( wAddSubBOutputReady && iOperation == `MAG),
 .iInputReady( wAddSubBOutputReady && iOperation == `MAG),
 .OutputReady( wSquareRoot_OutputReady ),
 .OutputReady( wSquareRoot_OutputReady ),
 .Result( wSquareRoot_Result )
 .Result( wSquareRoot_Result )
);
);
//------------------------------------------------------
//------------------------------------------------------
 
 
assign wModulus2N_ResultA =  ({32'b0,iChannel_Ax}  & wAddSubA_Result );
assign wModulus2N_ResultA =  ({32'b0,iChannel_Ax}  & wAddSubA_Result );
assign wModulus2N_ResultB =  ({32'b0,iChannel_Ay}  & wAddSubB_Result );
assign wModulus2N_ResultB =  ({32'b0,iChannel_Ay}  & wAddSubB_Result );
assign wModulus2N_ResultC =  ({32'b0,iChannel_Az}  & wAddSubC_Result );
assign wModulus2N_ResultC =  ({32'b0,iChannel_Az}  & wAddSubC_Result );
 
 
 
 
 
 
 
 
 
 
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//
//****Mux for ResultA***
//****Mux for ResultA***
// Notice that the Dot Product or the Magnitud Result will
// Notice that the Dot Product or the Magnitud Result will
// output in ResultA.
// output in ResultA.
 
 
always @ ( *  )
always @ ( *  )
begin
begin
 case ( iOperation )
 case ( iOperation )
 `RETURN:    ResultA = iChannel_Ax;
 `RETURN:    ResultA = iChannel_Ax;
 `ADD:       ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};// & 32'h7FFFFFFF;
 `ADD:       ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};// & 32'h7FFFFFFF;
 `SUB:       ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};//wAddSubA_Result[31:0];
 `SUB:       ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};//wAddSubA_Result[31:0];
 `CROSS:    ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};//wAddSubA_Result[31:0];
 `CROSS:    ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};//wAddSubA_Result[31:0];
 `DIV:         ResultA = wDivisionA_Result;
 `DIV:         ResultA = wDivisionA_Result;
 `MUL:       ResultA = wMultiplicationA_Result[31:0];
 `MUL:       ResultA = wMultiplicationA_Result[31:0];
 `IMUL:            ResultA = wMultiplicationA_Result[31:0];
 `IMUL:            ResultA = wMultiplicationA_Result[31:0];
 `DOT:     ResultA = (wAddSubB_Result[63] == 1'b1) ? { 1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `DOT:     ResultA = (wAddSubB_Result[63] == 1'b1) ? { 1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `MAG:     ResultA = wSquareRoot_Result;
 `MAG:     ResultA = wSquareRoot_Result;
 `ZERO:    ResultA = 32'b0;
 `ZERO:    ResultA = 32'b0;
 `COPY:    ResultA = iChannel_Ax;
 `COPY:    ResultA = iChannel_Ax;
 `TMREAD:          ResultA = iTMEMReadData[95:64];
 `TMREAD:          ResultA = iTMEMReadData[95:64];
 `LEA:             ResultA = {16'b0,iCurrentIP};
 `LEA:             ResultA = {16'b0,iCurrentIP};
 
 
 `SWIZZLE3D: ResultA  = wSwizzleOutputX;
 `SWIZZLE3D: ResultA  = wSwizzleOutputX;
 
 
 //Set Operations
 //Set Operations
 `UNSCALE:   ResultA  = iChannel_Ax >> `SCALE;
 `UNSCALE:   ResultA  = iChannel_Ax >> `SCALE;
 `RESCALE:   ResultA  = iChannel_Ax << `SCALE;
 `RESCALE:   ResultA  = iChannel_Ax << `SCALE;
 `SETX,`RET:    ResultA  = iChannel_Ax;
 `SETX,`RET:    ResultA  = iChannel_Ax;
   `SETY:    ResultA  = iChannel_Bx;
   `SETY:    ResultA  = iChannel_Bx;
 `SETZ:    ResultA  = iChannel_Bx;
 `SETZ:    ResultA  = iChannel_Bx;
 `INC,`INCX,`INCY,`INCZ:     ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};
 `INC,`INCX,`INCY,`INCZ:     ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};
 `DEC:     ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};
 `DEC:     ResultA = (wAddSubA_Result[63] == 1'b1) ? { 1'b1,wAddSubA_Result[30:0]} : {1'b0,wAddSubA_Result[30:0]};
 `MOD:     ResultA =  wModulus2N_ResultA[31:0];
 `MOD:     ResultA =  wModulus2N_ResultA[31:0];
 `FRAC:    ResultA = iChannel_Ax & (`WIDTH'hFFFFFFFF >> (`WIDTH - `SCALE));
 `FRAC:    ResultA = iChannel_Ax & (`WIDTH'hFFFFFFFF >> (`WIDTH - `SCALE));
 `MULP:      ResultA = iChannel_Ax;
 `MULP:      ResultA = iChannel_Ax;
 `NEG:      ResultA = ~iChannel_Ax + 1'b1;
 `NEG:      ResultA = ~iChannel_Ax + 1'b1;
 `XCHANGEX:   ResultA  = iChannel_Bx;
 `XCHANGEX:   ResultA  = iChannel_Bx;
 
 `XCHANGEY:   ResultA  = iChannel_Ax;
 
 `XCHANGEZ:   ResultA  = iChannel_Ax;
 
 
 
 
 default:
 default:
 begin
 begin
 `ifdef DEBUG
 `ifdef DEBUG
// $display("%dns ALU: Error Unknown Operation: %d",$time,iOperation);
// $display("%dns ALU: Error Unknown Operation: %d",$time,iOperation);
// $stop();
// $stop();
 `endif
 `endif
 ResultA =  32'b0;
 ResultA =  32'b0;
 end
 end
 endcase
 endcase
end
end
//------------------------------------------------------
//------------------------------------------------------
//****Mux for RB***
//****Mux for RB***
always @ ( * )
always @ ( * )
begin
begin
 case ( iOperation )
 case ( iOperation )
 `RETURN:    ResultB = iChannel_Ax;
 `RETURN:    ResultB = iChannel_Ax;
 `ADD:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; // & 32'h7FFFFFFF;
 `ADD:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; // & 32'h7FFFFFFF;
 `SUB:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; //wAddSubB_Result[31:0];
 `SUB:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; //wAddSubB_Result[31:0];
 `CROSS:    ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `CROSS:    ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `DIV:         ResultB = wDivisionB_Result;
 `DIV:         ResultB = wDivisionB_Result;
 `MUL:       ResultB = wMultiplicationB_Result[31:0];
 `MUL:       ResultB = wMultiplicationB_Result[31:0];
 `IMUL:            ResultB = wMultiplicationB_Result[31:0];
 `IMUL:            ResultB = wMultiplicationB_Result[31:0];
 `DOT:     ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `DOT:     ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `MAG:     ResultB = wSquareRoot_Result;
 `MAG:     ResultB = wSquareRoot_Result;
 `ZERO:    ResultB = 32'b0;
 `ZERO:    ResultB = 32'b0;
 `COPY:    ResultB = iChannel_Ay;
 `COPY:    ResultB = iChannel_Ay;
 `TMREAD:          ResultB = iTMEMReadData[63:32];
 `TMREAD:          ResultB = iTMEMReadData[63:32];
 `LEA:             ResultB = {16'b0,iCurrentIP};
 `LEA:             ResultB = {16'b0,iCurrentIP};
 
 
 //Set Operations
 //Set Operations
 `UNSCALE:   ResultB  = iChannel_Ay >> `SCALE;
 `UNSCALE:   ResultB  = iChannel_Ay >> `SCALE;
 `RESCALE:   ResultB  = iChannel_Ay << `SCALE;
 `RESCALE:   ResultB  = iChannel_Ay << `SCALE;
 `SETX,`RET:  ResultB  = iChannel_By;  // {Source1[95:64],Source0[63:32],Source0[31:0]}; 
 `SETX,`RET:  ResultB  = iChannel_By;  // {Source1[95:64],Source0[63:32],Source0[31:0]}; 
 `SETY:    ResultB  = iChannel_Ax;  // {Source0[95:64],Source1[95:64],Source0[31:0]}; 
 `SETY:    ResultB  = iChannel_Ax;  // {Source0[95:64],Source1[95:64],Source0[31:0]}; 
 `SETZ:    ResultB  = iChannel_By;  // {Source0[95:64],Source0[63:32],Source1[95:64]}; 
 `SETZ:    ResultB  = iChannel_By;  // {Source0[95:64],Source0[63:32],Source1[95:64]}; 
 
 
 `SWIZZLE3D:   ResultB  = wSwizzleOutputY;
 `SWIZZLE3D:   ResultB  = wSwizzleOutputY;
 
 
 `INC,`INCX,`INCY,`INCZ:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; // & 32'h7FFFFFFF;
 `INC,`INCX,`INCY,`INCZ:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; // & 32'h7FFFFFFF;
 `DEC:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; // & 32'h7FFFFFFF;
 `DEC:       ResultB = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]}; // & 32'h7FFFFFFF;
 `MOD:     ResultB =  wModulus2N_ResultB[31:0];
 `MOD:     ResultB =  wModulus2N_ResultB[31:0];
 `FRAC:    ResultB = iChannel_Ay & (`WIDTH'hFFFFFFFF >> (`WIDTH - `SCALE));
 `FRAC:    ResultB = iChannel_Ay & (`WIDTH'hFFFFFFFF >> (`WIDTH - `SCALE));
 `MULP:    ResultB = iChannel_Ay;
 `MULP:    ResultB = iChannel_Ay;
 `NEG:     ResultB = ~iChannel_Ay + 1'b1;
 `NEG:     ResultB = ~iChannel_Ay + 1'b1;
 `XCHANGEX:   ResultB = iChannel_Ay;
 `XCHANGEX:   ResultB = iChannel_Ay;
 
 `XCHANGEY:   ResultB = iChannel_By;
 
 `XCHANGEZ:   ResultB = iChannel_Ay;
 
 
 default:
 default:
 begin
 begin
 `ifdef DEBUG
 `ifdef DEBUG
 //$display("%dns ALU: Error Unknown Operation: %d",$time,iOperation);
 //$display("%dns ALU: Error Unknown Operation: %d",$time,iOperation);
 //$stop();
 //$stop();
 `endif
 `endif
 ResultB =  32'b0;
 ResultB =  32'b0;
 end
 end
 endcase
 endcase
end
end
//------------------------------------------------------
//------------------------------------------------------
//****Mux for RC***
//****Mux for RC***
always @ ( * )
always @ ( * )
begin
begin
 case ( iOperation )
 case ( iOperation )
 `RETURN:    ResultC = iChannel_Ax;
 `RETURN:    ResultC = iChannel_Ax;
 `ADD:       ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];// & 32'h7FFFFFFF;
 `ADD:       ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];// & 32'h7FFFFFFF;
 `SUB:       ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];
 `SUB:       ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];
 `CROSS:    ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]};//wAddSubC_Result[31:0];
 `CROSS:    ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]};//wAddSubC_Result[31:0];
 `DIV:         ResultC = wDivisionC_Result;
 `DIV:         ResultC = wDivisionC_Result;
 `MUL:       ResultC = wMultiplicationC_Result[31:0];
 `MUL:       ResultC = wMultiplicationC_Result[31:0];
 `IMUL:            ResultC = wMultiplicationC_Result[31:0];
 `IMUL:            ResultC = wMultiplicationC_Result[31:0];
 `DOT:     ResultC = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `DOT:     ResultC = (wAddSubB_Result[63] == 1'b1) ? {1'b1,wAddSubB_Result[30:0]} : {1'b0,wAddSubB_Result[30:0]};//wAddSubB_Result[31:0];
 `MAG:     ResultC = wSquareRoot_Result;
 `MAG:     ResultC = wSquareRoot_Result;
 `ZERO:    ResultC = 32'b0;
 `ZERO:    ResultC = 32'b0;
 `COPY:    ResultC = iChannel_Az;
 `COPY:    ResultC = iChannel_Az;
 `TMREAD:          ResultC = iTMEMReadData[31:0];
 `TMREAD:          ResultC = iTMEMReadData[31:0];
 `LEA:             ResultC = {16'b0,iCurrentIP};
 `LEA:             ResultC = {16'b0,iCurrentIP};
 
 
 `SWIZZLE3D: ResultC  = wSwizzleOutputZ;
 `SWIZZLE3D: ResultC  = wSwizzleOutputZ;
 
 
 //Set Operations
 //Set Operations
 `UNSCALE:   ResultC  = iChannel_Az >> `SCALE;
 `UNSCALE:   ResultC  = iChannel_Az >> `SCALE;
 `RESCALE:   ResultC  = iChannel_Az << `SCALE;
 `RESCALE:   ResultC  = iChannel_Az << `SCALE;
 `SETX,`RET:  ResultC  = iChannel_Bz;  // {Source1[95:64],Source0[63:32],Source0[31:0]}; 
 `SETX,`RET:  ResultC  = iChannel_Bz;  // {Source1[95:64],Source0[63:32],Source0[31:0]}; 
 `SETY:    ResultC  = iChannel_Bz;  // {Source0[95:64],Source1[95:64],Source0[31:0]}; 
 `SETY:    ResultC  = iChannel_Bz;  // {Source0[95:64],Source1[95:64],Source0[31:0]}; 
 `SETZ:    ResultC  = iChannel_Ax;  // {Source0[95:64],Source0[63:32],Source1[95:64]}; 
 `SETZ:    ResultC  = iChannel_Ax;  // {Source0[95:64],Source0[63:32],Source1[95:64]}; 
 
 
 `INC,`INCX,`INCY,`INCZ:       ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];// & 32'h7FFFFFFF;
 `INC,`INCX,`INCY,`INCZ:       ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];// & 32'h7FFFFFFF;
 `DEC:     ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];// & 32'h7FFFFFFF;
 `DEC:     ResultC = (wAddSubC_Result[63] == 1'b1) ? {1'b1,wAddSubC_Result[30:0]} : {1'b0,wAddSubC_Result[30:0]}; //wAddSubC_Result[31:0];// & 32'h7FFFFFFF;
 `MOD:     ResultC =  wModulus2N_ResultC[31:0];
 `MOD:     ResultC =  wModulus2N_ResultC[31:0];
 `FRAC:    ResultC = iChannel_Az & (`WIDTH'hFFFFFFFF >> (`WIDTH - `SCALE));
 `FRAC:    ResultC = iChannel_Az & (`WIDTH'hFFFFFFFF >> (`WIDTH - `SCALE));
 `MULP:    ResultC = wMultiplicationA_Result[31:0];
 `MULP:    ResultC = wMultiplicationA_Result[31:0];
 `NEG:     ResultC = ~iChannel_Az + 1'b1;
 `NEG:     ResultC = ~iChannel_Az + 1'b1;
 `XCHANGEX:   ResultC = iChannel_Az;
 `XCHANGEX:   ResultC = iChannel_Az;
 
 `XCHANGEY:   ResultC = iChannel_Az;
 
 `XCHANGEZ:   ResultC = iChannel_Bz;
 default:
 default:
 begin
 begin
 `ifdef DEBUG
 `ifdef DEBUG
 //$display("%dns ALU: Error Unknown Operation: %d",$time,iOperation);
 //$display("%dns ALU: Error Unknown Operation: %d",$time,iOperation);
 //$stop();
 //$stop();
 `endif
 `endif
 ResultC =  32'b0;
 ResultC =  32'b0;
 end
 end
 endcase
 endcase
end
end
//------------------------------------------------------------------------
//------------------------------------------------------------------------
 
 
 
 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 `JMP,`CALL,`RET: oBranchTaken = OutputReady;
 `JMP,`CALL,`RET: oBranchTaken = OutputReady;
 `JGX: oBranchTaken = wArithmeticComparison_Result;
 `JGX: oBranchTaken = wArithmeticComparison_Result;
 `JGY: oBranchTaken = wArithmeticComparison_Result;
 `JGY: oBranchTaken = wArithmeticComparison_Result;
 `JGZ: oBranchTaken = wArithmeticComparison_Result;
 `JGZ: oBranchTaken = wArithmeticComparison_Result;
 
 
 `JLX: oBranchTaken = wArithmeticComparison_Result;
 `JLX: oBranchTaken = wArithmeticComparison_Result;
 `JLY: oBranchTaken = wArithmeticComparison_Result;
 `JLY: oBranchTaken = wArithmeticComparison_Result;
 `JLZ: oBranchTaken = wArithmeticComparison_Result;
 `JLZ: oBranchTaken = wArithmeticComparison_Result;
 
 
 `JEQX: oBranchTaken = wArithmeticComparison_Result;
 `JEQX: oBranchTaken = wArithmeticComparison_Result;
 `JEQY: oBranchTaken = wArithmeticComparison_Result;
 `JEQY: oBranchTaken = wArithmeticComparison_Result;
 `JEQZ: oBranchTaken = wArithmeticComparison_Result;
 `JEQZ: oBranchTaken = wArithmeticComparison_Result;
 
 
 `JNEX: oBranchTaken = wArithmeticComparison_Result;
 `JNEX: oBranchTaken = wArithmeticComparison_Result;
 `JNEY: oBranchTaken = wArithmeticComparison_Result;
 `JNEY: oBranchTaken = wArithmeticComparison_Result;
 `JNEZ: oBranchTaken = wArithmeticComparison_Result;
 `JNEZ: oBranchTaken = wArithmeticComparison_Result;
 
 
 `JGEX: oBranchTaken = wArithmeticComparison_Result;
 `JGEX: oBranchTaken = wArithmeticComparison_Result;
 `JGEY: oBranchTaken = wArithmeticComparison_Result;
 `JGEY: oBranchTaken = wArithmeticComparison_Result;
 `JGEZ: oBranchTaken = wArithmeticComparison_Result;
 `JGEZ: oBranchTaken = wArithmeticComparison_Result;
 
 
 `JLEX: oBranchTaken = wArithmeticComparison_Result;
 `JLEX: oBranchTaken = wArithmeticComparison_Result;
 `JLEY: oBranchTaken = wArithmeticComparison_Result;
 `JLEY: oBranchTaken = wArithmeticComparison_Result;
 `JLEZ: oBranchTaken = wArithmeticComparison_Result;
 `JLEZ: oBranchTaken = wArithmeticComparison_Result;
 
 
 default: oBranchTaken = 0;
 default: oBranchTaken = 0;
 endcase
 endcase
 
 
end
end
 
 
always @ ( * )
always @ ( * )
begin
begin
 case (iOperation)
 case (iOperation)
 
 
  `JMP,`CALL,`RET,`JGX,`JGY,`JGZ,`JLX,`JLY,`JLZ,`JEQX,`JEQY,`JEQZ,
  `JMP,`CALL,`RET,`JGX,`JGY,`JGZ,`JLX,`JLY,`JLZ,`JEQX,`JEQY,`JEQZ,
  `JNEX,`JNEY,`JNEZ,`JGEX,`JGEY,`JGEZ: oBranchNotTaken = !oBranchTaken && OutputReady;
  `JNEX,`JNEY,`JNEZ,`JGEX,`JGEY,`JGEZ: oBranchNotTaken = !oBranchTaken && OutputReady;
  `JLEX: oBranchNotTaken = !oBranchTaken && OutputReady;
  `JLEX: oBranchNotTaken = !oBranchTaken && OutputReady;
  `JLEY: oBranchNotTaken = !oBranchTaken && OutputReady;
  `JLEY: oBranchNotTaken = !oBranchTaken && OutputReady;
  `JLEZ: oBranchNotTaken = !oBranchTaken && OutputReady;
  `JLEZ: oBranchNotTaken = !oBranchTaken && OutputReady;
 default:
 default:
  oBranchNotTaken = 0;
  oBranchNotTaken = 0;
 endcase
 endcase
end
end
//------------------------------------------------------------------------
//------------------------------------------------------------------------
//Output ready logic Stuff for Division...
//Output ready logic Stuff for Division...
//Some FFT will hopefully do the trick
//Some FFT will hopefully do the trick
 
 
wire wDivisionOutputReadyA,wDivisionOutputReadyB,wDivisionOutputReadyC ;
wire wDivisionOutputReadyA,wDivisionOutputReadyB,wDivisionOutputReadyC ;
wire wDivisionOutputReady;
wire wDivisionOutputReady;
 
 
 
 
 
 
assign wAddSubAOutputReady = wAddSubA_OutputReady;
assign wAddSubAOutputReady = wAddSubA_OutputReady;
assign wAddSubBOutputReady = wAddSubB_OutputReady;
assign wAddSubBOutputReady = wAddSubB_OutputReady;
assign wAddSubCOutputReady = wAddSubC_OutputReady;
assign wAddSubCOutputReady = wAddSubC_OutputReady;
 
 
wire wDivA_tmp, wDivB_tmp, wDivC_tmp;
wire wDivA_tmp, wDivB_tmp, wDivC_tmp;
UPCOUNTER_POSEDGE # (1) FFT_DivisionA
UPCOUNTER_POSEDGE # (1) FFT_DivisionA
(
(
.Clock(Clock),
.Clock(Clock),
.Reset(Reset | iInputReady),
.Reset(Reset | iInputReady),
.Initial(1'b0),
.Initial(1'b0),
.Enable(wDivisionA_OutputReady),
.Enable(wDivisionA_OutputReady),
.Q(wDivA_tmp)
.Q(wDivA_tmp)
);
);
 
 
assign wDivisionOutputReadyA = ((wDivA_tmp | wDivisionA_OutputReady) & ~iInputReady);
assign wDivisionOutputReadyA = ((wDivA_tmp | wDivisionA_OutputReady) & ~iInputReady);
UPCOUNTER_POSEDGE # (1) FFT_DivisionB
UPCOUNTER_POSEDGE # (1) FFT_DivisionB
(
(
.Clock(Clock),
.Clock(Clock),
.Reset(Reset | iInputReady),
.Reset(Reset | iInputReady),
.Initial(1'b0),
.Initial(1'b0),
.Enable(wDivisionB_OutputReady),
.Enable(wDivisionB_OutputReady),
.Q(wDivB_tmp)
.Q(wDivB_tmp)
);
);
assign wDivisionOutputReadyB = ((wDivB_tmp | wDivisionB_OutputReady) & ~iInputReady);
assign wDivisionOutputReadyB = ((wDivB_tmp | wDivisionB_OutputReady) & ~iInputReady);
 
 
UPCOUNTER_POSEDGE # (1) FFT_DivisionC
UPCOUNTER_POSEDGE # (1) FFT_DivisionC
(
(
.Clock(Clock),
.Clock(Clock),
.Reset(Reset | iInputReady),
.Reset(Reset | iInputReady),
.Initial(1'b0),
.Initial(1'b0),
.Enable(wDivisionC_OutputReady),
.Enable(wDivisionC_OutputReady),
.Q(wDivC_tmp)
.Q(wDivC_tmp)
);
);
assign wDivisionOutputReadyC = ((wDivC_tmp | wDivisionC_OutputReady) & ~iInputReady);
assign wDivisionOutputReadyC = ((wDivC_tmp | wDivisionC_OutputReady) & ~iInputReady);
/*
/*
FFT1 FFT_DivisionA
FFT1 FFT_DivisionA
  (
  (
   .D(1'b1),
   .D(1'b1),
   .Clock( wDivisionA_OutputReady ),
   .Clock( wDivisionA_OutputReady ),
   .Reset( iInputReady ),
   .Reset( iInputReady ),
   .Q( wDivisionOutputReadyA )
   .Q( wDivisionOutputReadyA )
 );
 );
 
 
FFT1 FFT_DivisionB
FFT1 FFT_DivisionB
  (
  (
   .D(1'b1),
   .D(1'b1),
   .Clock( wDivisionB_OutputReady ),
   .Clock( wDivisionB_OutputReady ),
   .Reset( iInputReady ),
   .Reset( iInputReady ),
   .Q( wDivisionOutputReadyB )
   .Q( wDivisionOutputReadyB )
 );
 );
 
 
 FFT1 FFT_DivisionC
 FFT1 FFT_DivisionC
  (
  (
   .D(1'b1),
   .D(1'b1),
   .Clock( wDivisionC_OutputReady ),
   .Clock( wDivisionC_OutputReady ),
   .Reset( iInputReady ),
   .Reset( iInputReady ),
   .Q( wDivisionOutputReadyC )
   .Q( wDivisionOutputReadyC )
 );
 );
 */
 */
 assign wDivisionOutputReady =
 assign wDivisionOutputReady =
 ( wDivisionOutputReadyA && wDivisionOutputReadyB && wDivisionOutputReadyC );
 ( wDivisionOutputReadyA && wDivisionOutputReadyB && wDivisionOutputReadyC );
 
 
assign wMultiplicationOutputReadyA = wMultiplicationA_OutputReady;
assign wMultiplicationOutputReadyA = wMultiplicationA_OutputReady;
assign wMultiplicationOutputReadyB = wMultiplicationB_OutputReady;
assign wMultiplicationOutputReadyB = wMultiplicationB_OutputReady;
assign wMultiplicationOutputReadyC = wMultiplicationC_OutputReady;
assign wMultiplicationOutputReadyC = wMultiplicationC_OutputReady;
assign wMultiplicationOutputReadyD = wMultiplicationD_OutputReady;
assign wMultiplicationOutputReadyD = wMultiplicationD_OutputReady;
 
 
 assign wMultiplicationOutputReady =
 assign wMultiplicationOutputReady =
 ( wMultiplicationOutputReadyA && wMultiplicationOutputReadyB && wMultiplicationOutputReadyC );
 ( wMultiplicationOutputReadyA && wMultiplicationOutputReadyB && wMultiplicationOutputReadyC );
 
 
 wire wSquareRootOutputReady;
 wire wSquareRootOutputReady;
 FFT1 FFT_Sqrt
 FFT1 FFT_Sqrt
  (
  (
   .D(1'b1),
   .D(1'b1),
   .Clock( wSquareRoot_OutputReady ),
   .Clock( wSquareRoot_OutputReady ),
   .Reset( iInputReady ),
   .Reset( iInputReady ),
   .Q( wSquareRootOutputReady )
   .Q( wSquareRootOutputReady )
 );
 );
 
 
 
 
//------------------------------------------------------------------------
//------------------------------------------------------------------------
wire wOutputDelay1Cycle,wOutputDelay2Cycle,wOutputDelay3Cycle;
wire wOutputDelay1Cycle,wOutputDelay2Cycle,wOutputDelay3Cycle;
 
 
 
 
 
 
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFOutputReadyDelay2
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFOutputReadyDelay2
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .Enable(1'b1),
 .Enable(1'b1),
 .D( iInputReady ),
 .D( iInputReady ),
 .Q( wOutputDelay1Cycle )
 .Q( wOutputDelay1Cycle )
);
);
 
 
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFOutputReadyDelay22
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFOutputReadyDelay22
(
(
 .Clock( Clock  ),
 .Clock( Clock  ),
 .Reset( Reset ),
 .Reset( Reset ),
 .Enable(1'b1),
 .Enable(1'b1),
 .D( wOutputDelay1Cycle ),
 .D( wOutputDelay1Cycle ),
 .Q( wOutputDelay2Cycle )
 .Q( wOutputDelay2Cycle )
);
);
wire wIsOMWRITE;
wire wIsOMWRITE;
assign wIsOMWRITE = (wOperation == `OMWRITE) ? 1'b1: 1'b0;
assign wIsOMWRITE = (wOperation == `OMWRITE) ? 1'b1: 1'b0;
 
 
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFOutputReadyDelay222
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFOutputReadyDelay222
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .Enable(wIsOMWRITE),
 .Enable(wIsOMWRITE),
 .D( wOutputDelay2Cycle ),
 .D( wOutputDelay2Cycle ),
 .Q( wOutputDelay3Cycle )
 .Q( wOutputDelay3Cycle )
);
);
 
 
FFD_POSEDGE_SYNCRONOUS_RESET # ( `INSTRUCTION_OP_LENGTH ) SourceZ2
FFD_POSEDGE_SYNCRONOUS_RESET # ( `INSTRUCTION_OP_LENGTH ) SourceZ2
(
(
 .Clock( Clock ),
 .Clock( Clock ),
 .Reset( Reset ),
 .Reset( Reset ),
 .Enable( iInputReady ),
 .Enable( iInputReady ),
 .D( iOperation ),
 .D( iOperation ),
 .Q(wOperation)
 .Q(wOperation)
);
);
 
 
 
 
//Mux for output ready signal
//Mux for output ready signal
always @ ( * )
always @ ( * )
begin
begin
 case ( wOperation )
 case ( wOperation )
 `UNSCALE,`RESCALE:   OutputReady  = wOutputDelay1Cycle;
 `UNSCALE,`RESCALE:   OutputReady  = wOutputDelay1Cycle;
 `RETURN: OutputReady = wOutputDelay1Cycle;
 `RETURN: OutputReady = wOutputDelay1Cycle;
 
 
 `NOP: OutputReady = wOutputDelay1Cycle;
 `NOP: OutputReady = wOutputDelay1Cycle;
 `FRAC: OutputReady = wOutputDelay1Cycle;
 `FRAC: OutputReady = wOutputDelay1Cycle;
 `NEG: OutputReady = wOutputDelay1Cycle;
 `NEG: OutputReady = wOutputDelay1Cycle;
 `OMWRITE: OutputReady = wOutputDelay3Cycle;
 `OMWRITE: OutputReady = wOutputDelay3Cycle;
 `TMREAD:  OutputReady = wTMReadOutputReady;  //One cycle after TMEM data availale asserted
 `TMREAD:  OutputReady = wTMReadOutputReady;  //One cycle after TMEM data availale asserted
 
 
 `ifdef DEBUG
 `ifdef DEBUG
 //Debug Print behaves as a NOP in terms of ALU...
 //Debug Print behaves as a NOP in terms of ALU...
 `DEBUG_PRINT: OutputReady = wOutputDelay1Cycle;
 `DEBUG_PRINT: OutputReady = wOutputDelay1Cycle;
 `endif
 `endif
 
 
 `ADD,`INC,`INCX,`INCY,`INCZ:  OutputReady =  wAddSubAOutputReady &&
 `ADD,`INC,`INCX,`INCY,`INCZ:  OutputReady =  wAddSubAOutputReady &&
         wAddSubBOutputReady &&
         wAddSubBOutputReady &&
         wAddSubCOutputReady;
         wAddSubCOutputReady;
 
 
 `SUB,`DEC:    OutputReady =  wAddSubAOutputReady &&
 `SUB,`DEC:    OutputReady =  wAddSubAOutputReady &&
         wAddSubBOutputReady &&
         wAddSubBOutputReady &&
         wAddSubCOutputReady;
         wAddSubCOutputReady;
 
 
 `DIV:  OutputReady =  wDivisionOutputReady;
 `DIV:  OutputReady =  wDivisionOutputReady;
 
 
 
 
 `MUL,`IMUL:    OutputReady =  wMultiplicationOutputReady;
 `MUL,`IMUL:    OutputReady =  wMultiplicationOutputReady;
 `MULP:  OutputReady =  wMultiplicationOutputReadyA;
 `MULP:  OutputReady =  wMultiplicationOutputReadyA;
 
 
 `DOT:  OutputReady = wAddSubBOutputReady;
 `DOT:  OutputReady = wAddSubBOutputReady;
 
 
 `CROSS: OutputReady =  wAddSubAOutputReady &&
 `CROSS: OutputReady =  wAddSubAOutputReady &&
         wAddSubBOutputReady &&
         wAddSubBOutputReady &&
         wAddSubCOutputReady;
         wAddSubCOutputReady;
 
 
 `MAG:  OutputReady = wSquareRootOutputReady;
 `MAG:  OutputReady = wSquareRootOutputReady;
 
 
 `ZERO: OutputReady = wOutputDelay1Cycle;
 `ZERO: OutputReady = wOutputDelay1Cycle;
 
 
 `COPY: OutputReady = wOutputDelay1Cycle;
 `COPY: OutputReady = wOutputDelay1Cycle;
 
 
 `SWIZZLE3D: OutputReady = wOutputDelay1Cycle;
 `SWIZZLE3D: OutputReady = wOutputDelay1Cycle;
 
 
 `SETX,`SETY,`SETZ,`JMP,`LEA,`CALL,`RET:  OutputReady = wOutputDelay1Cycle;
 `SETX,`SETY,`SETZ,`JMP,`LEA,`CALL,`RET:  OutputReady = wOutputDelay1Cycle;
 
 
 
 
 
 
 `JGX,`JGY,`JGZ:    OutputReady = ArithmeticComparison_OutputReady;
 `JGX,`JGY,`JGZ:    OutputReady = ArithmeticComparison_OutputReady;
 `JLX,`JLY,`JLZ:    OutputReady = ArithmeticComparison_OutputReady;
 `JLX,`JLY,`JLZ:    OutputReady = ArithmeticComparison_OutputReady;
 `JEQX,`JEQY,`JEQZ:   OutputReady = ArithmeticComparison_OutputReady;
 `JEQX,`JEQY,`JEQZ:   OutputReady = ArithmeticComparison_OutputReady;
 `JNEX,`JNEY,`JNEZ:   OutputReady = ArithmeticComparison_OutputReady;
 `JNEX,`JNEY,`JNEZ:   OutputReady = ArithmeticComparison_OutputReady;
 `JGEX,`JGEY,`JGEZ:   OutputReady = ArithmeticComparison_OutputReady;
 `JGEX,`JGEY,`JGEZ:   OutputReady = ArithmeticComparison_OutputReady;
 `JLEX,`JLEY,`JLEZ:   OutputReady = ArithmeticComparison_OutputReady;
 `JLEX,`JLEY,`JLEZ:   OutputReady = ArithmeticComparison_OutputReady;
 
 
 `MOD: OutputReady = wAddSubAOutputReady &&    //TODO: wait 1 more cycle
 `MOD: OutputReady = wAddSubAOutputReady &&    //TODO: wait 1 more cycle
         wAddSubBOutputReady &&
         wAddSubBOutputReady &&
         wAddSubCOutputReady;
         wAddSubCOutputReady;
 
 
 `XCHANGEX: OutputReady = wOutputDelay1Cycle;
 `XCHANGEX,`XCHANGEY,`XCHANGEZ: OutputReady = wOutputDelay1Cycle;
 
 
 
 
 default:
 default:
 begin
 begin
  OutputReady =  1'b0;
  OutputReady =  1'b0;
  //`ifdef DEBUG
  //`ifdef DEBUG
  //$display("*** ALU ERROR: iOperation = %d ***",iOperation);
  //$display("*** ALU ERROR: iOperation = %d ***",iOperation);
  //`endif
  //`endif
 end
 end
 
 
 endcase
 endcase
end
end
 
 
endmodule
endmodule
//------------------------------------------------------------------------
//------------------------------------------------------------------------
 
 

powered by: WebSVN 2.1.0

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