Commit a502642
authored
cranelift: inline small constant-length
* cranelift: inline small constant-length `array.copy`
When a scalar-element `array.copy` has a compile-time-constant length of at
most 8, expand it inline as loads-then-stores instead of calling the
`memory_copy` libcall. The libcall's fixed per-call cost (a wasm/host
transition and an indirect call) dominates for tiny copies, and is
especially visible in unoptimized builds where the libcall body itself is
not optimized.
Every element is loaded before any is stored so overlapping ranges keep
memmove semantics. Dynamic or larger lengths, and tables, still use the
libcall, whose `memmove` amortizes the overhead. The bound of 8 trades a
little perf (the inline-vs-libcall crossover is ~16 elements) for bounded
code size, capturing the largest wins, which cluster at <= 8 elements.
Assisted-by: Claude Code:claude-opus-4-7
* cranelift: tidy inline `array.copy` helper after review
Reword `emit_inline_array_copy`'s doc to describe a bitwise copy by element
width (it also handles `v128` and copies `f32`/`f64` via integer types), and
replace the `elem_size`/`n` parameter shadowing with `stride`/`count`. No
codegen change.
Assisted-by: Claude Code:claude-opus-4-7
* cranelift: generalize inline copy to all constant-length bulk copies
Per review, move the inline expansion into `raw_bulk_memory_operation`, keyed
on a constant byte length, so it also covers `memory.copy` and `table.copy`,
not just `array.copy`. It now uses width-agnostic wide accesses (`i8x16` down
to `i8`), and `BulkOp::MemoryCopy` carries entity-appropriate flags. Threshold
128 bytes, from measurement (~1.7-2.7x faster up to 128 B, ties by 256).
Assisted-by: Claude Code:claude-opus-4-7
* cranelift: simplify inline bulk copy after review
- Use `MemFlagsData::trusted()` in `emit_inline_memcpy` and drop the
per-entity flags threaded through `BulkOp::MemoryCopy`; each load only
feeds its paired store, so unaligned moves are selected regardless.
- Detect a constant length by matching only `iconst` on the raw wasm
length (plumbed as `const_len`) instead of folding the width casts and
`* element_size` multiply, which was type-unfaithful.
- Gate on `bytes <= 128` with a zero-length early return.
Assisted-by: Claude Code:claude-opus-4-7array.copy for performance (#13460)1 parent 5aa80a1 commit a502642
4 files changed
Lines changed: 407 additions & 7 deletions
File tree
- crates/cranelift/src
- tests
- disas
- misc_testsuite/gc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3448 | 3448 | | |
3449 | 3449 | | |
3450 | 3450 | | |
| 3451 | + | |
| 3452 | + | |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
3451 | 3477 | | |
3452 | 3478 | | |
3453 | 3479 | | |
| |||
3467 | 3493 | | |
3468 | 3494 | | |
3469 | 3495 | | |
3470 | | - | |
| 3496 | + | |
3471 | 3497 | | |
3472 | 3498 | | |
3473 | 3499 | | |
| |||
3530 | 3556 | | |
3531 | 3557 | | |
3532 | 3558 | | |
3533 | | - | |
| 3559 | + | |
3534 | 3560 | | |
3535 | 3561 | | |
3536 | 3562 | | |
| |||
3553 | 3579 | | |
3554 | 3580 | | |
3555 | 3581 | | |
3556 | | - | |
| 3582 | + | |
3557 | 3583 | | |
3558 | 3584 | | |
3559 | 3585 | | |
| |||
3577 | 3603 | | |
3578 | 3604 | | |
3579 | 3605 | | |
3580 | | - | |
| 3606 | + | |
3581 | 3607 | | |
3582 | 3608 | | |
3583 | 3609 | | |
| |||
3976 | 4002 | | |
3977 | 4003 | | |
3978 | 4004 | | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
3979 | 4011 | | |
3980 | 4012 | | |
3981 | 4013 | | |
3982 | 4014 | | |
3983 | 4015 | | |
3984 | 4016 | | |
3985 | 4017 | | |
| 4018 | + | |
| 4019 | + | |
3986 | 4020 | | |
3987 | 4021 | | |
3988 | 4022 | | |
3989 | 4023 | | |
3990 | 4024 | | |
3991 | 4025 | | |
| 4026 | + | |
3992 | 4027 | | |
3993 | 4028 | | |
3994 | 4029 | | |
| |||
4005 | 4040 | | |
4006 | 4041 | | |
4007 | 4042 | | |
| 4043 | + | |
4008 | 4044 | | |
4009 | 4045 | | |
4010 | 4046 | | |
| |||
4211 | 4247 | | |
4212 | 4248 | | |
4213 | 4249 | | |
4214 | | - | |
| 4250 | + | |
| 4251 | + | |
| 4252 | + | |
4215 | 4253 | | |
4216 | 4254 | | |
4217 | 4255 | | |
| |||
4227 | 4265 | | |
4228 | 4266 | | |
4229 | 4267 | | |
| 4268 | + | |
4230 | 4269 | | |
4231 | 4270 | | |
4232 | 4271 | | |
| |||
4300 | 4339 | | |
4301 | 4340 | | |
4302 | 4341 | | |
4303 | | - | |
| 4342 | + | |
4304 | 4343 | | |
| 4344 | + | |
4305 | 4345 | | |
4306 | 4346 | | |
4307 | 4347 | | |
4308 | 4348 | | |
4309 | 4349 | | |
4310 | 4350 | | |
| 4351 | + | |
4311 | 4352 | | |
4312 | 4353 | | |
4313 | 4354 | | |
| |||
4384 | 4425 | | |
4385 | 4426 | | |
4386 | 4427 | | |
| 4428 | + | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
| 4458 | + | |
| 4459 | + | |
| 4460 | + | |
| 4461 | + | |
| 4462 | + | |
| 4463 | + | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
| 4469 | + | |
| 4470 | + | |
| 4471 | + | |
| 4472 | + | |
| 4473 | + | |
| 4474 | + | |
| 4475 | + | |
| 4476 | + | |
| 4477 | + | |
| 4478 | + | |
| 4479 | + | |
| 4480 | + | |
| 4481 | + | |
| 4482 | + | |
| 4483 | + | |
| 4484 | + | |
| 4485 | + | |
| 4486 | + | |
| 4487 | + | |
| 4488 | + | |
| 4489 | + | |
| 4490 | + | |
| 4491 | + | |
| 4492 | + | |
| 4493 | + | |
4387 | 4494 | | |
4388 | 4495 | | |
4389 | 4496 | | |
| |||
5436 | 5543 | | |
5437 | 5544 | | |
5438 | 5545 | | |
5439 | | - | |
| 5546 | + | |
| 5547 | + | |
| 5548 | + | |
5440 | 5549 | | |
5441 | 5550 | | |
5442 | 5551 | | |
5443 | 5552 | | |
| 5553 | + | |
5444 | 5554 | | |
5445 | 5555 | | |
5446 | 5556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments