Repository navigation
Conversation
…ay<UInt8>) Adds SKIP_Sequence_copyStringBytesTo in runtime/string.c: a single memcpy of a string's UTF-8 bytes into an Array<UInt8> region at a given offset (no bounds check; returns bytes copied), plus the module-level native declaration in Sequence.sk. Meant for building byte buffers one block at a time instead of per-byte get/set loops, which do not vectorize (per-byte external call + bounds-check branch). Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
Each part (and each separator) is now copied into the output buffer with a single native memcpy instead of a per-byte Bytes::get/Array::set loop. See #1718 for the codegen analysis that motivated this. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
The prelude declares copyStringBytesTo as a @cpp_extern native (the C implementation in runtime/string.c stays as the fallback for compilers that don't know it, e.g. the pinned stage0). This teaches the compiler itself to perform the block copy: the intrinsic is rewritten to a load of the string's byte size from its header plus a single llvm.memcpy.p0.p0.i64 into the destination array at the given offset, returning the number of bytes copied. Motivated by codegen inspection (#1718): the per-byte copy loop does not vectorize (per-byte external call + bounds-check branch), while a single memcpy is one call. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
mbouaziz
enabled auto-merge
November 19, 2026 23:48
This branch has not been deployed
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.
Implements item 1 of #1718 on top of merged #1716, in the compiler itself plus a runtime fallback. 3 commits:
prelude: add native copyStringBytesTo block copy (String bytes -> Array<UInt8>)—SKIP_Sequence_copyStringBytesToinruntime/string.c(singlememcpyof a string's UTF-8 bytes into anArray<UInt8>region at an offset; returns bytes copied) + the@cpp_extern native fundeclaration in moduleSequence. This is the fallback for the pinned stage0, which doesn't know the intrinsic — the prelude CI job compiles with stage0, so the C symbol must exist.prelude: use copyStringBytesTo in Sequence::join fill loop— each part/separator is copied with one block-copy call instead of a per-byteBytes::get/Array::setloop.compiler: lower Sequence.copyStringBytesTo to an llvm.memcpy— the compiler-direct part:IntrinsicsInlinernow recognizes the call and rewrites it to a load of the string's byte size from its header (sk_string_t: u32 at -4 on 64-bit, -8 on wasm32) plus a singlellvm.memcpy.p0.p0.i64into the destination array at the offset, returning the size. No C code involved on stage1+.Why (verified codegen, see #1718)
The previous per-byte fill loop was not vectorized (zero SIMD instructions in the emitted IR; per-byte external
SKIP_String_getBytecall + bounds-check branch + scalar store block LLVM's loop vectorizer). With this change, compiling aVector<String>.join(", ")probe with the freshly built stage1 (--emit llvm-ir --release -O 2) shows 6llvm.memcpycalls and 0 references to the C fallback; the fill loop body is one memcpy per part/separator. With stage0 the same program links and runs against the C fallback.Validation
make STAGE=1,skc 0.4.7 (adfcadf8)).SKTEST_PROFILE=release PATH=stage1/bin:$PATH ../../bin/run-sktest.sh): 1769/1769 pass.testJoinMultibyte): 146/146 pass; with pinned stage0 (C fallback path): 146/146 pass.skfmtclean; CircleCI on the branch head.AI-assisted: implemented with Mistral Vibe (
Co-Authored-Bytrailers on the commits).