@@ -507,6 +507,20 @@ swap_endianness:
507507# instruction, decode_address -> op_id, arg1, arg2, arg3
508508# ret: decode_ret
509509decode:
510+ # the lowest 2 bits are always "11" for non-compressed instructions
511+ # check this first to increase the odds of an early exit for non-code addresses
512+ op and low_bits instruction 0b11
513+ jump decode_illegal_instruction notEqual low_bits 0b11
514+
515+ # opcode
516+ op and opcode instruction 0b1111111
517+
518+ # also bail out if we're in the big group of illegal instructions between OP-32 and 48b
519+ # TODO: we could use this to reduce the code size a bit
520+ jump decode__ok lessThan opcode 0b0111011 # OP-32
521+ jump decode_illegal_instruction lessThanEq opcode 0b1011111 # 48b
522+ decode__ok:
523+
510524 # decode common fields to save space
511525 # we assume arg1=rs1, arg2=rs2, arg3=rd, which is close enough to most of the formats to save space
512526 # rs1
@@ -532,12 +546,7 @@ decode:
532546 op shr funct7 instruction 25
533547 op and funct7 funct7 0b1111111
534548
535- # the lowest 2 bits are always "11" for non-compressed instructions
536- op and low_bits instruction 0b11
537- jump decode_illegal_instruction notEqual low_bits 0b11
538-
539549 # counter array based on (opcode >> 2), since the low 2 bits don't matter
540- op and opcode instruction 0b1111111
541550 op shr jump opcode 2
542551 op add @counter @counter jump
543552
0 commit comments