reprospect.test.sass.instruction.instruction module
- class reprospect.test.sass.instruction.instruction.AnyMatcherView on GitHub
Bases:
PatternMatcherMatch any instruction.
Note
The instruction is decomposed into its components.
Warning
As explained in https://github.com/cloudcores/CuAssembler/blob/96a9f72baf00f40b9b299653fcef8d3e2b4a3d49/CuAsm/CuInsParser.py#L251-LL258, nearly all operands are comma-separated. Notable exceptions:
RET.REL.NODEC R10 0x0
>>> from reprospect.test.sass.instruction import AnyMatcher >>> AnyMatcher().match(inst = 'FADD.FTZ.RN R0, R1, R2') InstructionMatch(opcode='FADD', modifiers=('FTZ', 'RN'), operands=('R0', 'R1', 'R2'), predicate=None, additional=None) >>> AnyMatcher().match(inst = 'RET.REL.NODEC R4 0x0') InstructionMatch(opcode='RET', modifiers=('REL', 'NODEC'), operands=('R4', '0x0'), predicate=None, additional=None)
- PATTERN: Final[Pattern[str]] = regex.Regex('(?:(?P<predicate>@!?U?P(?:T|[0-9]+)))?\\s*(?P<opcode>[A-Z0-9]+)(?:\\.(?P<modifiers>[A-Z0-9_]+))*\\s*(?:(?P<operands>[\\w!\\.\\[\\]\\+\\-\\|~]+)(?:,?\\s*(?P<operands>[\\w!\\.\\[\\]\\+\\-\\|~]+))*)?', flags=regex.V0)
- __init__() NoneView on GitHub
- class reprospect.test.sass.instruction.instruction.ArchitectureAndVersionAwarePatternMatcher(arch: NVIDIAArch, version: Version | None = None)View on GitHub
Bases:
ArchitectureAwarePatternMatcherBase class for matchers that generate patterns based on CUDA version and architecture.
Note
The CUDA version is defaulted to the CUDA_VERSION environment variable. However, it must be noted that it is expected to be the version of
ptxas.The version is not always needed, but is useful for some SASS instructions that changed over the course of CUDA ISA evolution. For instance, under CUDA 12.6, an atomic add for int (at block scope) translates to:
ATOM.E.ADD.STRONG.CTA PT, RZ, [R2], R5
whereas for CUDA 12.8.1 or 13.0.0, it translates to:
ATOM.E.ADD.S32.STRONG.CTA PT, RZ, [R2], R5
- __init__(arch: NVIDIAArch, version: Version | None = None) NoneView on GitHub
- class reprospect.test.sass.instruction.instruction.ArchitectureAwarePatternMatcher(arch: NVIDIAArch)View on GitHub
Bases:
PatternMatcherBase class for matchers that generate patterns based on architecture.
- __init__(arch: NVIDIAArch) NoneView on GitHub
- class reprospect.test.sass.instruction.instruction.InstructionMatch(opcode: str, modifiers: tuple[str, ...], operands: tuple[str, ...], predicate: str | None = None, additional: dict[str, list[str]] | None = None)View on GitHub
Bases:
objectAn instruction with parsed components.
- __init__(opcode: str, modifiers: tuple[str, ...], operands: tuple[str, ...], predicate: str | None = None, additional: dict[str, list[str]] | None = None) None
- static parse(*, bits: Match[str]) InstructionMatchView on GitHub
The only mandatory capture group is opcode.
- class reprospect.test.sass.instruction.instruction.InstructionMatcherView on GitHub
Bases:
ABCAbstract base class for instruction matchers.
- abstractmethod match(inst: Instruction | str) InstructionMatch | NoneView on GitHub
Check if the instruction matches.
- reprospect.test.sass.instruction.instruction.OPERAND_SEPARATOR: Final[str] = ',?\\s*'
Separator between operands.
- class reprospect.test.sass.instruction.instruction.OpCodeView on GitHub
Bases:
objectOpcode patterns.
- classmethod mod(opcode: str, modifiers: Iterable[str | int | ZeroOrOne] | None = None, *, captured: bool = True) strView on GitHub
Append each modifier with a . separator.
Modifiers wrapped in a
reprospect.test.sass.instruction.instruction.ZeroOrOneinstance are matched optionally.
- classmethod modifier() strView on GitHub
MODIFIERwith modifiers group.
- classmethod opcode() strView on GitHub
OPCODEwith opcode group.
- class reprospect.test.sass.instruction.instruction.OpcodeModsMatcher(*, opcode: str, modifiers: Iterable[str | int | ZeroOrOne] | None = None, operands: bool = True)View on GitHub
Bases:
PatternMatcherMatcher that will collect all operands of an instruction.
Useful when the opcode and modifiers are known and the operands may need to be retrieved.
>>> from reprospect.test.sass.instruction import OpcodeModsMatcher >>> OpcodeModsMatcher(opcode = 'ISETP', modifiers = ('NE', 'AND')).match( ... 'ISETP.NE.AND P2, PT, R4, RZ, PT' ... ) InstructionMatch(opcode='ISETP', modifiers=('NE', 'AND'), operands=('P2', 'PT', 'R4', 'RZ', 'PT'), predicate=None, additional=None)
- class reprospect.test.sass.instruction.instruction.OpcodeModsWithOperandsMatcher(*, opcode: str, modifiers: Iterable[str | int | ZeroOrOne] | None = None, operands: Iterable[str | ZeroOrOne] | None = None)View on GitHub
Bases:
PatternMatcherMatcher that matches a given instruction and operands.
Similar to
OpcodeModsMatcher, but the operands can be better constrained.>>> from reprospect.test.sass.instruction import OpcodeModsWithOperandsMatcher, PatternBuilder >>> from reprospect.test.sass.instruction.register import Register >>> OpcodeModsWithOperandsMatcher( ... opcode = 'ISETP', ... modifiers = ('NE', 'AND'), ... operands = ( ... Register.PRED, ... Register.PREDT, ... 'R4', ... Register.REGZ, ... Register.PREDT, ... ) ... ).match('ISETP.NE.AND P2, PT, R4, RZ, PT') InstructionMatch(opcode='ISETP', modifiers=('NE', 'AND'), operands=('P2', 'PT', 'R4', 'RZ', 'PT'), predicate=None, additional=None)
Note
Some operands can be optionally matched.
>>> from reprospect.test.sass.instruction import OpcodeModsWithOperandsMatcher, PatternBuilder >>> from reprospect.test.sass.instruction.instruction import ZeroOrOne >>> matcher = OpcodeModsWithOperandsMatcher(opcode = 'WHATEVER', operands = ( ... ZeroOrOne('R0'), ... ZeroOrOne('R9'), ... )) >>> matcher.match('WHATEVER') InstructionMatch(opcode='WHATEVER', modifiers=(), operands=(), predicate=None, additional=None) >>> matcher.match('WHATEVER R0') InstructionMatch(opcode='WHATEVER', modifiers=(), operands=('R0',), predicate=None, additional=None) >>> matcher.match('WHATEVER R0, R9') InstructionMatch(opcode='WHATEVER', modifiers=(), operands=('R0', 'R9'), predicate=None, additional=None)
- class reprospect.test.sass.instruction.instruction.PatternMatcher(pattern: str | Pattern[str])View on GitHub
Bases:
InstructionMatcherRegex-based (or pattern) matching.
Note
It is not decorated with
dataclasses.dataclass()because of https://github.com/mypyc/mypyc/issues/1061.- __init__(pattern: str | Pattern[str]) NoneView on GitHub
- classmethod build_pattern(*, opcode: str | None = None, modifiers: Iterable[str | int | ZeroOrOne] | None = None, operands: Iterable[str | ZeroOrOne] | None = None, predicate: str | bool | None = None) strView on GitHub
- classmethod build_pattern_operands(operands: Iterable[str | ZeroOrOne] | None = None, *, captured: bool = True) str | NoneView on GitHub
Build an operands pattern.
Join multiple operands with a
reprospect.test.sass.instruction.instruction.OPERAND_SEPARATORseparator. Operands wrapped in areprospect.test.sass.instruction.instruction.ZeroOrOneinstance are matched optionally.
- final match(inst: Instruction | str) InstructionMatch | NoneView on GitHub
- class reprospect.test.sass.instruction.instruction.PredicateView on GitHub
Bases:
objectPredicate patterns.
- PREDICATE: Final[str] = '@!?U?P(?:T|[0-9]+)'
Predicate for the whole instruction (comes before the opcode).
- classmethod predicate() strView on GitHub
PREDICATEwith predicate group.