forked from libre-chip/cpu
add helper functions for creating instructions
This commit is contained in:
parent
5b15f4a6b4
commit
4ff75313e7
3 changed files with 188 additions and 94 deletions
|
|
@ -3,10 +3,7 @@
|
|||
|
||||
use cpu::{
|
||||
config::{CpuConfig, UnitConfig},
|
||||
instruction::{
|
||||
AddSubMOp, AluCommonMOp, CommonMOp, LogicalMOp, MOp, MOpDestReg, MOpRegNum,
|
||||
OutputIntegerMode, COMMON_MOP_2_IMM_WIDTH, COMMON_MOP_3_IMM_WIDTH,
|
||||
},
|
||||
instruction::{AddSubMOp, LogicalMOp, MOp, MOpDestReg, MOpRegNum, OutputIntegerMode},
|
||||
reg_alloc::{reg_alloc, FetchedDecodedMOp},
|
||||
register::{FlagsMode, PRegFlagsPowerISA},
|
||||
unit::{GlobalState, UnitKind},
|
||||
|
|
@ -47,97 +44,66 @@ fn test_reg_alloc() {
|
|||
),
|
||||
},
|
||||
);
|
||||
let insns = std::array::from_fn::<_, 4, _>(|i| {
|
||||
MOp.AluBranch(MOp.AluBranch.AddSubI(
|
||||
let insns_init: [Expr<MOp>; 4] = std::array::from_fn(|i| {
|
||||
AddSubMOp::add_sub_i(
|
||||
#[hdl]
|
||||
AddSubMOp {
|
||||
alu_common: #[hdl]
|
||||
AluCommonMOp {
|
||||
common: CommonMOp::new(
|
||||
0_hdl_u0,
|
||||
#[hdl]
|
||||
MOpDestReg {
|
||||
normal_regs: #[hdl]
|
||||
[
|
||||
#[hdl]
|
||||
MOpRegNum { value: i as u8 + 1 },
|
||||
MOpRegNum::const_zero(),
|
||||
],
|
||||
flag_regs: #[hdl]
|
||||
[HdlSome(()), HdlNone()],
|
||||
},
|
||||
[0u8; 2],
|
||||
0x12345678u32.cast_to(SInt[COMMON_MOP_2_IMM_WIDTH]),
|
||||
),
|
||||
output_integer_mode: OutputIntegerMode.DupLow32(),
|
||||
},
|
||||
invert_src0: false,
|
||||
src1_is_carry_in: false,
|
||||
invert_carry_in: false,
|
||||
add_pc: false,
|
||||
MOpDestReg {
|
||||
normal_regs: #[hdl]
|
||||
[
|
||||
#[hdl]
|
||||
MOpRegNum { value: i as u8 + 1 },
|
||||
MOpRegNum::const_zero(),
|
||||
],
|
||||
flag_regs: #[hdl]
|
||||
[HdlSome(()), HdlNone()],
|
||||
},
|
||||
))
|
||||
})
|
||||
.into_iter()
|
||||
.chain(
|
||||
[
|
||||
MOp.AluBranch(MOp.AluBranch.AddSub(
|
||||
#[hdl]
|
||||
AddSubMOp {
|
||||
alu_common: #[hdl]
|
||||
AluCommonMOp {
|
||||
common: CommonMOp::new(
|
||||
0_hdl_u0,
|
||||
#[hdl]
|
||||
MOpDestReg {
|
||||
normal_regs: #[hdl]
|
||||
[
|
||||
#[hdl]
|
||||
MOpRegNum { value: 1u8 },
|
||||
MOpRegNum::const_zero(),
|
||||
],
|
||||
flag_regs: #[hdl]
|
||||
[HdlSome(()), HdlNone()],
|
||||
},
|
||||
[1u8, 0, 0],
|
||||
1.cast_to(SInt[COMMON_MOP_3_IMM_WIDTH]),
|
||||
),
|
||||
output_integer_mode: OutputIntegerMode.Full64(),
|
||||
},
|
||||
invert_src0: false,
|
||||
src1_is_carry_in: false,
|
||||
invert_carry_in: false,
|
||||
add_pc: false,
|
||||
},
|
||||
)),
|
||||
MOp.AluBranch(MOp.AluBranch.Logical(
|
||||
#[hdl]
|
||||
LogicalMOp {
|
||||
alu_common: #[hdl]
|
||||
AluCommonMOp {
|
||||
common: CommonMOp::new(
|
||||
0_hdl_u0,
|
||||
#[hdl]
|
||||
MOpDestReg {
|
||||
normal_regs: [
|
||||
#[hdl]
|
||||
MOpRegNum { value: 2u8 },
|
||||
MOpRegNum::const_zero(),
|
||||
],
|
||||
flag_regs: [HdlNone(), HdlSome(())],
|
||||
},
|
||||
[2u8, 4u8],
|
||||
SInt[COMMON_MOP_2_IMM_WIDTH].zero(),
|
||||
),
|
||||
output_integer_mode: OutputIntegerMode.Full64(),
|
||||
},
|
||||
lut: 0b0110_hdl_u4,
|
||||
},
|
||||
)),
|
||||
]
|
||||
.into_iter()
|
||||
.cycle(),
|
||||
);
|
||||
[0u8; 2],
|
||||
0x12345678u32.cast_to_static(),
|
||||
OutputIntegerMode.DupLow32(),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
});
|
||||
let insns_loop = [
|
||||
AddSubMOp::add_sub(
|
||||
#[hdl]
|
||||
MOpDestReg {
|
||||
normal_regs: #[hdl]
|
||||
[
|
||||
#[hdl]
|
||||
MOpRegNum { value: 1u8 },
|
||||
MOpRegNum::const_zero(),
|
||||
],
|
||||
flag_regs: #[hdl]
|
||||
[HdlSome(()), HdlNone()],
|
||||
},
|
||||
[1u8, 0, 0],
|
||||
1.cast_to_static(),
|
||||
OutputIntegerMode.Full64(),
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
),
|
||||
LogicalMOp::logical(
|
||||
#[hdl]
|
||||
MOpDestReg {
|
||||
normal_regs: [
|
||||
#[hdl]
|
||||
MOpRegNum { value: 2u8 },
|
||||
MOpRegNum::const_zero(),
|
||||
],
|
||||
flag_regs: [HdlNone(), HdlSome(())],
|
||||
},
|
||||
[2u8, 4u8],
|
||||
0.cast_to_static(),
|
||||
OutputIntegerMode.Full64(),
|
||||
0b0110_hdl_u4,
|
||||
),
|
||||
];
|
||||
let insns = insns_init.into_iter().chain(insns_loop.into_iter().cycle());
|
||||
let mut insn_index = 0;
|
||||
for cycle in 0..20 {
|
||||
for fetch_index in 0..config.fetch_width.get() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue