バレルシフタって、こんなんじゃなかったかな~?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module BARREL_SHIFTER(indata, val, outdata); | |
| parameter integer data_bits = 64; | |
| parameter integer val_bits = 32; | |
| input [data_bits-1:0] indata; | |
| input [ val_bits-1:0] val; | |
| output [data_bits-1:0] outdata; | |
| function integer calc_max(input integer bits); | |
| for (calc_max = 1; (2**calc_max) <= bits; calc_max = calc_max + 1) begin end | |
| endfunction | |
| localparam integer val_max = calc_max(data_bits); | |
| function [data_bits-1:0] shift_constant( | |
| input [data_bits-1:0] indata, | |
| input integer val | |
| ); | |
| integer i; | |
| for (i = 0 ; i < data_bits ; i = i+1) begin | |
| if (i >= val) | |
| shift_constant[i] = indata[i-val]; | |
| else | |
| shift_constant[i] = 1'b0; | |
| end | |
| endfunction | |
| function [data_bits-1:0] shift( | |
| input [data_bits-1:0] indata, | |
| input [ val_bits-1:0] val | |
| ); | |
| integer i; | |
| shift = indata; | |
| for (i = 0 ; i < val_bits ; i = i+1) begin | |
| if (val[i] == 1'b1) | |
| if (i < val_max) | |
| shift = shift_constant(shift,2**i); | |
| else | |
| shift = 0; | |
| end | |
| endfunction | |
| assign outdata = shift(indata, val); | |
| endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment