Partial progress towards compressed instructions

This commit is contained in:
Jarred Allen 2021-03-04 18:30:26 -05:00
parent 106718b196
commit 41f682f848
5 changed files with 26 additions and 17 deletions

View File

@ -29,7 +29,7 @@ module hazard(
// Detect hazards // Detect hazards
input logic PCSrcE, CSRWritePendingDEM, RetM, TrapM, input logic PCSrcE, CSRWritePendingDEM, RetM, TrapM,
input logic LoadStallD, MulDivStallD, CSRRdStallD, input logic LoadStallD, MulDivStallD, CSRRdStallD,
input logic InstrStall, DataStall, input logic InstrStall, DataStall, ICacheStallF,
// Stall & flush outputs // Stall & flush outputs
output logic StallF, StallD, StallE, StallM, StallW, output logic StallF, StallD, StallE, StallM, StallW,
output logic FlushD, FlushE, FlushM, FlushW output logic FlushD, FlushE, FlushM, FlushW

View File

@ -34,6 +34,8 @@ module icache(
input logic [`XLEN-1:0] InstrInF, input logic [`XLEN-1:0] InstrInF,
output logic [`XLEN-1:0] InstrPAdrF, output logic [`XLEN-1:0] InstrPAdrF,
output logic InstrReadF, output logic InstrReadF,
output logic CompressedF,
output logic ICacheStallF,
// Decode // Decode
output logic [31:0] InstrRawD output logic [31:0] InstrRawD
); );
@ -46,7 +48,7 @@ module icache(
flopr #(1) flushDLastCycleFlop(clk, reset, FlushD | (FlushDLastCycle & StallF), FlushDLastCycle); flopr #(1) flushDLastCycleFlop(clk, reset, FlushD | (FlushDLastCycle & StallF), FlushDLastCycle);
flopenr #(1) delayStateFlop(clk, reset, ~StallF, (DelayF & ~DelaySideF) ? 1'b1 : 1'b0 , DelaySideF); flopenr #(1) delayStateFlop(clk, reset, ~StallF, (DelayF & ~DelaySideF) ? 1'b1 : 1'b0 , DelaySideF);
flopenr #(16) halfInstrFlop(clk, reset, DelayF, MisalignedHalfInstrF, MisalignedHalfInstrD); flopenr #(16) halfInstrFlop(clk, reset, DelayF & ~StallF, MisalignedHalfInstrF, MisalignedHalfInstrD);
flopenr #(32) instrFlop(clk, reset, ~StallF, InstrF, AlignedInstrD); flopenr #(32) instrFlop(clk, reset, ~StallF, InstrF, AlignedInstrD);
@ -69,15 +71,20 @@ module icache(
// machinery to swizzle bits. // machinery to swizzle bits.
generate generate
if (`XLEN == 32) begin if (`XLEN == 32) begin
assign InstrF = PCPF[1] ? 32'b0 : InstrInF; assign InstrF = PCPF[1] ? {16'b0, InstrInF[31:16]} : InstrInF;
assign DelayF = PCPF[1]; assign DelayF = PCPF[1];
assign MisalignedHalfInstrF = InstrInF[31:16]; assign MisalignedHalfInstrF = InstrInF[31:16];
end else begin end else begin
assign InstrF = PCPF[2] ? (PCPF[1] ? 64'b0 : InstrInF[63:32]) : (PCPF[1] ? InstrInF[47:16] : InstrInF[31:0]); assign InstrF = PCPF[2] ? (PCPF[1] ? {16'b0, InstrInF[63:48]} : InstrInF[63:32]) : (PCPF[1] ? InstrInF[47:16] : InstrInF[31:0]);
assign DelayF = PCPF[1] && PCPF[2]; assign DelayF = PCPF[1] && PCPF[2];
assign MisalignedHalfInstrF = InstrInF[63:48]; assign MisalignedHalfInstrF = InstrInF[63:48];
end end
endgenerate endgenerate
assign ICacheStallF = DelayF & ~DelaySideF;
// Detect if the instruction is compressed
// TODO Low-hanging optimization, don't delay if compressed
assign CompressedF = DelaySideF ? (MisalignedHalfInstrD[1:0] != 2'b11) : (InstrF[1:0] != 2'b11);
// Pick the correct output, depending on whether we have to assemble this // Pick the correct output, depending on whether we have to assemble this
// instruction from two reads or not. // instruction from two reads or not.

View File

@ -35,6 +35,7 @@ module ifu (
output logic [`XLEN-1:0] PCF, output logic [`XLEN-1:0] PCF,
output logic [`XLEN-1:0] InstrPAdrF, output logic [`XLEN-1:0] InstrPAdrF,
output logic InstrReadF, output logic InstrReadF,
output logic ICacheStallF,
// Decode // Decode
// Execute // Execute
input logic PCSrcE, input logic PCSrcE,
@ -51,23 +52,23 @@ module ifu (
input logic IllegalBaseInstrFaultD, input logic IllegalBaseInstrFaultD,
output logic IllegalIEUInstrFaultD, output logic IllegalIEUInstrFaultD,
output logic InstrMisalignedFaultM, output logic InstrMisalignedFaultM,
output logic [`XLEN-1:0] InstrMisalignedAdrM,
// TLB management // TLB management
//input logic [`XLEN-1:0] PageTableEntryF, //input logic [`XLEN-1:0] PageTableEntryF,
//input logic ITLBWriteF, ITLBFlushF, //input logic ITLBWriteF, ITLBFlushF,
// *** satp value will come from CSRs // *** satp value will come from CSRs
// input logic [`XLEN-1:0] SATP, // input logic [`XLEN-1:0] SATP,
output logic ITLBMissF, ITLBHitF, output logic ITLBMissF, ITLBHitF
output logic [`XLEN-1:0] InstrMisalignedAdrM
); );
logic [`XLEN-1:0] UnalignedPCNextF, PCNextF; logic [`XLEN-1:0] UnalignedPCNextF, PCNextF;
logic misaligned, BranchMisalignedFaultE, BranchMisalignedFaultM, TrapMisalignedFaultM; logic misaligned, BranchMisalignedFaultE, BranchMisalignedFaultM, TrapMisalignedFaultM;
logic PrivilegedChangePCM; logic PrivilegedChangePCM;
logic IllegalCompInstrD; logic IllegalCompInstrD;
logic [`XLEN-1:0] PCPlusUpperF, PCPlus2or4F, PCD, PCW, PCLinkD, PCLinkE, PCLinkM, PCPF; logic [`XLEN-1:0] PCPlusUpperF, PCPlus2or4F, PCD, PCW, PCLinkD, PCLinkE, PCLinkM, PCPF;
logic CompressedF; logic CompressedF;
logic [31:0] InstrRawD, InstrE, InstrW; logic [31:0] InstrRawD, InstrE, InstrW;
logic [31:0] nop = 32'h00000013; // instruction for NOP logic [31:0] nop = 32'h00000013; // instruction for NOP
logic [`XLEN-1:0] ITLBInstrPAdrF, ICacheInstrPAdrF; logic [`XLEN-1:0] ITLBInstrPAdrF, ICacheInstrPAdrF;
// *** temporary hack until we can figure out how to get actual satp value // *** temporary hack until we can figure out how to get actual satp value
@ -87,7 +88,7 @@ module ifu (
// jarred 2021-03-04 Add instrution cache block to remove rd2 // jarred 2021-03-04 Add instrution cache block to remove rd2
assign PCPF = PCF; // Temporary workaround until iTLB is live assign PCPF = PCF; // Temporary workaround until iTLB is live
icache ic(clk, reset, StallF, StallD, FlushD, PCPF, InstrInF, ICacheInstrPAdrF, InstrReadF, InstrRawD); icache ic(clk, reset, StallF, StallD, FlushD, PCPF, InstrInF, ICacheInstrPAdrF, InstrReadF, CompressedF, ICacheStallF, InstrRawD);
// Prioritize the iTLB for reads if it wants one // Prioritize the iTLB for reads if it wants one
mux2 #(`XLEN) instrPAdrMux(ICacheInstrPAdrF, ITLBInstrPAdrF, ITLBMissF, InstrPAdrF); mux2 #(`XLEN) instrPAdrMux(ICacheInstrPAdrF, ITLBInstrPAdrF, ITLBMissF, InstrPAdrF);
@ -95,13 +96,11 @@ module ifu (
mux3 #(`XLEN) pcmux(PCPlus2or4F, PCTargetE, PrivilegedNextPCM, {PrivilegedChangePCM, PCSrcE}, UnalignedPCNextF); mux3 #(`XLEN) pcmux(PCPlus2or4F, PCTargetE, PrivilegedNextPCM, {PrivilegedChangePCM, PCSrcE}, UnalignedPCNextF);
assign PCNextF = {UnalignedPCNextF[`XLEN-1:1], 1'b0}; // hart-SPEC p. 21 about 16-bit alignment assign PCNextF = {UnalignedPCNextF[`XLEN-1:1], 1'b0}; // hart-SPEC p. 21 about 16-bit alignment
flopenl #(`XLEN) pcreg(clk, reset, ~StallF, PCNextF, `RESET_VECTOR, PCF); flopenl #(`XLEN) pcreg(clk, reset, ~StallF & ~ICacheStallF, PCNextF, `RESET_VECTOR, PCF);
// pcadder // pcadder
// add 2 or 4 to the PC, based on whether the instruction is 16 bits or 32 // add 2 or 4 to the PC, based on whether the instruction is 16 bits or 32
assign CompressedF = 0; // is it a 16-bit compressed instruction? TODO Fix this
assign PCPlusUpperF = PCF[`XLEN-1:2] + 1; // add 4 to PC assign PCPlusUpperF = PCF[`XLEN-1:2] + 1; // add 4 to PC
// choose PC+2 or PC+4 // choose PC+2 or PC+4
always_comb always_comb
if (CompressedF) // add 2 if (CompressedF) // add 2

View File

@ -91,6 +91,9 @@ module wallypipelinedhart (
logic ITLBMissF, ITLBHitF; logic ITLBMissF, ITLBHitF;
logic DTLBMissM, DTLBHitM; logic DTLBMissM, DTLBHitM;
// ICache stalls
logic ICacheStallF;
// bus interface to dmem // bus interface to dmem
logic MemReadM, MemWriteM; logic MemReadM, MemWriteM;
logic [2:0] Funct3M; logic [2:0] Funct3M;

View File

@ -322,7 +322,7 @@ string tests32i[] = {
initial initial
if (`XLEN == 64) begin // RV64 if (`XLEN == 64) begin // RV64
tests = {tests64i}; tests = {tests64i};
if (`C_SUPPORTED % 2 == 1) tests = {tests, tests64ic}; if (`C_SUPPORTED % 2 == 1) tests = {tests64ic, tests};
else tests = {tests, tests64iNOc}; else tests = {tests, tests64iNOc};
if (`M_SUPPORTED % 2 == 1) tests = {tests, tests64m}; if (`M_SUPPORTED % 2 == 1) tests = {tests, tests64m};
end else begin // RV32 end else begin // RV32