diff --git a/core/priority_encoder.sv b/core/priority_encoder.sv new file mode 100644 index 0000000..5980fe1 --- /dev/null +++ b/core/priority_encoder.sv @@ -0,0 +1,68 @@ +/* + * Copyright © 2021 Eric Matthews, Lesley Shannon + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Initial code developed under the supervision of Dr. Lesley Shannon, + * Reconfigurable Computing Lab, Simon Fraser University. + * + * Author(s): + * Eric Matthews + */ + +//////////////////////////////////////////////////// +//Highest Priority for: Index Zero +//Look-up Table based +//Max width of 12 +//////////////////////////////////////////////////// +module priority_encoder + #( + parameter WIDTH = 4 + ) + ( + input logic [WIDTH-1:0] priority_vector, + output logic [(WIDTH == 1) ? 0 : ($clog2(WIDTH)-1) : 0] encoded_result + ); + //////////////////////////////////////////////////// + //Width Check + if (WIDTH > 12) + $error("Max priority encoder width exceeded!"); + + localparam LOG2_WIDTH = $clog2(WIDTH); + //////////////////////////////////////////////////// + //Implementation + + generate + if (WIDTH == 1) + assign encoded_result = 0; + else begin + + //Table generation for priority encoder + function [2**WIDTH-1:0][LOG2_WIDTH-1 : 0] table_gen (); + for (int i = 0; i < 2**WIDTH; i++) begin //Loop through all memory addresses + table_gen[i] = LOG2_WIDTH'(WIDTH - 1);//Initialize to lowest priority + for (int j = (WIDTH - 2); j >= 0; j--) begin//Check each bit in increasing priority + if (i[j])//If bit is set update table value with that bit's index + table_gen[i] = LOG2_WIDTH'(j); + end + end + endfunction + + //Initialize Table + const logic [2**WIDTH-1:0][LOG2_WIDTH-1 : 0] encoder_rom = table_gen(); + + assign encoded_result = encoder_rom[priority_vector]; + end + endgenerate + +endmodule diff --git a/tools/taiga_compile_order b/tools/taiga_compile_order index 421353c..8e8f8b2 100644 --- a/tools/taiga_compile_order +++ b/tools/taiga_compile_order @@ -30,6 +30,7 @@ core/one_hot_occupancy.sv core/binary_occupancy.sv core/taiga_fifo.sv core/shift_counter.sv +core/priority_encoder.sv core/set_clr_reg_with_rst.sv