Skip to content

CG.Copy_n: build the sub-byte extraction mask at the target's word size - #1307

Merged
hosking merged 1 commit into
masterfrom
cg-copyn-word-mask
Nov 22, 2026
Merged

hosking merged 1 commit into
masterfrom
cg-copyn-word-mask

Conversation

@hosking

@hosking hosking commented Nov 22, 2026

Copy link
Copy Markdown
Member

m3tests p277 ("mixtures of nested constructors") stops the C backend with

TIntLiteral:type=UINT64 i=-256 ok1=FALSE ok2=TRUE
*** <*ASSERT*> failed: ok1   (M3C.m3, line 6030)

CG.Copy_n copies open arrays of 1-, 2- or 4-bit elements, and its sub-byte path pushes a mask as a Word literal:

CONST GMaskToShift = TInt.Int {16_00, 16_FF, ..};

Target.Int is nine bytes, so .. sets the byte above the word as well. The value is therefore the signed −256, not the word 16_FF..FF00. M3C checks a Word literal against the word's range and rejects it. Back ends that don't check that range accept it.

This PR computes the mask as Target.Word.max - 16_FF, which is also correct for 32-bit words. The constant came from the packedVars work (9343e3f, 2018).

Testing (ARM64_DARWIN, C backend). Two concierge.py upgrade passes, the second self-hosted, then m3tests:

  • p277 passes.
  • No new failures: 15 errors against 16 on master.

The remaining failures were already failing on master. r001, r003, r004 and r005 are fixed by #1302, and p269 by #1306.

🤖 Generated with Claude Code

The mask for copying arrays of 1-, 2- or 4-bit elements was the constant
TInt.Int {16_00, 16_FF, ..}.  Target.Int is nine bytes, so ".." also set
the byte above the word: the value was the signed -256, not the Word
16_FF..FF00.  The C backend checks Word literals against the word's range
and stopped with "TIntLiteral:type=UINT64 i=-256" (m3tests p277).
Compute the mask as Target.Word.max - 16_FF, which is also right for
32-bit words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hosking
hosking merged commit 71a9f29 into master Nov 22, 2026
31 of 33 checks passed
hosking pushed a commit that referenced this pull request Nov 23, 2026
Brings in #1302 (report an unhandled ex_stack exception), the RTStack
and RTMachine consolidation (#1312-#1319), #1307 (Copy_n's sub-byte
mask), #1309, #1323/#1324, #1331, #1332, #1334 and #1335.

Conflicts, all in favour of master's versions:
- RTException, RTExStack, RTExStackC.c: #1302 is the upstreamed form of
  msir's unhandled-exception report; master installs the terminate
  handler by an explicit call from RTExStack's body rather than a C++
  static initializer.
- runtime/common/m3makefile: RTStackCommon.c moved to separate
  Has_walker files (#1316).
- m3tests: keep master's p309 alongside msir's p303 and p304.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant