URL
https://opencores.org/ocsvn/forwardcom/forwardcom/trunk
Subversion Repositories forwardcom
[/] [forwardcom/] [trunk/] [addressgenerator.sv] - Rev 117
Go to most recent revision | Compare with Previous | Blame | View Log
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Engineer: Agner Fog//// Create Date: 2020-06-04// Last modified: 2021-07-17// Module Name: decoder// Project Name: ForwardCom soft core// Target Devices: Artix 7// Tool Versions: Vivado v. 2020.1// License: CERN-OHL-W v. 2 or later// Description: Address generator. Calculates address of memory operand////////////////////////////////////////////////////////////////////////////////////`include "defines.vh"module addressgenerator(input clock, // system clock (100 MHz)input clock_enable, // clock enable. Used when single-steppinginput reset, // system reset.input valid_in, // data from fetch module readyinput stall_in, // a later stage in pipeline is stalledinput [`CODE_ADDR_WIDTH-1:0] instruction_pointer_in, // address of current instructioninput [95:0] instruction_in, // current instruction, up to 3 words longinput [`TAG_WIDTH-1:0] tag_val_in, // instruction tag valueinput vector_in, // this is a vector instructioninput [1:0] category_in, // 00: multiformat, 01: single format, 10: jumpinput [1:0] format_in, // 00: format A, 01: format E, 10: format B, 11: format C (format D never goes through decoder)input [2:0] rs_status_in, // 1: RS is register operand, 2: RS is pointer, 3: RS is index, 4: RS is vector lengthinput [2:0] rt_status_in, // 1: RT is register operand, 2: RT is pointerinput [1:0] ru_status_in, // 1: RU is used as register operandinput [1:0] rd_status_in, // 1: RD is used as inputinput [1:0] mask_status_in, // 1: mask register usedinput mask_alternative_in, // mask register and fallback register used for alternative purposesinput [2:0] fallback_use_in, // 0: no fallback, 1: same as first source operand, 2-4: RU, RS, RTinput [1:0] num_operands_in, // number of source operandsinput [1:0] result_type_in, // type of result: 0: register, 1: system register, 2: memory, 3: other or nothinginput [1:0] offset_field_in, // address offset. 0: none, 1: 8 bit, possibly scaled, 2: 16 bit, 3: 32 bitinput [1:0] immediate_field_in, // immediate data field. 0: none, 1: 8 bit, 2: 16 bit, 3: 32 or 64 bitinput [1:0] scale_factor_in, // 00: index is not scaled, 01: index is scaled by operand size, 10: index is scaled by -1input index_limit_in, // IM2 or IM3 contains a limit to the index// Register valuesinput [`RB:0] rd_val_in, // value of register operand RD, bit `RB indicates missinginput [`RB:0] rs_val_in, // value of register operand RS, bit `RB indicates missinginput [`RB:0] rt_val_in, // value of register operand RT, bit `RB indicates missinginput [`RB:0] ru_val_in, // value of register operand RU, bit `RB indicates missinginput [`MASKSZ:0] regmask_val_in, // value of mask register, bit 32 indicates missing// monitor result buses:input write_en1, // a result is written to writeport1input [`TAG_WIDTH-1:0] write_tag1_in, // tag of result inwriteport1input [`RB1:0] writeport1_in, // result bus 1input write_en2, // a result is written to writeport2input [`TAG_WIDTH-1:0] write_tag2_in, // tag of result inwriteport2input [`RB1:0] writeport2_in, // result bus 2input [`TAG_WIDTH-1:0] predict_tag1_in, // tag on result bus 1 in next clock cycleinput [`TAG_WIDTH-1:0] predict_tag2_in, // tag on result bus 2 in next clock cycle// calculated read and write memory addresses go to data cacheoutput reg [`COMMON_ADDR_WIDTH-1:0] read_write_address_out, // address of memory operandoutput reg read_enable_out, // read from data cacheoutput reg [1:0] read_data_size_out, // 8, 16, 32, or 64 bits readoutput reg [7:0] write_enable_out, // write enable for each byte separatelyoutput reg [63:0] write_data_out, // data to write// instruction output to next pipeline stageoutput reg valid_out, // An instruction is ready for output to next stageoutput reg [`CODE_ADDR_WIDTH-1:0] instruction_pointer_out, // address of current instructionoutput reg [63:0] instruction_out, // first word of instructionoutput reg stall_predict_out, // will be waiting for an operandoutput reg [`TAG_WIDTH-1:0] tag_val_out,// instruction tag valueoutput reg [`RB:0] operand1_out, // value of first operand, bit `RB indicates invalidoutput reg [`RB:0] operand2_out, // value of second operand, bit `RB indicates invalidoutput reg [`RB:0] operand3_out, // value of last, bit `RB indicates validoutput reg [`MASKSZ:0] regmask_val_out,// value of mask register, high bit indicates validoutput reg vector_out, // this is a vector instructionoutput reg [1:0] category_out, // 00: multiformat, 01: single format, 10: jumpoutput reg [1:0] format_out, // 00: format A, 01: format E, 10: format B, 11: format C (format D never goes through decoder)output reg mask_status_out, // 1: mask register usedoutput reg mask_alternative_out, // mask register and fallback register used for alternative purposesoutput reg [2:0] fallback_use_out, // 0: no fallback, 1: same as first source operand, 2-4: RU, RS, RToutput reg [1:0] num_operands_out, // number of source operandsoutput reg [1:0] result_type_out, // type of result: 0: register, 1: system register, 2: memory, 3: other or nothingoutput reg [1:0] offset_field_out, // address offset. 0: none, 1: 8 bit, possibly scaled, 2: 16 bit, 3: 32 bitoutput reg [1:0] immediate_field_out, // immediate data field. 0: none, 1: 8 bit, 2: 16 bit, 3: 32 or 64 bitoutput reg [1:0] scale_factor_out, // 00: index is not scaled, 01: index is scaled by operand size, 10: index is scaled by -1output reg memory_operand_out, // The instruction has a memory operandoutput reg array_error_out, // Array index exceeds limitoutput reg options3_out, // IM3 containts option bitsoutput reg [31:0] debug1_out, // Temporary output for debugging purposeoutput reg [31:0] debug2_out, // Temporary output for debugging purposeoutput reg [31:0] debug3_out // Temporary output for debugging purpose);// instruction componentslogic [1:0] il; // instruction lengthlogic [2:0] mode; // instruction modelogic M; // M bitlogic [5:0] op1; // OP1 in instructionlogic [1:0] op2; // OP2 in instructionlogic [2:0] otype; // operand typelogic [2:0] mode2; // mode2 in format Elogic option_bits_im3; // IM3 is used for option bits// synchronization signalslogic waiting; // waiting for needed register valuelogic wait_next1; // predict that it will also be waiting for reg1 in the next clock cyclelogic wait_next2; // predict that it will also be waiting for reg2 in the next clock cyclelogic wait_next3; // predict that it will also be waiting for reg3 in the next clock cyclelogic address_instruction; // this is an address instruction. no memory accesslogic mask_off; // result is masked offlogic new_instruction; // instruction is different from last instructionlogic array_error; // Array index exceeds limitreg last_stall; // was stalled in last clock cycle. May obtain values from the temporary registersreg last_valid; // input was valid in last clock cyclereg [`TAG_WIDTH-1:0] last_tag_val; // check if instruction tag has changed// components of address calculationlogic [`COMMON_ADDR_WIDTH-1:0] base_pointer;logic [`COMMON_ADDR_WIDTH-1:0] address_index;logic [`COMMON_ADDR_WIDTH-1:0] address_offset; // offset of memory operandlogic [`COMMON_ADDR_WIDTH-1:0] address; // address of memory operandlogic [`RB1:0] write_data; // data to write// register values. Extra bit is 1 if not foundlogic [`RB:0] rs_val; // value of first register operand RS, bit `RB indicates missinglogic [`RB:0] rt_val; // value of second register operand RT, bit `RB indicates missinglogic [`RB:0] ru_val; // value of third register operand RD or RU, bit `RB indicates missinglogic [`RB:0] rd_val; // value of third register operand RD or RU, bit `RB indicates missinglogic [`MASKSZ:0] regmask_val; // value of mask register, bit 32 indicates missing// temporary storage of register values if found during stall. High bit is zero if validreg [`RB:0] rs_val_temp; // value of first register operand RS, bit `RB indicates missingreg [`RB:0] rt_val_temp; // value of second register operand RT, bit `RB indicates missingreg [`RB:0] ru_val_temp; // value of third register operand RD or RU, bit `RB indicates missingreg [`RB:0] rd_val_temp; // value of third register operand RD or RU, bit `RB indicates missingreg [`MASKSZ:0] regmask_val_temp; // value of mask register, bit 32 indicates missingalways_comb begin// components of format templateil = instruction_in[`IL]; // instruction lengthmode = instruction_in[`MODE]; // format modeM = instruction_in[`M]; // extension to operand type or modeop1 = instruction_in[`OP1]; // operation codeop2 = instruction_in[`OP2]; // operation code extensionotype = instruction_in[`OT] & {vector_in,2'b11}; // operand typemode2 = instruction_in[`MODE2]; // format mode extension// look for address instructionif (il == 2 && mode == 1 && M && op1 == `II_ADDRESS_29) address_instruction = 1;else address_instruction = 0;// detect use of IM3 as option bits or extra operandoption_bits_im3 = 0;if (il == 2 && (mode == 0 || mode == 5) && mode2 == 5) beginoption_bits_im3 = 0; // format 2.0.5 and 2.2.5 are using IM3 for an operand, not for optionsend else if (category_in == `CAT_MULTI) beginif (op1 == `II_SIGN_EXTEND_ADD || op1 == `II_COMPARE|| op1 == `II_DIV || op1 == `II_DIV_REV || op1 == `II_DIV_U|| op1 == `II_TEST_BIT || op1 == `II_TEST_BITS_AND || op1 == `II_TEST_BITS_OR|| op1 == `II_MUL_ADD_FLOAT16 || op1 == `II_MUL_ADD || op1 == `II_MUL_ADD2|| op1 == `II_ADD_ADD) beginoption_bits_im3 = 1;endend else if (il == 2) beginif (((mode == 0 && !M) || mode == 2) && mode2 == 7 && op1 == `II_MOVE_BITS && op2 == `II2_MOVE_BITS)option_bits_im3 = 1;if (mode == 2 && mode2 == 7 && op1 == `II_MASK_LENGTH && op2 == `II2_MASK_LENGTH)option_bits_im3 = 1;if (((mode == 0 && !M) || mode == 2) && mode2 == 6 && op1 == `II_TRUTH_TAB3 && op2 == `II2_TRUTH_TAB3)option_bits_im3 = 1;end/* We need to prevent spill-over of values from a preceding stalled instructionbecause the address generator can produce pipeline bubbles. The solution usedhere is to check if the instruction tag has changed before using the _temp values.Test case:int64 sp -= 32int r8 = 8int r9 = 9int32 [sp+0x00] = r8int32 [sp+0x08] = r9int32 r2 = r8 + r9int32 [sp+0x10] = r2*/// check if current instruction is different from last clock cyclenew_instruction = (tag_val_in != last_tag_val) && valid_in;// look at result buses for any missing register valuesif (last_stall && rs_val_temp[`RB] == 0 && last_valid && !new_instruction) rs_val = rs_val_temp; // obtained during stallelse if (rs_val_in[`RB] == 1 && write_en1 && rs_val_in[`TAG_WIDTH-1:0] == write_tag1_in) rs_val = {1'b0, writeport1_in}; // obtained from result bus 1else if (rs_val_in[`RB] == 1 && write_en2 && rs_val_in[`TAG_WIDTH-1:0] == write_tag2_in) rs_val = {1'b0, writeport2_in}; // obtained from result bus 2else rs_val = rs_val_in;if (last_stall && rt_val_temp[`RB] == 0 && last_valid && !new_instruction) rt_val = rt_val_temp; // obtained during stallelse if (rt_val_in[`RB] == 1 && write_en1 && rt_val_in[`TAG_WIDTH-1:0] == write_tag1_in) rt_val = {1'b0, writeport1_in}; // obtained from result bus 1else if (rt_val_in[`RB] == 1 && write_en2 && rt_val_in[`TAG_WIDTH-1:0] == write_tag2_in) rt_val = {1'b0, writeport2_in}; // obtained from result bus 2else rt_val = rt_val_in;if (last_stall && ru_val_temp[`RB] == 0 && last_valid && !new_instruction) ru_val = ru_val_temp; // obtained during stallelse if (ru_val_in[`RB] == 1 && write_en1 && ru_val_in[`TAG_WIDTH-1:0] == write_tag1_in) ru_val = {1'b0, writeport1_in}; // obtained from result bus 1else if (ru_val_in[`RB] == 1 && write_en2 && ru_val_in[`TAG_WIDTH-1:0] == write_tag2_in) ru_val = {1'b0, writeport2_in}; // obtained from result bus 2else ru_val = ru_val_in;if (last_stall && rd_val_temp[`RB] == 0 && last_valid && !new_instruction) rd_val = rd_val_temp; // obtained during stallelse if (rd_val_in[`RB] == 1 && write_en1 && rd_val_in[`TAG_WIDTH-1:0] == write_tag1_in) rd_val = {1'b0, writeport1_in}; // obtained from result bus 1else if (rd_val_in[`RB] == 1 && write_en2 && rd_val_in[`TAG_WIDTH-1:0] == write_tag2_in) rd_val = {1'b0, writeport2_in}; // obtained from result bus 2else rd_val = rd_val_in;if (mask_status_in == `REG_UNUSED) regmask_val = 1; // no maskelse if (last_stall && regmask_val_temp[`MASKSZ] == 0 && last_valid && !new_instruction) regmask_val = regmask_val_temp; // obtained during stallelse if (regmask_val_in[`MASKSZ] == 1 && write_en1 && regmask_val_in[`TAG_WIDTH-1:0] == write_tag1_in) regmask_val = {1'b0, writeport1_in[`MASKSZ-1:0]}; // obtained from result bus 1else if (regmask_val_in[`MASKSZ] == 1 && write_en2 && regmask_val_in[`TAG_WIDTH-1:0] == write_tag2_in) regmask_val = {1'b0, writeport2_in[`MASKSZ-1:0]}; // obtained from result bus 2else regmask_val = regmask_val_in;end// save values from result bus during stallalways_ff @(posedge clock) if (clock_enable) beginif ((stall_in || waiting) && valid_in ) beginrs_val_temp <= rs_val; // temporary save during stallrt_val_temp <= rt_val; // temporary save during stallru_val_temp <= ru_val; // temporary save during stallrd_val_temp <= rd_val; // temporary save during stallregmask_val_temp <= regmask_val; // temporary save during stallend else beginrs_val_temp <= {1'b1,`RB'b0}; // reset when not stalledrt_val_temp <= {1'b1,`RB'b0}; // reset when not stalledru_val_temp <= {1'b1,`RB'b0}; // reset when not stalledrd_val_temp <= {1'b1,`RB'b0}; // reset when not stalledregmask_val_temp <= {1'b1,`MASKSZ'b0}; // reset when not stalledendendalways_comb begin// Check if result is masked off so that we don't have to wait for operandsmask_off = mask_status_in != `REG_UNUSED && !mask_alternative_in && !vector_in && regmask_val[`MASKSZ] == 0 && regmask_val[0] == 0;waiting = 0;wait_next1 = 0; wait_next2 = 0; wait_next3 = 0;array_error = 0;// check if we need to wait for register valuesif (rs_val[`RB] && rs_status_in == `REG_POINTER && !mask_off) beginwaiting = 1; // value of RS needed in this stage for address calculation. must stall// predict if value will arrive in next clock cyclewait_next1 = predict_tag1_in != rs_val[`TAG_WIDTH-1:0] && predict_tag2_in != rs_val[`TAG_WIDTH-1:0];endif (rt_val[`RB] && rt_status_in >= `REG_INDEX && !mask_off) beginwaiting = 1; // value of RT needed in this stage for address calculation. must stall// predict if value will arrive in next clock cyclewait_next2 = predict_tag1_in != rt_val[`TAG_WIDTH-1:0] && predict_tag2_in != rt_val[`TAG_WIDTH-1:0];endif (rd_val[`RB] && rd_status_in != 0 && result_type_in == `RESULT_MEM && !mask_off) beginwaiting = 1; // value of RD needed in this stage for writing. must stall// predict if value will arrive in next clock cyclewait_next3 = predict_tag1_in != rd_val[`TAG_WIDTH-1:0] && predict_tag2_in != rd_val[`TAG_WIDTH-1:0];endif (regmask_val[`MASKSZ] && mask_status_in != `REG_UNUSED && result_type_in == `RESULT_MEM) beginwaiting = 1; // value of mask needed before write// predict if value will arrive in next clock cyclewait_next3 = predict_tag1_in != regmask_val[`TAG_WIDTH-1:0] && predict_tag2_in != regmask_val[`TAG_WIDTH-1:0];end////////////////////////////////////////////////// calculate address: //////////////////////////////////////////////////// rs is base pointerbase_pointer = rs_val[`RB1:0];if (rt_status_in == `REG_INDEX) begin// rt is scaled indexif (scale_factor_in == `SCALE_OS) begincase (otype) // operand type`OT_INT8: address_index = rt_val[`RB-1:0]; // scale factor 1`OT_INT16: address_index = {rt_val[`RB-2:0],1'b0}; // scale factor 2`OT_INT32, `OT_FLOAT32: address_index = {rt_val[`RB-3:0],2'b0}; // scale factor 4`OT_INT64, `OT_FLOAT64: address_index = {rt_val[`RB-4:0],3'b0}; // scale factor 8`OT_INT128,`OT_FLOAT128: address_index = {rt_val[`RB-5:0],4'b0}; // scale factor 16endcaseend else if (scale_factor_in == `SCALE_MINUS) beginaddress_index = -rt_val[`RB1:0]; // scale factor -1end else beginaddress_index = rt_val[`RB1:0]; // no scale factorendif (index_limit_in) begin// check index limitif (il == 3 && rt_val[`RB1:0] > instruction_in[95:64]|| il == 2 && rt_val[`RB1:0] > instruction_in[`IM2E]) array_error = 1;endend else beginaddress_index = 0; // no indexendif (offset_field_in == `OFFSET_NONE) begin // no offsetaddress_offset = 0;end else if (offset_field_in == `OFFSET_1) begin // 8 bit offset in IM1, scaled by operand sizecase (otype) // operand type`OT_INT8: address_offset = {{56{instruction_in[7]}},instruction_in[`IM1]}; // sign extend IM1`OT_INT16: address_offset = {{55{instruction_in[7]}},instruction_in[`IM1],1'b0}; // sign extend, scale by 2`OT_INT32, `OT_FLOAT32: address_offset = {{54{instruction_in[7]}},instruction_in[`IM1],2'b0}; // sign extend, scale by 4`OT_INT64, `OT_FLOAT64: address_offset = {{53{instruction_in[7]}},instruction_in[`IM1],3'b0}; // sign extend, scale by 8`OT_INT128,`OT_FLOAT128: address_offset = {{52{instruction_in[7]}},instruction_in[`IM1],4'b0}; // sign extend, scale by 16endcaseend else if(offset_field_in == `OFFSET_2) begin // 16 bit offset in IM2, not scaledaddress_offset = {{48{instruction_in[47]}},instruction_in[`IM2E]}; // sign extend IM2;end else if (il == 2) begin // 32 bit offset in IM2address_offset = {{32{instruction_in[63]}},instruction_in[63:32]}; // sign extend IM2;end else if (mode == 1 && op1 == 0) begin // format 3.1.0. Jump with memory offest in IM3address_offset = {{32{instruction_in[95]}},instruction_in[95:64]}; // sign extend IM3;end else begin // format 3.x.x, except 3.1.0address_offset = {{32{instruction_in[95]}},instruction_in[95:64]}; // sign extend IM4;end// calculated addressaddress = base_pointer + address_index + address_offset;// data to write. (mask is handled below)if (category_in == `CAT_MULTI) beginwrite_data <= rd_val; // write registerend else beginwrite_data <= instruction_in[63:32]; // write constantendendalways_ff @(posedge clock) if (clock_enable) beginread_enable_out <= 0;write_enable_out <= 0;if (valid_in && !waiting) begin// output memory address for data cache read and write// must have natural alignmentread_write_address_out <= address;if (result_type_in == `RESULT_MEM && !mask_off && !array_error) begin// memory writeif (otype == `OT_INT8) begin // write 8 bitscase (address[2:0])0: beginwrite_data_out <= write_data;write_enable_out <= 8'b00000001; end1: beginwrite_data_out <= {write_data[7:0],8'b0};write_enable_out <= 8'b00000010; end2: beginwrite_data_out <= {write_data[7:0],16'b0};write_enable_out <= 8'b00000100; end3: beginwrite_data_out <= {write_data[7:0],24'b0};write_enable_out <= 8'b00001000; end4: beginwrite_data_out <= {write_data[7:0],32'b0};write_enable_out <= 8'b00010000; end5: beginwrite_data_out <= {write_data[7:0],40'b0};write_enable_out <= 8'b00100000; end6: beginwrite_data_out <= {write_data[7:0],48'b0};write_enable_out <= 8'b01000000; end7: beginwrite_data_out <= {write_data[7:0],56'b0};write_enable_out <= 8'b10000000; endendcaseend else if (otype == `OT_INT16) begin // write 16 bitscase (address[2:1])0: beginwrite_data_out <= write_data;write_enable_out <= 8'b00000011; end1: beginwrite_data_out <= {write_data[15:0],16'b0};write_enable_out <= 8'b00001100; end2: beginwrite_data_out <= {write_data[15:0],32'b0};write_enable_out <= 8'b00110000; end3: beginwrite_data_out <= {write_data[15:0],48'b0};write_enable_out <= 8'b11000000; endendcaseend else if (otype == `OT_INT32 || otype == `OT_FLOAT32) begin // write 32 bitscase (address[2])0: beginwrite_data_out <= write_data;write_enable_out <= 8'b00001111; end1: beginwrite_data_out <= {write_data[31:0],32'b0};write_enable_out <= 8'b11110000; endendcaseend else begin // write 64 bits (or more)write_data_out <= write_data;write_enable_out <= 8'b11111111;endend else if (rs_status_in == `REG_POINTER && !address_instruction) begin// memory read. Must have natural alignmentread_enable_out <= valid_in && !mask_off && !array_error;write_enable_out <= 0;case (otype)`OT_INT8: read_data_size_out <= `OT_INT8;`OT_INT16: read_data_size_out <= `OT_INT16;`OT_INT32,`OT_FLOAT32: read_data_size_out <= `OT_INT32;default: read_data_size_out <= `OT_INT64;endcaseend// sort operand values, selected by the priority order: immediate, memory, rt, rs, ru, rdoperand1_out <= 0; // value of first operand, bit `RB indicates invalidoperand2_out <= 0; // value of second operand, bit `RB indicates invalidoperand3_out <= 0; // value of last operand, bit `RB indicates invalidif (immediate_field_in != `IMMED_NONE && rs_status_in == `REG_POINTER) begin// both memory and immediate operands.// Last operand is an immediate value calculated below.// Next to last operand is a memory operand retrieved later.// Find remaining register operandif (rt_status_in == `REG_OPERAND) operand1_out <= rt_val;else if (ru_status_in == `REG_OPERAND) operand1_out <= ru_val;else if (rd_status_in == `REG_OPERAND) operand1_out <= rd_val;end else if (immediate_field_in != `IMMED_NONE || rs_status_in == `REG_POINTER) begin// Last operand is an immediate value calculated below or a memory operand retrieved later.// Find remaining register operandsif (rt_status_in == `REG_OPERAND) beginoperand2_out <= rt_val;if (rs_status_in == `REG_OPERAND) operand1_out <= rs_val;else if (ru_status_in == `REG_OPERAND) operand1_out <= ru_val;else if (rd_status_in == `REG_OPERAND) operand1_out <= rd_val;else operand1_out <= rt_val; // possible fallbackend else if (rs_status_in == `REG_OPERAND || rs_status_in == `REG_SYSTEM) beginoperand2_out <= rs_val;if (ru_status_in == `REG_OPERAND) operand1_out <= ru_val;else if (rd_status_in == `REG_OPERAND) operand1_out <= rd_val;else operand1_out <= rs_val; // possible fallback_use_in == `FALLBACK_RSend else if (ru_status_in == `REG_OPERAND) beginoperand2_out <= ru_val;if (rd_status_in == `REG_OPERAND) operand1_out <= rd_val;else operand1_out <= ru_val;end else if (rd_status_in == `REG_OPERAND) beginoperand2_out <= rd_val;operand1_out <= rd_val;endend else begin// last operand is a registerif (rt_status_in == `REG_OPERAND) beginoperand3_out <= rt_val;if (rs_status_in == `REG_OPERAND) beginoperand2_out <= rs_val;if (ru_status_in == `REG_OPERAND) operand1_out <= ru_val;else if (rd_status_in == `REG_OPERAND) operand1_out <= rd_val;else operand1_out <= rs_val;end else if (ru_status_in == `REG_OPERAND) beginoperand2_out <= ru_val;if (rd_status_in == `REG_OPERAND) operand1_out <= rd_val;else operand1_out <= ru_val;end else if (rd_status_in == `REG_OPERAND) beginoperand2_out <= rd_val;operand1_out <= rd_val;endend else if (rs_status_in == `REG_OPERAND) beginoperand3_out <= rs_val;if (ru_status_in == `REG_OPERAND) beginoperand2_out <= ru_val;if (rd_status_in == `REG_OPERAND) operand1_out <= rd_val;else operand1_out <= ru_val;end else if (rd_status_in == `REG_OPERAND) beginoperand2_out <= rd_val;operand1_out <= rd_val;endend else if (ru_status_in == `REG_OPERAND) begin // should not occuroperand3_out <= ru_val;if (rd_status_in == `REG_OPERAND) beginoperand2_out <= rd_val;operand1_out <= rd_val;end else beginoperand1_out <= ru_val;endend else if (rd_status_in == `REG_OPERAND) beginoperand3_out <= rd_val;operand1_out <= rd_val;endend// look for immediate operand, and process it if necessaryif (immediate_field_in != `IMMED_NONE) beginif (immediate_field_in == `IMMED_1) begin // sign_extend 8 bit immediate operandif (format_in == `FORMAT_E) beginoperand3_out <= {{(`RB-8){instruction_in[`IM3EXS]}},instruction_in[`IM3EX]};end else if (format_in == `FORMAT_C && category_in == `CAT_JUMP) begin// jump in format 1.7C and 2.5.4Coperand3_out <= {{(`RB-8){instruction_in[15]}},instruction_in[15:8]};end else begin // format Boperand3_out <= {{(`RB-8){instruction_in[`IM1S]}},instruction_in[`IM1]};endendif (immediate_field_in == `IMMED_2) begin // sign_extend 16 bit immediate operandif (format_in == `FORMAT_C) begin // format C: sign extend (IM2,IM1)operand3_out <= {{(`RB-16){instruction_in[15]}},instruction_in[15:0]};// special casesif (mode == 1) beginif (op1 == `II_MOVEU11) operand3_out <= instruction_in[15:0]; // zero extendedif (op1 == `II_ADDSHIFT16_11) begin`ifdef SUPPORT_64BIToperand3_out <= {{(`RB-32){instruction_in[15]}},instruction_in[15:0],16'b0}; // shift left by 16`elseoperand3_out <= {instruction_in[15:0],16'b0}; // shift left by 16`endifendif ((op1 & -2) == `II_SHIFT_MOVE_11 || op1 >= `II_SHIFT_ADD_11 && op1 <= `II_SHIFT_XOR_11+1) begin // IM2 << IM1if (instruction_in[`IM1] >= 64) operand3_out <= 0;else operand3_out <= {{(`RB-8){instruction_in[15]}},instruction_in[15:8]} << instruction_in[5:0];endendend else beginoperand3_out <= {{(`RB-16){instruction_in[`IM2ES]}},instruction_in[`IM2E]};// special casesif (il == 2 && ((mode == 0 && !M) || mode == 2) && mode2 == 7 && !option_bits_im3) begin// format 2.0.7 and 2.2.7 have shiftoperand3_out <= {{(`RB-16){instruction_in[47]}},instruction_in[`IM2E]} << instruction_in[`IM3E];endendendif (immediate_field_in == `IMMED_3) begin`ifdef SUPPORT_64BITif (il == 3 && ((mode == 0 && !M) || mode == 2) && mode2 == 7 && otype < `OT_FLOAT32) begin// format 3.0.7 and 3.2.7 have shiftoperand3_out <= {{32{instruction_in[95]}},instruction_in[95:64]} << instruction_in[`IM2E];end else if (il == 3 && format_in == `FORMAT_E) begin// other format 3Eoperand3_out <= {{32{instruction_in[95]}},instruction_in[95:64]};end else if (il == 3 && mode == 0 && M) begin// format 3.8operand3_out <= instruction_in[95:32];end else begin// format 2.xoperand3_out <= {{32{instruction_in[63]}},instruction_in[63:32]};end`elseif (((mode == 0 && !M) || mode == 2) && mode2 == 7 && otype < `OT_FLOAT32) begin// format 3.0.7 and 3.2.7 have shiftoperand3_out <= instruction_in[95:64] << instruction_in[`IM2E];end else if (il == 3 && format_in == `FORMAT_E) beginoperand3_out <= instruction_in[95:64];end else beginoperand3_out <= instruction_in[63:32];end`endif// special casesif (il == 2 && mode == 1 && M) beginif (op1 == `II_ADDU_29 || op1 == `II_SUBU_29) beginoperand3_out <= instruction_in[63:32]; // zero extendendif (op1 == `II_MOVE_HI_29 || (op1 >= `II_ADD_HI_29 && op1 <= `II_XOR_HI_29)) begin// immediate constant is high word of 64 bits`ifdef SUPPORT_64BIToperand3_out <= {instruction_in[63:32],32'b0}; // high word`elseoperand3_out <= 0; // there is no high word`endifendendend//if (category_in == `CAT_JUMP) begin // unnecessary checkif (il == 2 && mode == 5) begin// immediate operands in jump instructions 2.5.xif (op1 == 0) begin// format 2.5.0A: jump with three registers, and 24 bit jump offset, no immediateend else if (op1 == 1) begin// format 2.5.1B: jump with one register, one 16 bit operand, and 16 bit jum offsetoperand3_out <= {{48{instruction_in[47]}},instruction_in[47:32]}; // sign extend 16 bit operandend else if (op1 == 4) begin// format 2.5.4C: jump with one register, one 8 bit operand, and 32 bit offsetoperand3_out <= {{56{instruction_in[15]}},instruction_in[15:8]}; // sign extend 8 bit operandend else if (op1 == 5) begin// format 2.5.5: jump with one register, one 32 bit operand, and 8 bit offsetoperand3_out <= {{32{instruction_in[63]}},instruction_in[63:32]}; // sign extend 32 bit operandend else if (op1 == 7) begin// format 2.5.7: system call. 16 bit and 32 bit constantsoperand3_out <= {instruction_in[63:32],16'b0,instruction_in[15:0]}; // 32 bit module ID, 16 bit function IDendendif (il == 3 && mode == 1) begin// immedate operands in jump instructions 3.1.xif (op1 == 0) begin// format 3.1.0: jump with memory operand and 32 bit offset. no immediateend else if (op1 == 1) begin // && op1 == `IJ_SYSCALL// jump format 3.1.1if (instruction_in[5:0] < `IJ_SYSCALL) beginoperand3_out <= instruction_in[95:64];end else begin// format 3.1.1: system call with 32 bit module ID and 32 bit function ID`ifdef SUPPORT_64BIToperand3_out <= instruction_in[95:32];`elseoperand3_out <= {instruction_in[79:64],instruction_in[47:32]};`endifendendendoperand3_out[`RB] <= 0; // indicate not missingendif (address_instruction) beginoperand3_out <= address; // address instructionendif (fallback_use_in > `FALLBACK_SOURCE) begin// separate fallback register. Check if fallback zeroif (fallback_use_in == `FALLBACK_RU && instruction_in[`RU] == 31) operand1_out <= 0;if (fallback_use_in == `FALLBACK_RS && instruction_in[`RS] == 31) operand1_out <= 0;if (fallback_use_in == `FALLBACK_RT && instruction_in[`RT] == 31) operand1_out <= 0;end// output everything elseregmask_val_out <= regmask_val;instruction_pointer_out <= instruction_pointer_in; // address of current instructioninstruction_out <= instruction_in[63:0]; // first two words of instructiontag_val_out <= tag_val_in; // instruction tag valuevector_out <= vector_in; // this is a vector instructioncategory_out <= category_in; // 00: multiformat, 01: single format, 10: jumpformat_out <= format_in; // 00: format A, 01: format E, 10: format B, 11: format C (format D never goes through decoder)mask_status_out <= mask_status_in == `REG_OPERAND;// mask register is usedmask_alternative_out <= mask_alternative_in; // mask register and fallback register used for alternative purposesfallback_use_out <= fallback_use_in; // use of fallback registernum_operands_out <= num_operands_in; // number of source operandsresult_type_out <= result_type_in; // type of result: 0: register, 1: system register, 2: memory, 3: other or nothingoffset_field_out <= offset_field_in; // address offset. 0: none, 1: 8 bit, possibly scaled, 2: 16 bit, 3: 32 bitimmediate_field_out <= immediate_field_in; // immediate data field. 0: none, 1: 8 bit, 2: 16 bit, 3: 32 or 64 bitscale_factor_out <= scale_factor_in; // 00: index is not scaled, 01: index is scaled by operand size, 10: index is scaled by -1memory_operand_out <= (rs_status_in >= `REG_POINTER) && !address_instruction; // The instruction has a memory operandarray_error_out <= array_error; // Array index exceeds limit;options3_out <= option_bits_im3; // IM3 used for option bitsendendalways_ff @(posedge clock) if (clock_enable) beginlast_stall <= (stall_in || waiting) && valid_in;last_valid <= valid_in;stall_predict_out <= (wait_next1 | wait_next2 | wait_next3) && valid_in; // predict stalling in next clock cyclelast_tag_val <= tag_val_in;if (reset) beginvalid_out <= 0;end else begin// avoid sending an instruction that is not ready, or an instruction that has already been sentvalid_out <= valid_in && !waiting && !stall_in && (new_instruction | !valid_out);end// temporary debug outputsdebug1_out <= {address_offset[7:0], address_index[7:0], base_pointer[15:0]};debug2_out <= write_data;debug3_out[0] <= waiting;debug3_out[1] <= stall_in;debug3_out[2] <= last_stall;debug3_out[4] <= wait_next1;debug3_out[5] <= wait_next2;debug3_out[6] <= wait_next3;debug3_out[8] <= rs_val[`RB] && (rs_status_in >= `REG_POINTER) && !mask_off;debug3_out[9] <= rt_val[`RB] && (rt_status_in >= `REG_INDEX) && !mask_off;debug3_out[10] <= rd_val[`RB] && (rd_status_in != 0)&& result_type_in == `RESULT_MEM && !mask_off;debug3_out[11] <= new_instruction;debug3_out[12] <= valid_in;debug3_out[14] <= valid_out; // preceding valid outdebug3_out[15] <= last_valid;debug3_out[16] <= rs_val[`RB];debug3_out[17] <= rt_val[`RB];debug3_out[18] <= rd_val[`RB];debug3_out[20] <= rs_val_temp[`RB];debug3_out[21] <= rt_val_temp[`RB];debug3_out[22] <= rd_val_temp[`RB];debug3_out[24] <= write_en1 && rt_val_in[`TAG_WIDTH-1:0] == write_tag1_in;debug3_out[25] <= write_en2 && rt_val_in[`TAG_WIDTH-1:0] == write_tag2_in;debug3_out[26] <= write_en1 && rd_val_in[`TAG_WIDTH-1:0] == write_tag1_in;debug3_out[27] <= write_en2 && rd_val_in[`TAG_WIDTH-1:0] == write_tag2_in;debug3_out[28] <= option_bits_im3;debug3_out[31] <= mask_off;endendmodule
Go to most recent revision | Compare with Previous | Blame | View Log
