Skip to content

Commit e5dfbd3

Browse files
committed
sys/huge added branch/jump instructions (30825)
1 parent 217cc9c commit e5dfbd3

1 file changed

Lines changed: 50 additions & 3 deletions

File tree

sys/huge/huge.vadl

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ instruction set architecture HUGE = {
110110
, imm3 = imm as SIntD << 48 // sign extended shifted immediate value
111111
}
112112

113+
format BranchFormat : Instr = // branch format
114+
{ opsize : Bits<2> // operation size
115+
, cond : Bits<3> // condition
116+
, ccsz : Bits<2> // condition size
117+
, cregl : IndexC // condition register left
118+
, cregr : IndexC // condition register right
119+
, op : Bits<7> // opcode
120+
, regd : Index // destination register (return address)
121+
, off : Bits<37> // branch offset
122+
, offset = off as SIntD << 3 // sign extended and shifted branch offset
123+
}
124+
113125
model-type InstrModel = (Id, Str, CondRec, InstrRec, ShiftRec) -> IsaDefs
114126
model-type OperandModel = (InstrModel, Id, Str, CondRec, InstrRec) -> IsaDefs
115127

@@ -125,6 +137,21 @@ instruction set architecture HUGE = {
125137
register(regd), ',', register(regl), ',', register(regr), $sft.asms)
126138
}
127139

140+
model JumpInstr (size: Id, sizeStr: Str, c : CondRec, i : InstrRec, sft : ShiftRec) : IsaDefs = {
141+
instruction AsId ($i.id, $size, $sft.sftId, $c.condStr) : ArithmeticRegFormat =
142+
if ($c.condEx) then
143+
let return = PC.next in {
144+
PC := (RD(regl) + ($sft.sftEx) as SIntD) & -8 as BitsD
145+
RD(regd) := return
146+
}
147+
encoding AsId ($i.id, $size, $sft.sftId, $c.condStr) = {
148+
opsize = OpSize::$size, cond = Condition::$c.condId, ccsz = OpSize::$c.condSize,
149+
op = 0b111'1111, funct = $i.opcode, $c.encs, $sft.encs
150+
}
151+
assembly AsId ($i.id, $size, $sft.sftId, $c.condStr) = (AsStr($i.name, $sizeStr, $c.condStr), ' ', register(cregl), ',', register(cregr), ',',
152+
register(regd), ',', register(regl), ',', register(regr), $sft.asms)
153+
}
154+
128155
model OpShiftReg (m: InstrModel, size: Id, sizeStr: Str, c : CondRec, i : InstrRec) : IsaDefs = {
129156
$m ($size ; $sizeStr ; $c ; $i ; (Zero ; (AsId(R, $size)(regr)) ; regs= 0, shift = 0, opShift = OpShift::Add ; "" ))
130157
$m ($size ; $sizeStr ; $c ; $i ; (Add ; (AsId(R, $size)(regr) + AsId(R, $size)(regs)) ; shift = 0, opShift = OpShift::Add ; ("+", register(regs) )))
@@ -156,6 +183,24 @@ instruction set architecture HUGE = {
156183
$m ($size ; $sizeStr ; $c ; $i ; (Sft48 ; (imm3 as AsId(Bits, $size)) ; immShift = 3 ; (udec(imm), "<<48")))
157184
}
158185

186+
model BranchInstr (size: Id, sizeStr: Str, c : CondRec, i : InstrRec, sft : ShiftRec) : IsaDefs = {
187+
instruction AsId ($i.id, $c.condStr) : BranchFormat =
188+
if ($c.condEx) then {
189+
RD(regd) := PC.next
190+
PC := PC + offset
191+
}
192+
encoding AsId ($i.id, $c.condStr) = {
193+
opsize = OpSize::$size, cond = Condition::$c.condId, ccsz = OpSize::$c.condSize,
194+
op = $i.opcode, $c.encs
195+
}
196+
assembly AsId ($i.id, $c.condStr) = (AsStr($i.name, $sizeStr, $c.condStr), ' ', register(cregl), ',', register(cregr), ',',
197+
register(regd), ',', sdec(offset))
198+
}
199+
200+
model NoOperand (m: InstrModel, size: Id, sizeStr: Str, c : CondRec, i : InstrRec) : IsaDefs = {
201+
$m ($size ; $sizeStr ; $c ; $i ; (none ; none ; none ; ""))
202+
}
203+
159204
model ArithCondInstr (m: InstrModel, o: OperandModel, size: Id, sizeStr: Str, i : InstrRec) : IsaDefs = {
160205
$o ($m ;$size ; $sizeStr ; (EQ ; B ; "" ; true ; cregl = 0, cregr = 0) ; $i)
161206
$o ($m ;$size ; $sizeStr ; (EQ ; B ; "beq" ; RB(cregl) = RB(cregr); none ) ; $i)
@@ -184,15 +229,15 @@ instruction set architecture HUGE = {
184229
$o ($m ;$size ; $sizeStr ; (ULE ; D ; "dule" ; RD(cregl) <= RD(cregr); none ) ; $i)
185230
}
186231

187-
model ArithSizeInstr (m: InstrModel, o: OperandModel, i : InstrRec) : IsaDefs = {
232+
model SizeCondInstr (m: InstrModel, o: OperandModel, i : InstrRec) : IsaDefs = {
188233
$ArithCondInstr ($m ; $o; B ; "b" ; $i )
189234
$ArithCondInstr ($m ; $o; H ; "h" ; $i )
190235
$ArithCondInstr ($m ; $o; W ; "w" ; $i )
191236
$ArithCondInstr ($m ; $o; D ; "d" ; $i )
192237
}
193238

194-
model SizeCondInstr (m: InstrModel, o: OperandModel, i : InstrRec) : IsaDefs = {
195-
$ArithSizeInstr ($m ; $o ; $i )
239+
model DoubleCondInstr (m: InstrModel, o: OperandModel, i : InstrRec) : IsaDefs = {
240+
$ArithCondInstr ($m ; $o; D ; "d" ; $i )
196241
}
197242

198243
// arithmetic register instructions ********************************************
@@ -251,4 +296,6 @@ instruction set architecture HUGE = {
251296
$SizeCondInstr (ArithmeticImmInstr ; OpShiftImm ; (USGT ; "usgt" ; ugth ; 0b1'0110))
252297
$SizeCondInstr (ArithmeticImmInstr ; OpShiftImm ; (USGE ; "usge" ; ugeq ; 0b1'0111))
253298

299+
$DoubleCondInstr (BranchInstr ; NoOperand ; (BR ; "br" ; none ; 0b111'1110))
300+
$SizeCondInstr (JumpInstr ; OpShiftReg ; (JMP ; "jmp" ; none ; 0b11'1111'1111'1111))
254301
}

0 commit comments

Comments
 (0)