|
| 1 | +// Copyright © 2019-2023 |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +`include "VX_define.vh" |
| 15 | + |
| 16 | +module VX_dispatch import VX_gpu_pkg::*; #( |
| 17 | + parameter `STRING INSTANCE_ID = "", |
| 18 | + parameter ISSUE_ID = 0 |
| 19 | +) ( |
| 20 | + input wire clk, |
| 21 | + input wire reset, |
| 22 | + |
| 23 | +`ifdef PERF_ENABLE |
| 24 | + output wire [NUM_EX_UNITS-1:0][PERF_CTR_BITS-1:0] perf_stalls, |
| 25 | + output wire [NUM_EX_UNITS-1:0][PERF_CTR_BITS-1:0] perf_instrs, |
| 26 | +`endif |
| 27 | + // inputs |
| 28 | + VX_operands_if.slave operands_if, |
| 29 | + |
| 30 | + // outputs |
| 31 | + VX_dispatch_if.master dispatch_if [NUM_EX_UNITS] |
| 32 | +); |
| 33 | + `UNUSED_SPARAM (INSTANCE_ID) |
| 34 | + `UNUSED_PARAM (ISSUE_ID) |
| 35 | + |
| 36 | + localparam OUT_DATAW = $bits(dispatch_t); |
| 37 | + |
| 38 | + wire [NUM_EX_UNITS-1:0] operands_ready_in; |
| 39 | + assign operands_if.ready = operands_ready_in[operands_if.data.ex_type]; |
| 40 | + |
| 41 | + for (genvar i = 0; i < NUM_EX_UNITS; ++i) begin : g_buffers |
| 42 | + VX_elastic_buffer #( |
| 43 | + .DATAW (OUT_DATAW), |
| 44 | + .SIZE (2), |
| 45 | + .OUT_REG (1) |
| 46 | + ) buffer ( |
| 47 | + .clk (clk), |
| 48 | + .reset (reset), |
| 49 | + .valid_in (operands_if.valid && (operands_if.data.ex_type == EX_BITS'(i))), |
| 50 | + .ready_in (operands_ready_in[i]), |
| 51 | + .data_in ({ |
| 52 | + operands_if.data.uuid, |
| 53 | + operands_if.data.wis, |
| 54 | + operands_if.data.sid, |
| 55 | + operands_if.data.tmask, |
| 56 | + operands_if.data.PC, |
| 57 | + operands_if.data.wb, |
| 58 | + operands_if.data.wr_xregs, |
| 59 | + operands_if.data.rd, |
| 60 | + operands_if.data.op_type, |
| 61 | + operands_if.data.op_args, |
| 62 | + operands_if.data.rs1_data, |
| 63 | + operands_if.data.rs2_data, |
| 64 | + operands_if.data.rs3_data, |
| 65 | + operands_if.data.sop, |
| 66 | + operands_if.data.eop |
| 67 | + }), |
| 68 | + .data_out (dispatch_if[i].data), |
| 69 | + .valid_out (dispatch_if[i].valid), |
| 70 | + .ready_out (dispatch_if[i].ready) |
| 71 | + ); |
| 72 | + end |
| 73 | + |
| 74 | +`ifdef PERF_ENABLE |
| 75 | + reg [NUM_EX_UNITS-1:0][PERF_CTR_BITS-1:0] perf_stalls_r; |
| 76 | + reg [NUM_EX_UNITS-1:0][PERF_CTR_BITS-1:0] perf_instrs_r; |
| 77 | + |
| 78 | + wire operands_if_fire = operands_if.valid && operands_if.ready; |
| 79 | + wire operands_if_stall = operands_if.valid && ~operands_if.ready; |
| 80 | + |
| 81 | + for (genvar i = 0; i < NUM_EX_UNITS; ++i) begin : g_perf_stalls |
| 82 | + always @(posedge clk) begin |
| 83 | + if (reset) begin |
| 84 | + perf_stalls_r[i] <= '0; |
| 85 | + perf_instrs_r[i] <= '0; |
| 86 | + end else begin |
| 87 | + perf_stalls_r[i] <= perf_stalls_r[i] + PERF_CTR_BITS'(operands_if_stall && operands_if.data.ex_type == EX_BITS'(i)); |
| 88 | + perf_instrs_r[i] <= perf_instrs_r[i] + PERF_CTR_BITS'(operands_if_fire && operands_if.data.ex_type == EX_BITS'(i) && operands_if.data.eop); |
| 89 | + end |
| 90 | + end |
| 91 | + assign perf_stalls[i] = perf_stalls_r[i]; |
| 92 | + assign perf_instrs[i] = perf_instrs_r[i]; |
| 93 | + end |
| 94 | +`endif |
| 95 | + |
| 96 | +endmodule |
0 commit comments