pacoblaze_idu.v
来自「PacoBlaze is a from-scratch synthesizabl」· Verilog 代码 · 共 329 行
V
329 行
/* Copyright (C) 2004, 2006 Pablo Bleyer Kocik. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//** @file PacoBlaze Instruction Decode Unit.*/`ifndef PACOBLAZE_IDU_V_`define PACOBLAZE_IDU_V_`include "pacoblaze_inc.v"module `PACOBLAZE_IDU( instruction, operation, shift_operation, shift_direction, shift_constant, operand_selection, x_address, y_address, implied_value, port_address,`ifdef HAS_SCRATCH_MEMORY scratch_address,`endif code_address, conditional, condition_flags, interrupt_enable`ifdef HAS_DEBUG , debug_opcode`endif);input [`code_width-1:0] instruction; ///< Instructionoutput reg [`operation_width-1:0] operation; ///< Main operationoutput [2:0] shift_operation; ///< Rotate/shift operationoutput shift_direction; ///< Rotate/shift left(0)/right(1)output shift_constant; ///< Shift constant valueoutput operand_selection; ///< Operand selection (k/p/s:0, y:1)output [`register_depth-1:0] x_address, y_address; ///< Operation x source/target, y sourceoutput [`operand_width-1:0] implied_value; ///< Operand constant sourceoutput [`port_depth-1:0] port_address; ///< Port address`ifdef HAS_SCRATCH_MEMORYoutput [`scratch_depth-1:0] scratch_address; ///< Scratchpad address`endifoutput [`code_depth-1:0] code_address; ///< Program addressoutput conditional; ///< Conditional operation (unconditional(0)/conditional(1))output [1:0] condition_flags; ///< Condition flags on zero and carryoutput interrupt_enable; ///< Interrupt disable(0)/enable(1)`ifdef HAS_DEBUGoutput reg [8*`debug_width:1] debug_opcode; ///< Operation debug stringreg [2*8:1] debug_conditional; ///< Conditional debug stringreg [5*8:1] debug_operand; ///< Operand debug stringreg [7*8:1] debug_interrupt; ///< Interrupt debug string`endif`ifdef PACOBLAZE1wire [3:0] instruction_0 = (instruction[15:12] == `opcode_reg) ? instruction[3:0] : instruction[15:12];wire [3:0] instruction_1 = instruction[9:6];assign x_address = instruction[11:8];assign y_address = instruction[7:4];assign operand_selection = (instruction[15] && instruction[13]) ? instruction[12] : instruction[15];assign code_address = instruction[7:0];assign interrupt_enable = instruction[5];`endif`ifdef PACOBLAZE2wire [3:0] instruction_0 = {instruction[17], instruction[15:13]};wire instruction_1 = instruction[16];assign x_address = instruction[12:8];assign y_address = instruction[7:3];assign operand_selection = instruction[16];assign code_address = instruction[9:0];assign interrupt_enable = instruction[0];`endif`ifdef PACOBLAZE3wire [4:0] instruction_0 = instruction[17:13];assign x_address = instruction[11:8];assign y_address = instruction[7:4];assign operand_selection = instruction[12];assign code_address = instruction[9:0];assign interrupt_enable = instruction[0];assign scratch_address = instruction[5:0];`endif`ifdef PACOBLAZE3Mwire [4:0] instruction_0 = instruction[17:13];assign x_address = instruction[11:8];assign y_address = instruction[7:4];assign operand_selection = instruction[12];assign code_address = instruction[9:0];assign interrupt_enable = instruction[0];assign scratch_address = instruction[5:0];`endifassign shift_direction = instruction[3];assign shift_operation = instruction[2:1];assign shift_constant = instruction[0];assign conditional = instruction[12];assign condition_flags = instruction[11:10];assign implied_value = instruction[7:0];assign port_address = instruction[7:0];`ifdef PACOBLAZE1always @(instruction_0, instruction_1)`endif`ifdef PACOBLAZE2always @(instruction_0, instruction_1)`endif`ifdef PACOBLAZE3always @(instruction_0)`endif`ifdef PACOBLAZE3Malways @(instruction_0)`endifbegin `ifdef HAS_DEBUG operation = 'hx; // default `else operation = 'h0; // default `endif // synthesis parallel_case full_case`ifdef PACOBLAZE1 casex (instruction_0)`else case (instruction_0)`endif `opcode_load: operation = `op_load; `opcode_add: operation = `op_add; `opcode_addcy: operation = `op_addcy; `opcode_and: operation = `op_and; `opcode_or: operation = `op_or; `opcode_rs: operation = `op_rs; `opcode_sub: operation = `op_sub; `opcode_subcy: operation = `op_subcy; `opcode_xor: operation = `op_xor;`ifdef PACOBLAZE1 {`opcode_ctl, 1'b?}: casex (instruction_1) {`opcode_jump, 2'b??}: operation = `op_jump; {`opcode_call, 2'b??}: operation = `op_call; `opcode_return: operation = `op_return; `opcode_returni: operation = `op_returni; `opcode_interrupt: operation = `op_interrupt; endcase {`opcode_input, 1'b?}: operation = `op_input; {`opcode_output, 1'b?}: operation = `op_output;`endif // PACOBLAZE1`ifdef PACOBLAZE2 `opcode_jump: // == `opcode_return if (instruction_1) operation = `op_jump; else operation = `op_return; `opcode_call: if (instruction_1) operation = `op_call; `opcode_interrupt: // == `opcode_returni if (instruction_1) operation = `op_interrupt; else operation = `op_returni; `opcode_input: operation = `op_input; `opcode_output: operation = `op_output;`endif // PACOBLAZE2`ifdef PACOBLAZE3 `opcode_jump: operation = `op_jump; `opcode_call: operation = `op_call; `opcode_return: operation = `op_return; `opcode_returni: operation = `op_returni; `opcode_interrupt: operation = `op_interrupt; `opcode_input: operation = `op_input; `opcode_output: operation = `op_output;`endif // PACOBLAZE3`ifdef PACOBLAZE3M `opcode_jump: operation = `op_jump; `opcode_call: operation = `op_call; `opcode_return: operation = `op_return; `opcode_returni: operation = `op_returni; `opcode_interrupt: operation = `op_interrupt; `opcode_input: operation = `op_input; `opcode_output: operation = `op_output;`endif // PACOBLAZE3M // PB3`ifdef HAS_COMPARE_OPERATION `opcode_compare: operation = `op_compare;`endif`ifdef HAS_TEST_OPERATION `opcode_test: operation = `op_test;`endif`ifdef HAS_SCRATCH_MEMORY `opcode_fetch: operation = `op_fetch; `opcode_store: operation = `op_store;`endif // PB3M`ifdef HAS_MUL_OPERATION `opcode_mul: operation = `op_mul;`endif`ifdef HAS_WIDE_ALU `opcode_addw: operation = `op_addw; `opcode_addwcy: operation = `op_addwcy; `opcode_subw: operation = `op_subw; `opcode_subwcy: operation = `op_subwcy;`endif // default: operation = 0; endcaseend`ifdef HAS_DEBUG`include "pacoblaze_util.v"always @(operand_selection, x_address, y_address, implied_value) if (operand_selection) debug_operand = {"s", numtohex(x_address), ",", "s", numtohex(y_address)}; else debug_operand = {"s", numtohex(x_address), ",", numtohex(implied_value[7:4]), numtohex(implied_value[3:0])};always @(conditional, condition_flags) case ({conditional, condition_flags}) // 3b'0??: debug_conditional = ""; {1'b0, `flag_z}: debug_conditional = `os_z; {1'b0, `flag_nz}: debug_conditional = `os_nz; {1'b0, `flag_c}: debug_conditional = `os_c; {1'b0, `flag_nc}: debug_conditional = `os_nc; default: debug_conditional = " "; endcasealways @(interrupt_enable) if (interrupt_enable) debug_interrupt = `os_enable; else debug_interrupt = `os_disable;always @(operation, shift_direction, shift_operation, shift_constant, debug_operand, debug_conditional, debug_interrupt, code_address) case (operation) `op_load: debug_opcode = {`os_load, " ", debug_operand}; `op_add: debug_opcode = {`os_add, " ", debug_operand}; `op_addcy: debug_opcode = {`os_addcy, " ", debug_operand}; `op_and: debug_opcode = {`os_and, " ", debug_operand}; `op_or: debug_opcode = {`os_or, " ", debug_operand}; `op_rs: // debug_opcode = `os_rs; case ({shift_direction, shift_operation, shift_constant}) 4'b1_11_0: debug_opcode = {`os_sr0, " s", numtohex(x_address)}; 4'b1_11_1: debug_opcode = {`os_sr1, " s", numtohex(x_address)}; 4'b1_01_0: debug_opcode = {`os_srx, " s", numtohex(x_address)}; 4'b1_00_0: debug_opcode = {`os_sra, " s", numtohex(x_address)}; 4'b1_10_0: debug_opcode = {`os_rr, " s", numtohex(x_address)}; 4'b0_11_0: debug_opcode = {`os_sl0, " s", numtohex(x_address)}; 4'b0_11_1: debug_opcode = {`os_sl1, " s", numtohex(x_address)}; 4'b0_10_0: debug_opcode = {`os_slx, " s", numtohex(x_address)}; 4'b0_00_0: debug_opcode = {`os_sla, " s", numtohex(x_address)}; 4'b0_01_0: debug_opcode = {`os_rl, " s", numtohex(x_address)}; default: debug_opcode = `os_invalid; endcase `op_sub: debug_opcode = {`os_sub, " ", debug_operand}; `op_subcy: debug_opcode = {`os_subcy, " ", debug_operand}; `op_xor: debug_opcode = {`os_xor, " ", debug_operand};`ifdef HAS_MUL_OPERATION `op_mul: debug_opcode = {`os_mul, " ", debug_operand};`endif `op_jump: debug_opcode = {`os_jump, " ", debug_conditional, " ", adrtohex(code_address)}; `op_call: debug_opcode = {`os_call, " ", debug_conditional, " ", adrtohex(code_address)}; `op_return: debug_opcode = {`os_return, " ", debug_conditional}; `op_returni: debug_opcode = {`os_returni, " ", debug_interrupt}; `op_interrupt: debug_opcode = {`os_interrupt, " ", debug_interrupt}; `op_input: debug_opcode = {`os_input, " ", debug_operand}; `op_output: debug_opcode = {`os_output, " ", debug_operand};`ifdef HAS_COMPARE_OPERATION `op_compare: debug_opcode = {`os_compare, " ", debug_operand};`endif`ifdef HAS_TEST_OPERATION `os_test: debug_opcode = {`os_test, " ", debug_operand};`endif`ifdef HAS_SCRATCH_MEMORY `op_fetch: debug_opcode = {`os_fetch, " ", debug_operand}; `op_store: debug_opcode = {`os_store, " ", debug_operand};`endif default: debug_opcode = `os_invalid; endcase`endif // HAS_DEBUGendmodule`endif // PACOBLAZE_IDU_V_
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?