rex3: CIDMATCH is a mask of permitted CIDs, not an equality value - #105
Merged
Merged
Conversation
CLIPMODE bits 12:9 are a four-bit permission mask: bit N permits a framebuffer write to a destination whose two-bit CID is N. Both the interpreter and the REX JIT compared AUX's low nibble (CID + popup bits) for equality against the field, which rejected legitimate writes — seen as drawing artifacts in StudioPaint (CLIPMODE 0x00000403, destination AUX 0x11). Disabling the REX JIT did not help because the interpreter had the same bug, and its screen-to-screen path skipped destination CID checking entirely. Tests cover all masks, CIDs and popup values for blocks, integer lines and copies on both paths; the JIT variant checks the dispatch counter so an interpreter fallback can't pass it. Test init now uses mask 15, and explicit compile requests use that CLIPMODE key. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019t4zZR7XH1DeuPZbVooWNS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
REX3
CLIPMODEbits 12:9 (CIDMATCH) are a four-bit permission mask: bit N permits a framebuffer write to a destination pixel whose two-bit CID is N (0000rejects every write,1111permits all). Seedocs/rex3.pdf, table 16 and section 3.3.Both the interpreter and the REX JIT treated the field as an equality value and compared it against AUX's low nibble, which also includes the popup bits. That rejected legitimate writes. It showed up as drawing artifacts in StudioPaint: the captured
CLIPMODEwas0x00000403(mask0010, i.e. CID 1), and the destination AUX byte was0x11(CID 1), yet the write was dropped.Disabling the REX JIT did not help, because the interpreter had the same bug. Its screen-to-screen copy path also skipped the destination CID check entirely.
Change
src/rex3.rs: acid_allows_writehelper implements the mask check. Pixel draws and screen-to-screen copies both use it; the copy path checks the destination.src/rex3_jit/compiler.rs: the emitted check for block draws and integer lines now tests(mask >> cid) & 1, using only AUX bits 1:0.Tests
cid_write_masks_interpreterandcid_write_masks_jitcover every mask × CID × popup value for block draws, integer lines and screen-to-screen copies. The JIT variant checksjit_go_count, so an interpreter fallback can't make it pass.rex3initnow uses mask1111rather than0000(under the correct semantics,0000rejects everything), and explicit JIT compile requests use that CLIPMODE key.Docs:
docs/rex3.mdCIDMATCH description corrected; new noterules/rex3/cidmatch-is-a-mask.md.