# packed-switch

## Purpose

Jump to a new instruction based on the value in the given register, using a table of offsets corresponding to each value in a particular integral range, or fall through to the next instruction if there is no match.

Note: The address of the table is guaranteed to be even (that is, 4-byte aligned). If the code size of the method is otherwise odd, then an extra code unit is inserted between the main code and the table whose value is the same as a nop.

## Details

Op & Format | Mnemonic / Syntax | Arguments
--- | --- | ---
2b 31t | packed-switch vAA, +BBBBBBBB (with supplemental data as specified below in "`packed-switch` Format") | `A:` register to test `B:` signed "branch" offset to table data (32 bits)

## Constraints

- A must be a valid register index in the current stack frame.
- Let PC be the address of the packed-switch instruction in the code array of the current method. Then T = PC + B with the following properties:
  - T must be 4-byte-aligned.
  T must be in the same method.
- T must point to a packed-switch data table.

## Behavior

- The value of vA is used as an index into the given table data.
- If vA is in the range of the table, that is, if vA >= table.first_key and vA < first_key + size, then the jump target is determined as follows:
  - PC' = PC + table.targets[vA - table.firstKey].
  - Execution resumes at this address.
- Otherwise execution continues at the instruction following the packed-switch statement.

## Exceptions

None.