Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
Instruction Format

Detailed Description

Instructions are 32-bit words with the following formats:

Fields:

To determine if the C field is a register or a constant the reduct_mode_t flags are used to modify the opcode.

Note
The reason we avoid formats such as iABx, used within Lua, is that even if it increases the maximum constant capacity it means that operations such as REDUCT_OPCODE_EQUAL always need to act on registers, which introduces unnecessary MOV instructions to load constants into registers before they can be compared.

Macros

#define REDUCT_REGISTER_INVALID   ((reduct_reg_t) - 1)
 Invalid register value.
 
#define REDUCT_INST_READS_REG(_inst, _reg)
 Check if an instruction reads from a specific register.
 
#define REDUCT_INST_WRITES_REG(_inst, _reg)    (REDUCT_OPCODE_HAS_TARGET(REDUCT_INST_GET_OP(_inst)) && (_reg) == REDUCT_INST_GET_A(_inst))
 Check if an instruction writes to a specific register.
 
#define REDUCT_INST_WIDTH_OPCODE   8U
 Opcode width in bits.
 
#define REDUCT_INST_WIDTH_A   8U
 A operand width in bits.
 
#define REDUCT_INST_WIDTH_B   8U
 B operand width in bits.
 
#define REDUCT_INST_WIDTH_C   8U
 C operand width in bits.
 
#define REDUCT_INST_WIDTH_SAX   (REDUCT_INST_WIDTH_A + REDUCT_INST_WIDTH_B)
 SAx operand width in bits.
 
#define REDUCT_REGISTER_MAX   (1U << REDUCT_INST_WIDTH_A)
 The max number of registers per function frame.
 
#define REDUCT_CONSTANT_MAX   (1U << REDUCT_INST_WIDTH_C)
 The max number of constants per function.
 
#define REDUCT_INST_POS_OPCODE   0U
 Opcode position in bits.
 
#define REDUCT_INST_POS_A   (REDUCT_INST_POS_OPCODE + REDUCT_INST_WIDTH_OPCODE)
 A operand position in bits.
 
#define REDUCT_INST_POS_B   (REDUCT_INST_POS_A + REDUCT_INST_WIDTH_A)
 B operand position in bits.
 
#define REDUCT_INST_POS_C   (REDUCT_INST_POS_B + REDUCT_INST_WIDTH_B)
 C operand position in bits.
 
#define REDUCT_INST_POS_SAX   (REDUCT_INST_POS_A)
 SAx operand position in bits.
 
#define REDUCT_INST_MASK_OPCODE   ((1U << REDUCT_INST_WIDTH_OPCODE) - 1U)
 Opcode mask.
 
#define REDUCT_INST_MASK_A   ((1U << REDUCT_INST_WIDTH_A) - 1U)
 A operand mask.
 
#define REDUCT_INST_MASK_B   ((1U << REDUCT_INST_WIDTH_B) - 1U)
 B operand mask.
 
#define REDUCT_INST_MASK_C   ((1U << REDUCT_INST_WIDTH_C) - 1U)
 C operand mask.
 
#define REDUCT_INST_MASK_SAX   ((1U << REDUCT_INST_WIDTH_SAX) - 1U)
 SAx operand mask.
 
#define REDUCT_INST_MAKE_ABC(_op, _a, _b, _c)
 Create an instruction with opcode, A, B, and C operands.
 
#define REDUCT_INST_MAKE_SAXC(_op, _sax, _c)
 Create an instruction with opcode and SAx operand, and C operand.
 
#define REDUCT_INST_GET_OP(_inst)   (((_inst) >> REDUCT_INST_POS_OPCODE) & REDUCT_INST_MASK_OPCODE)
 Get the opcode from an instruction.
 
#define REDUCT_INST_GET_A(_inst)   (((_inst) >> REDUCT_INST_POS_A) & REDUCT_INST_MASK_A)
 Get the A operand from an instruction.
 
#define REDUCT_INST_GET_B(_inst)   (((_inst) >> REDUCT_INST_POS_B) & REDUCT_INST_MASK_B)
 Get the B operand from an instruction.
 
#define REDUCT_INST_GET_C(_inst)   (((_inst) >> REDUCT_INST_POS_C) & REDUCT_INST_MASK_C)
 Get the C operand from an instruction.
 
#define REDUCT_INST_GET_SAX(_inst)   ((int32_t)(int16_t)(((_inst) >> REDUCT_INST_POS_SAX) & REDUCT_INST_MASK_SAX))
 Get the SAX operand from an instruction.
 
#define REDUCT_INST_SET_OP(_inst, _op)
 Set the opcode in an instruction.
 
#define REDUCT_INST_SET_A(_inst, _a)    (((_inst) & ~(REDUCT_INST_MASK_A << REDUCT_INST_POS_A)) | (((_a) & REDUCT_INST_MASK_A) << REDUCT_INST_POS_A))
 Set the A operand in an instruction.
 
#define REDUCT_INST_SET_B(_inst, _b)    (((_inst) & ~(REDUCT_INST_MASK_B << REDUCT_INST_POS_B)) | (((_b) & REDUCT_INST_MASK_B) << REDUCT_INST_POS_B))
 Set the B operand in an instruction.
 
#define REDUCT_INST_SET_C(_inst, _c)    (((_inst) & ~(REDUCT_INST_MASK_C << REDUCT_INST_POS_C)) | (((_c) & REDUCT_INST_MASK_C) << REDUCT_INST_POS_C))
 Set the C operand in an instruction.
 
#define REDUCT_INST_SET_SAX(_inst, _sax)    (((_inst) & ~(REDUCT_INST_MASK_SAX << REDUCT_INST_POS_A)) | (((_sax) & REDUCT_INST_MASK_SAX) << REDUCT_INST_POS_A))
 Set the SAX operand in an instruction.
 

Typedefs

typedef uint16_t reduct_const_t
 Constant index type.
 
typedef uint16_t reduct_reg_t
 Register type.
 
typedef uint32_t reduct_inst_t
 Instruction type.
 

Macro Definition Documentation

◆ REDUCT_REGISTER_INVALID

#define REDUCT_REGISTER_INVALID   ((reduct_reg_t) - 1)

Invalid register value.

Definition at line 46 of file inst.h.

◆ REDUCT_INST_READS_REG

#define REDUCT_INST_READS_REG (   _inst,
  _reg 
)
Value:
((REDUCT_OPCODE_READS_A(REDUCT_INST_GET_OP(_inst)) && (_reg) == REDUCT_INST_GET_A(_inst)) || \
(REDUCT_OPCODE_READS_B(REDUCT_INST_GET_OP(_inst)) && (_reg) == REDUCT_INST_GET_B(_inst)) || \
(REDUCT_OPCODE_READS_C(REDUCT_INST_GET_OP(_inst)) && (_reg) == REDUCT_INST_GET_C(_inst)) || \
(_reg) < REDUCT_INST_GET_A(_inst) + REDUCT_INST_GET_B(_inst)))
#define REDUCT_INST_GET_C(_inst)
Get the C operand from an instruction.
Definition inst.h:155
#define REDUCT_INST_GET_A(_inst)
Get the A operand from an instruction.
Definition inst.h:141
#define REDUCT_INST_GET_OP(_inst)
Get the opcode from an instruction.
Definition inst.h:134
#define REDUCT_INST_GET_B(_inst)
Get the B operand from an instruction.
Definition inst.h:148
#define REDUCT_OPCODE_READS_RANGE(_op)
Check if an opcode reads a range of registers starting at A.
Definition opcode.h:312
#define REDUCT_OPCODE_READS_A(_op)
Check if an opcode reads from register A.
Definition opcode.h:291
#define REDUCT_OPCODE_READS_C(_op)
Check if an opcode reads from register/constant C.
Definition opcode.h:305
#define REDUCT_OPCODE_READS_B(_op)
Check if an opcode reads from register B.
Definition opcode.h:298

Check if an instruction reads from a specific register.

Parameters
_instThe instruction.
_regThe register index.

Definition at line 60 of file inst.h.

◆ REDUCT_INST_WRITES_REG

#define REDUCT_INST_WRITES_REG (   _inst,
  _reg 
)     (REDUCT_OPCODE_HAS_TARGET(REDUCT_INST_GET_OP(_inst)) && (_reg) == REDUCT_INST_GET_A(_inst))

Check if an instruction writes to a specific register.

Parameters
_instThe instruction.
_regThe register index.

Definition at line 73 of file inst.h.

◆ REDUCT_INST_WIDTH_OPCODE

#define REDUCT_INST_WIDTH_OPCODE   8U

Opcode width in bits.

Definition at line 76 of file inst.h.

◆ REDUCT_INST_WIDTH_A

#define REDUCT_INST_WIDTH_A   8U

A operand width in bits.

Definition at line 77 of file inst.h.

◆ REDUCT_INST_WIDTH_B

#define REDUCT_INST_WIDTH_B   8U

B operand width in bits.

Definition at line 78 of file inst.h.

◆ REDUCT_INST_WIDTH_C

#define REDUCT_INST_WIDTH_C   8U

C operand width in bits.

Definition at line 79 of file inst.h.

◆ REDUCT_INST_WIDTH_SAX

#define REDUCT_INST_WIDTH_SAX   (REDUCT_INST_WIDTH_A + REDUCT_INST_WIDTH_B)

SAx operand width in bits.

Definition at line 80 of file inst.h.

◆ REDUCT_REGISTER_MAX

#define REDUCT_REGISTER_MAX   (1U << REDUCT_INST_WIDTH_A)

The max number of registers per function frame.

Definition at line 85 of file inst.h.

◆ REDUCT_CONSTANT_MAX

#define REDUCT_CONSTANT_MAX   (1U << REDUCT_INST_WIDTH_C)

The max number of constants per function.

Definition at line 89 of file inst.h.

◆ REDUCT_INST_POS_OPCODE

#define REDUCT_INST_POS_OPCODE   0U

Opcode position in bits.

Definition at line 91 of file inst.h.

◆ REDUCT_INST_POS_A

#define REDUCT_INST_POS_A   (REDUCT_INST_POS_OPCODE + REDUCT_INST_WIDTH_OPCODE)

A operand position in bits.

Definition at line 92 of file inst.h.

◆ REDUCT_INST_POS_B

#define REDUCT_INST_POS_B   (REDUCT_INST_POS_A + REDUCT_INST_WIDTH_A)

B operand position in bits.

Definition at line 93 of file inst.h.

◆ REDUCT_INST_POS_C

#define REDUCT_INST_POS_C   (REDUCT_INST_POS_B + REDUCT_INST_WIDTH_B)

C operand position in bits.

Definition at line 94 of file inst.h.

◆ REDUCT_INST_POS_SAX

#define REDUCT_INST_POS_SAX   (REDUCT_INST_POS_A)

SAx operand position in bits.

Definition at line 95 of file inst.h.

◆ REDUCT_INST_MASK_OPCODE

#define REDUCT_INST_MASK_OPCODE   ((1U << REDUCT_INST_WIDTH_OPCODE) - 1U)

Opcode mask.

Definition at line 97 of file inst.h.

◆ REDUCT_INST_MASK_A

#define REDUCT_INST_MASK_A   ((1U << REDUCT_INST_WIDTH_A) - 1U)

A operand mask.

Definition at line 98 of file inst.h.

◆ REDUCT_INST_MASK_B

#define REDUCT_INST_MASK_B   ((1U << REDUCT_INST_WIDTH_B) - 1U)

B operand mask.

Definition at line 99 of file inst.h.

◆ REDUCT_INST_MASK_C

#define REDUCT_INST_MASK_C   ((1U << REDUCT_INST_WIDTH_C) - 1U)

C operand mask.

Definition at line 100 of file inst.h.

◆ REDUCT_INST_MASK_SAX

#define REDUCT_INST_MASK_SAX   ((1U << REDUCT_INST_WIDTH_SAX) - 1U)

SAx operand mask.

Definition at line 101 of file inst.h.

◆ REDUCT_INST_MAKE_ABC

#define REDUCT_INST_MAKE_ABC (   _op,
  _a,
  _b,
  _c 
)
Value:
#define REDUCT_INST_POS_C
C operand position in bits.
Definition inst.h:94
#define REDUCT_INST_POS_A
A operand position in bits.
Definition inst.h:92
#define REDUCT_INST_MASK_A
A operand mask.
Definition inst.h:98
uint32_t reduct_inst_t
Instruction type.
Definition inst.h:52
#define REDUCT_INST_MASK_B
B operand mask.
Definition inst.h:99
#define REDUCT_INST_POS_B
B operand position in bits.
Definition inst.h:93
#define REDUCT_INST_MASK_OPCODE
Opcode mask.
Definition inst.h:97
#define REDUCT_INST_POS_OPCODE
Opcode position in bits.
Definition inst.h:91
#define REDUCT_INST_MASK_C
C operand mask.
Definition inst.h:100

Create an instruction with opcode, A, B, and C operands.

Parameters
_opOpcode operand.
_aA operand.
_bB operand.
_cC operand.

Definition at line 111 of file inst.h.

◆ REDUCT_INST_MAKE_SAXC

#define REDUCT_INST_MAKE_SAXC (   _op,
  _sax,
  _c 
)
Value:
#define REDUCT_INST_MASK_SAX
SAx operand mask.
Definition inst.h:101

Create an instruction with opcode and SAx operand, and C operand.

Parameters
_opOpcode operand.
_saxSAx operand.
_cC operand.

Definition at line 124 of file inst.h.

◆ REDUCT_INST_GET_OP

#define REDUCT_INST_GET_OP (   _inst)    (((_inst) >> REDUCT_INST_POS_OPCODE) & REDUCT_INST_MASK_OPCODE)

Get the opcode from an instruction.

Parameters
_instInstruction.

Definition at line 134 of file inst.h.

◆ REDUCT_INST_GET_A

#define REDUCT_INST_GET_A (   _inst)    (((_inst) >> REDUCT_INST_POS_A) & REDUCT_INST_MASK_A)

Get the A operand from an instruction.

Parameters
_instInstruction.

Definition at line 141 of file inst.h.

◆ REDUCT_INST_GET_B

#define REDUCT_INST_GET_B (   _inst)    (((_inst) >> REDUCT_INST_POS_B) & REDUCT_INST_MASK_B)

Get the B operand from an instruction.

Parameters
_instInstruction.

Definition at line 148 of file inst.h.

◆ REDUCT_INST_GET_C

#define REDUCT_INST_GET_C (   _inst)    (((_inst) >> REDUCT_INST_POS_C) & REDUCT_INST_MASK_C)

Get the C operand from an instruction.

Parameters
_instInstruction.

Definition at line 155 of file inst.h.

◆ REDUCT_INST_GET_SAX

#define REDUCT_INST_GET_SAX (   _inst)    ((int32_t)(int16_t)(((_inst) >> REDUCT_INST_POS_SAX) & REDUCT_INST_MASK_SAX))

Get the SAX operand from an instruction.

Parameters
_instInstruction.

Definition at line 162 of file inst.h.

◆ REDUCT_INST_SET_OP

#define REDUCT_INST_SET_OP (   _inst,
  _op 
)
Value:

Set the opcode in an instruction.

Parameters
_instInstruction.
_opOpcode value.

Definition at line 170 of file inst.h.

◆ REDUCT_INST_SET_A

#define REDUCT_INST_SET_A (   _inst,
  _a 
)     (((_inst) & ~(REDUCT_INST_MASK_A << REDUCT_INST_POS_A)) | (((_a) & REDUCT_INST_MASK_A) << REDUCT_INST_POS_A))

Set the A operand in an instruction.

Parameters
_instInstruction.
_aA operand value.

Definition at line 180 of file inst.h.

◆ REDUCT_INST_SET_B

#define REDUCT_INST_SET_B (   _inst,
  _b 
)     (((_inst) & ~(REDUCT_INST_MASK_B << REDUCT_INST_POS_B)) | (((_b) & REDUCT_INST_MASK_B) << REDUCT_INST_POS_B))

Set the B operand in an instruction.

Parameters
_instInstruction.
_bB operand value.

Definition at line 189 of file inst.h.

◆ REDUCT_INST_SET_C

#define REDUCT_INST_SET_C (   _inst,
  _c 
)     (((_inst) & ~(REDUCT_INST_MASK_C << REDUCT_INST_POS_C)) | (((_c) & REDUCT_INST_MASK_C) << REDUCT_INST_POS_C))

Set the C operand in an instruction.

Parameters
_instInstruction.
_cC operand value.

Definition at line 198 of file inst.h.

◆ REDUCT_INST_SET_SAX

#define REDUCT_INST_SET_SAX (   _inst,
  _sax 
)     (((_inst) & ~(REDUCT_INST_MASK_SAX << REDUCT_INST_POS_A)) | (((_sax) & REDUCT_INST_MASK_SAX) << REDUCT_INST_POS_A))

Set the SAX operand in an instruction.

Parameters
_instInstruction.
_saxSAX operand value.

Definition at line 207 of file inst.h.

Typedef Documentation

◆ reduct_const_t

Constant index type.

Definition at line 36 of file inst.h.

◆ reduct_reg_t

typedef uint16_t reduct_reg_t

Register type.

Definition at line 41 of file inst.h.

◆ reduct_inst_t

Instruction type.

Definition at line 52 of file inst.h.