Alkaid Low-Level Intermediate Representation (ALIR)
ALIR is alkaid’s low-level static-dataflow representation. A CombLogic program is a single SSA-style combinational block: each operation writes one buffer slot, later operations may read earlier slots, and outputs are selected from the final buffer.
The serialized JSON form written by CombLogic.save() is:
meta: the stringALIRModel.spec_version: the ALIR spec version. The current version is2.model: theCombLogicpayload described below.
CombLogic Payload
The model payload is stored as an array in the same order as the CombLogic fields:
shape:[n_inputs, n_outputs].inp_shifts: input scale shifts.out_idxs: buffer indices used as outputs.-1means a zero output.out_shifts: output scale shifts.out_negs: output sign flags.ops: operation records.carry_size: CMVM cost/latency configuration.adder_size: CMVM cost/latency configuration.lookup_tables: optional lookup table records, present only when lookup operations are used.
Each operation record is stored in the same order as the Op fields:
id0: first operand or input index.id1: second operand, or-1when unused.opcode: operation code. See the operation code table below.data: signed 64-bit integer payload whose meaning depends on the operation.qint: output quantization interval as[min, max, step].latency: estimated availability time.cost: estimated operation cost.
Unused id0 or id1 fields must be -1. For non-input operations, operand indices must refer only to earlier operations. For opcode 6, the condition index stored in data_low must also refer to an earlier operation.
Operation Codes
-2: Explicit negation.buf[i] = -buf[id0]
-1: Copy from the external input buffer and quantize.buf[i] = input[id0]
0: Addition.buf[i] = buf[id0] + buf[id1] * 2^data
1: Subtraction.buf[i] = buf[id0] - buf[id1] * 2^data
2: ReLU with output quantization.buf[i] = quantize(relu(buf[id0]))
3: Output quantization.buf[i] = quantize(buf[id0])
4: Add a constant.data_lowis a signed integer payload,data_highis a signed shift, and the constant isdata_low * 2^-data_high.
5: Define a constant.buf[i] = data * qint.step
6: Mux by the most-significant bit of a condition value.data_lowis the condition buffer index.data_highis the shift applied toid1.buf[i] = MSB(buf[data_low]) ? buf[id0] : buf[id1] * 2^data_high, then quantized toqint.
7: Multiplication.buf[i] = buf[id0] * buf[id1]
8: Logic lookup table.data_lowis the lookup table index.In bytecode,
data_highstores the table pad offset derived from the producer quantization interval.
9: Unary bitwise operation.data = 0: bitwise NOT.data = 1: reduce-any.data = 2: reduce-all.
10: Binary bitwise operation.data[31:0]is the signed shift aligning operand 1 to operand 0.data[55:32]is reserved.data[63:56]is the sub-operation:0= AND,1= OR,2= XOR.
Quantizing operations use direct fixed-point bit drop semantics: wrap for overflow and truncate for rounding.
External Bytecode Representation
CombLogic.to_bytecode() produces the int32 array consumed by the C++ ALIR interpreter. This is an in-memory interpreter format for python -> C++ communication, not a stable on-disk format. The bytecode is further converted to another internal bytecode format in the C++ interpreter for faster dispatch, which is not described here.
The int32 array layout is:
Header:
[spec_version, firmware_version, n_inputs, n_outputs, n_ops, n_tables].inp_shifts:int32[n_inputs].out_idxs:int32[n_outputs].out_shifts:int32[n_outputs].out_negs:int32[n_outputs].ops:int32[n_ops, 8].table_sizes:int32[n_tables].table_data: concatenatedint32lookup table contents.
Each bytecode operation row is:
opcode:int32.id0:int32.id1:int32.data_low: low 32 bits ofdata.data_high: high 32 bits ofdata.signed: output signedness.integers: integer bits excluding the sign bit.fractionals: fractional bits.
Lookup table data is stored in increasing lookup-index order. The bytecode loader validates the ALIR spec version, bytecode length, causality, and the interpreter’s current 64-bit intermediate-width limit.
The JSON loader in the C++ interpreter accepts plain JSON and gzip-compressed JSON with the same ALIRModel wrapper used by CombLogic.save().