Operands and parameters
RegDst- Reg5 destination or discard
SrcL- Reg5 source
imml- selected field width N minus one
imms- selected field starting bit M
CTZ counts trailing zero bits in an independently selected wrapping scalar field and publishes the XLEN count.
PTO-SCALAR-CTZctz SrcL, M, N, ->{t, u, Rd}| Field | Bits | Signedness | Architectural role | Encoded zero |
|---|---|---|---|---|
RegDst | 5 | encoding-defined | Reg5 destination or discard | Encoded zero discards the result. |
SrcL | 5 | encoding-defined | Reg5 source | Encoded zero reads the architectural zero GPR. |
imml | 6 | encoding-defined | selected field width N minus one | Encoded zero selects a one-bit field. |
imms | 6 | encoding-defined | selected field starting bit M | Encoded zero starts the selected field at source bit zero. |
Loading WaveDrom diagram… The encoding table and WaveJSON remain available below.
| Decoded item | Bit range | Value |
|---|---|---|
| imms | 31:26 | variable |
| imml | 25:20 | variable |
| SrcL | 19:15 | variable |
| Constant | 14:12 | 3'b100 |
| RegDst | 11:7 | variable |
| Constant | 6:0 | 7'b1100111 |
{
"reg": [
{
"bits": 7,
"name": "7'b1100111"
},
{
"bits": 5,
"name": "RegDst"
},
{
"bits": 3,
"name": "3'b100"
},
{
"bits": 5,
"name": "SrcL"
},
{
"bits": 6,
"name": "imml"
},
{
"bits": 6,
"name": "imms"
}
],
"config": {
"bits": 32,
"fontsize": 13,
"hspace": 900,
"lanes": 1,
"offset": 0
}
}ctz SrcL, M, N, ->{t, u, Rd}
RegDstSrcLimmlimmsThis Operation comes directly from the instruction owner; the page does not rewrite its behavior.
readonly func InstructionContractOperation_CTZ() => ScalarOperationbegin return ScalarOperation_CTZ;end;
pure func InstructionContractWidth_CTZ(encoded_imml: bits(6)) => integer {1..64}begin return UInt(encoded_imml) + 1;end;
pure func InstructionContractOffset_CTZ(encoded_imms: bits(6)) => integer {0..63}begin return UInt(encoded_imms);end;readonly func InstructionContractHandler_CTZ() => ScalarSemanticHandlerbegin return ScalarHandler_CountBitfield;end;
pure func InstructionContractResult_CTZ( value: Word, width: integer {1..64}, offset: integer {0..63}) => Wordbegin return CountBitfield( value, width, offset, FALSE, FALSE);end;// PTO-INSTRUCTION: {"assembly":["ctz SrcL, M, N, ->{t, u, Rd}"],"block":[],"catalog_indices":[72],"catalog_records":[{"asm":"ctz SrcL, M, N, ->{t, u, Rd}","constraints":[],"encoding":[{"index":0,"mask":"0x0000707f","match":"0x00004067","width_bits":32}],"encoding_kind":"L32","fields":[{"name":"RegDst","pieces":[{"instruction_lsb":7,"value_lsb":0,"width":5}],"signedness":"encoding-defined","width":5},{"name":"SrcL","pieces":[{"instruction_lsb":15,"value_lsb":0,"width":5}],"signedness":"encoding-defined","width":5},{"name":"imml","pieces":[{"instruction_lsb":20,"value_lsb":0,"width":6}],"signedness":"encoding-defined","width":6},{"name":"imms","pieces":[{"instruction_lsb":26,"value_lsb":0,"width":6}],"signedness":"encoding-defined","width":6}],"form_id":"ctz_32_1761cbcc2a89","length_bits":32,"mnemonic":"CTZ","semantic_family":"ALU","semantic_group":"ALU","semantic_handler":"CountBitfield","semantic_summary":"CTZ counts trailing zero bits in an independently selected wrapping scalar field and publishes the XLEN count.","status":"accepted"}],"classification":["alu"],"contract":{"block_composition":["none"],"canonical_assembly":["ctz SrcL, M, N, ->{t, u, Rd}"],"defaults":["SrcL, imml, imms, and RegDst are required encoded fields; no field can be omitted.","imml encodes N minus one, so raw values 0 through 63 select widths 1 through 64; encoded zero selects N=1.","imms directly encodes M from 0 through 63; encoded zero selects source bit zero."],"encoding_class":"standalone-encoded","examples":["ctz a0, 0, 64, ->a1","ctz u#1, 60, 8, ->t","ctz zero, 0, 1, ->zero"],"exceptions":["An unavailable selected T/U source raises Fault_IllegalInstruction before the destination effect and before TPC advances.","CTZ raises no arithmetic, memory, alignment, permission, or control-flow exception."],"field_contracts":{},"field_zero_meanings":{"RegDst":"Encoded zero discards the result.","SrcL":"Encoded zero reads the architectural zero GPR.","imml":"Encoded zero selects a one-bit field.","imms":"Encoded zero starts the selected field at source bit zero."},"legality":["SrcL codes 0..23 select absolute GPRs, 24..27 select T#1..T#4, and 28..31 select U#1..U#4 without consumption.","RegDst codes 0 and 24..29 discard, codes 1..23 write GPRs, code 30 pushes U, and code 31 pushes T.","Every imml and imms value is assigned. The selected N-bit field begins at bit M and wraps through bit 63 to bit 0."],"memory_effects":["none"],"operands":[{"field":"RegDst","role":"Reg5 destination or discard"},{"field":"SrcL","role":"Reg5 source"},{"field":"imml","role":"selected field width N minus one"},{"field":"imms","role":"selected field starting bit M"}],"ordering":["Snapshot SrcL before any destination effect so a GPR alias or a T/U destination push observes the pre-instruction source value.","Publish the result, then advance TPC by four bytes."],"standalone_opcode":true,"state_effects":["Extract the N-bit field beginning at bit M, wrapping from bit 63 to bit 0, then count zero bits from selected field bit zero until the first one. An all-zero selected field returns N.","Publish the complete XLEN result through the common Reg5 destination map. Relative sources are non-consuming; only a T or U destination push changes a temporary queue.","No memory, reservation, descriptor, numeric-status, block, privilege, branch-target, or other control state changes. Successful execution advances TPC by four bytes."]},"depends_on":["PTO-BLOCK-MODEL-SCHEMA-PROFILE-ENCODING"],"id":"PTO-SCALAR-CTZ","mnemonic":"CTZ","summary":"CTZ counts trailing zero bits in an independently selected wrapping scalar field and publishes the XLEN count.","surface":"scalar"}// PTO-REVIEW: {"review_method":"formal-definition-read","outcome":"FORMAL-COMPLETE","reviewed_fields":["assembly","encoding","defaults","operation","state","memory","ordering","faults","reserved"]}// NDF-BEGIN: PTO-CTZ-DECISION-BINDING-001// ndf: kind=contract level=L1 layer=scalar status=accepted// CTZ MUST implement the mnemonic-local canonical assembly, encoded// legality, defaults, state and memory effects, ordering, and fault boundaries// declared in this owner. The operation region below is the executable binding// for every accepted decision that names this mnemonic.// NDF-END: PTO-CTZ-DECISION-BINDING-001// DOC-BEGIN: decodereadonly func InstructionContractOperation_CTZ() => ScalarOperationbegin return ScalarOperation_CTZ;end;
pure func InstructionContractWidth_CTZ(encoded_imml: bits(6)) => integer {1..64}begin return UInt(encoded_imml) + 1;end;
pure func InstructionContractOffset_CTZ(encoded_imms: bits(6)) => integer {0..63}begin return UInt(encoded_imms);end;// DOC-END: decode// DOC-BEGIN: operationreadonly func InstructionContractHandler_CTZ() => ScalarSemanticHandlerbegin return ScalarHandler_CountBitfield;end;
pure func InstructionContractResult_CTZ( value: Word, width: integer {1..64}, offset: integer {0..63}) => Wordbegin return CountBitfield( value, width, offset, FALSE, FALSE);end;// DOC-END: operation
CTZ is a 32-bit scalar ALU instruction. It counts trailing zeroes in the independently selected wrapping bit field; its current instruction contract defines the result publication path and any additional state effect.
Execution snapshots the encoded inputs, then counts trailing zeroes in the independently selected wrapping bit field, and only afterward performs the destination effects.
imml and imms independently select field width and starting bit; wrapping is part of the selected-field mechanism.RegDst field selects the Reg5 result target or discards the result.SrcL field selects a scalar input through Reg5.imml field encodes the selected field width as N-1.imms field encodes selected-field starting bit M.These roles come from the current instruction contract. T/U sources are read and snapshotted without being removed from their queues; exact encoded-zero meanings appear in the generated defaults below.
Every scalar source is snapshotted before the destination effect. The completed value is then routed through RegDst using the current scalar destination map.
This ALU operation has no memory effect. After its successful architectural effects, TPC advances by 4 bytes.
The operation does not introduce a hidden scalar publication target or an implicit memory access. Architectural changes remain limited to the state effects enumerated by the current contract.
Field selection may wrap from bit 63 to bit 0; the generated defaults and legality tables below give the exact width and starting-position encodings.
The generated legality table is authoritative for assigned field values, reserved encodings, and destination discard codes. Decode and source availability are checked before architectural effects.
This example illustrates the current ASL owner and does not replace the normative operation.
For a small CTZ example, the four-bit selected field 0010 has one trailing zero, so the result is 1.
Bodies come from owning ASL. Dragging or buttons change only this page-session view order.
CTZ MUST implement the mnemonic-local canonical assembly, encoded legality, defaults, state and memory effects, ordering, and fault boundaries declared in this owner. The operation region below is the executable binding for every accepted decision that names this mnemonic.
PTO-CTZ-DECISION-BINDING-001asl/scalar/alu/CTZ.asl4fa0e52cbd14896e4c0ead640441035fdef95f7f850f2f6b81def1529cb5a5e1f3d5803427395cf4901eca957a405cac99fa0917d1a09f0ccc7ac78d5dd0fcce13 matching entries
PTO-AVS-SCALAR-CTZ-DECODE-001tests/asl/scalar/alu/CTZ/scalar-decode-ctz-canonical-001.aslab46313f6cd9f83676ab421184aabfe4b4a6f0a89d68a1748106b18c507837f2PTO-AVS-SCALAR-CTZ-READINESS-001tests/asl/scalar/alu/CTZ/scalar-fault-ctz-readiness-001.asl483c564184ed2da61655e3dc66382b2d0c34bd49d8e1fbbf101a6f647cfe5be7PTO-AVS-SCALAR-CTZ-SELECTORS-001tests/asl/scalar/alu/CTZ/scalar-bound-ctz-selectors-001.aslecf1fc78a91e2745d5fe0ded4697b9da99a8add36c7dc7c34015b662027fd4c1PTO-AVS-SCALAR-CTZ-WRAP-001tests/asl/scalar/alu/CTZ/scalar-exec-ctz-wrap-001.aslc119dfc34c495dd5456f53265147bb529a7a2445d9f9337d2b6a6ca77900f560PTO-EVIDENCE-RELEASE-TRACEABILITYPTO-EVIDENCE-RELEASE-TRACEABILITYspec/evidence/release-traceability-readiness.jsonc7327021d39dc67ac5564bc55073b3870a397d79ac8d9648284d56e33bc14a3ePTO-EVIDENCE-INSTRUCTION-CONTRACT-CLOSUREPTO-EVIDENCE-INSTRUCTION-CONTRACT-CLOSUREspec/evidence/instruction-contract-closure.json3ef2bb62421c79dff8fa77a1c7983923b523244b8090812883ef81286ca8106aPTO-EVIDENCE-ARCHITECTURE-READINESSPTO-EVIDENCE-ARCHITECTURE-READINESSspec/evidence/architecture-readiness.json4b0b85199101251bea744e0f3591cc31906909dc80d5ab651c417a936036a004PTO-EVIDENCE-RELEASE-GATE-READINESSPTO-EVIDENCE-RELEASE-GATE-READINESSspec/evidence/release-gate-readiness.jsona0f4d2b6920c08981ea55fd8ef820708a40d4feb5402c5150e8e9ab532d84ce0PTO-EVIDENCE-RELEASE-MANIFESTPTO-EVIDENCE-RELEASE-MANIFESTspec/release-manifest.json1a64c109ed7a90351c41e2a418b3c0ebaf8ad975838986d2101385186b85c0d8Loading ADR-0025…
ADR-0025docs/status/decisions/0025-scalar-bitfield-and-reverse-bounds.md1c9dcf2e2f9c8ea16659db372545ac8dd76c4a88af9140fbd95c4473f2fef5dcLoading ADR-0026…
ADR-0026docs/status/decisions/0026-scalar-alu-totality-and-alias-order.md41d126f224dddc371832120f1b02eab64e426872fdcbea452bad77c90bdec349Loading ADR-0059…
ADR-0059docs/status/decisions/0059-mnemonic-field-encoding-closure.mdf18d13f735cfaf9f2803c754c5818f4af33d1cc42c489f0d9ce060b07bb3a196Loading ADR-0084…
ADR-0084docs/status/decisions/0084-scalar-system-and-queue-operations.mde068992fa81e2c4ac46e492391a2f784141d68e041bf0b9e0586c37217d1e08c{
"classification": [
"alu"
],
"documentation": "docs/scalar/alu/CTZ.md",
"id": "PTO-SCALAR-CTZ",
"instruction_contract": {
"artifact": "spec/evidence/instruction-contract-closure.json",
"mnemonic": "CTZ",
"ndf_clause": "PTO-INST-SCALAR-CTZ"
},
"mnemonic": "CTZ",
"readiness_subjects": [
"ADR-0025",
"ADR-0026",
"ADR-0059",
"ADR-0084"
],
"semantic_tests": [
"PTO-AVS-SCALAR-CTZ-READINESS-001",
"PTO-AVS-SCALAR-CTZ-SELECTORS-001",
"PTO-AVS-SCALAR-CTZ-WRAP-001"
],
"source": "asl/scalar/alu/CTZ.asl",
"surface": "scalar",
"tests": [
"PTO-AVS-SCALAR-CTZ-DECODE-001",
"PTO-AVS-SCALAR-CTZ-READINESS-001",
"PTO-AVS-SCALAR-CTZ-SELECTORS-001",
"PTO-AVS-SCALAR-CTZ-WRAP-001"
]
}0.58.5 · Release candidate7dc8b7e5b121d2b2499a2273bebff29e2cd868124fa0e52cbd14896e4c0ead640441035fdef95f7f850f2f6b81def1529cb5a5e1515b63472a38f23a59e5cb73d55162700c4b29f23e199f66496af53aadc54bc1asl/scalar/alu/CTZ.aslasl/scalar/alu/CTZ.aslasl/scalar/alu/CTZ.asl