Repository navigation
compiler-builtins: Add size-optimized memcpy/memmove/memset - #163944
kleinesfilmroellchen wants to merge 2 commits into
Conversation
… core+alloc This (probably?) requires rebuilding compiler_intrinsics via build_std.
Note that this code is trivially correct, as it simply turns maybe-ifs into never-ifs.
On thumbv8m.main-none-eabi with -Os, this reduces memcpy from 324 bytes to 30 bytes. The assembly is so short, I can include it in the commit message:
```arm-assembly
0000152a <__aeabi_memcpy>:
152a: 1883 adds r3, r0, r2
152c: 4298 cmp r0, r3
152e: bf28 it cs
1530: 4770 bxcs lr
1532: b580 push {r7, lr}
1534: 466f mov r7, sp
1536: ,-> f811 3b01 ldrb.w r3, [r1], rust-lang#1
153a: | 3a01 subs r2, rust-lang#1
153c: | f800 3b01 strb.w r3, [r0], rust-lang#1
1540: '-- d1f9 bne.n 1536 <__aeabi_memcpy+0xc>
1542: e8bd 4080 ldmia.w sp!, {r7, lr}
1546: 4770 bx lr
```
memset is reduced from 100 to 26 bytes at least in simple tests.
|
cc @tgross35 |
|
|
Error: Failed to set assignee to
Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
|
Error: Failed to set assignee to
Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
|
r? libs |
|
Considering how this can be done via a separate PR to |
So that will require a separate PR here to pass the flag through alloc, right? |
Correct; I believe that this should be fine even if the subtree isn't merged yet, since cargo features just do nothing if they're not defined for the other crate. |
Tracking issue: #125612
On thumbv8m.main-none-eabi with -Os, this reduces memcpy from 324 bytes to 30 bytes. The assembly is so short and cute UwU, I can include it here:
memset is reduced from 100 to 26 bytes at least in simple tests.
Introducing this change requires introducing the optimize_for_size feature to compiler-builtins, and passing it from alloc (and possibly other places I have missed). This is why I have made the PR here and not in the compiler-builtins repo.
I’ve done some testing on multiple ARM embedded targets, but overall this code should be trivially correct. The previous
if <size-dependent condition>are simply turned intoif falsewith the flag, always using the bytewise copy/write branch.r? @diondokter
(as per our discussion about this on wg-embedded zulip)