tool-copt

Applies z88dk-copt peephole rules to optimize Z80 assembly and clean hand-written library code.

1.1k|206|Updated Mar 16, 2016
One-click install
npx skills add https://github.com/z88dk/z88dk --skill tool-copt-z88dk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tool-copt
Source: https://github.com/z88dk/z88dk/tree/main/.agents/skills/tool-copt
Command: npx skills add https://github.com/z88dk/z88dk --skill tool-copt-z88dk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Hand-written z88dk library assembly never passes through the copt peephole optimiser, so redundant instructions like copy-back loads and dead reloads persist unless authors manually apply the same optimizations the rules encode. ## Core Features & Use Cases - Rule file guidance: Explains the lib/z80rules.* family, which rule sets zcc applies at each -O level, and how wildcards, preconditions, and labels work in copt rule syntax. - Codegen hygiene checklist: Provides a table of common assembly smells (copy-back loads, dead second loads, push/pop transfers) and their optimized replacements for math16, math32, and sccz80 runtime code. - Use Case: After editing 8085 math32 library assembly, scan the touched files for copt-equivalent idioms, remove redundant ld a,r reloads, and validate with the CPU-specific test binary before committing. ## Quick Start Review my hand-written z88dk library assembly file for redundant instructions that copt rules would eliminate and suggest the optimized replacements.

Frequently Asked Questions about tool-copt

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a copt peephole rule for z88dk?

Write pattern lines followed by an equals sign and replacement lines, ending the rule with a blank line. Use %1 through %9 as wildcards that must bind consistently, and add preconditions like %check, %cpu, or %notcpu when a pattern is unsafe on certain CPUs.

Which z80rules files does zcc apply at each optimization level?

At -O0 only z80rules.9 applies; -O1 adds z80rules.1; -O2 adds z80rules.2; -O3 and above add z80rules.0. The z80rules.8 file loads only for the sccz80 inline ints path, and target or CPU-specific rules load when configured.

Does copt optimize hand-written z88dk library assembly?

No, copt only runs on compiler-generated output from sccz80 and similar frontends. Library sources under libsrc/ are assembled directly, so authors must manually apply the same cleanups the rules encode, such as removing copy-back loads and dead reloads.

Why does copt not change my assembly file?

copt rules match whole lines mostly literally, so space-indented or commented library code will not match rules written for tab-indented sccz80 output. This is expected behavior, not a broken tool; normalize a copy to tab style in a temp file to test rule firing.

Can I replace ld a,0 with xor a in Z80 assembly?

Not blindly: ld preserves flags while xor a clears the carry flag. The substitution is unsafe before sbc, rla, or rra instructions that depend on the prior carry, which is common in float sign handling and multiprecision negate paths.