Load string indices with inline asm to save space.#879
Load string indices with inline asm to save space.#879Dirbaio wants to merge 3 commits intoknurling-rs:mainfrom
Conversation
|
Thanks for this PR - it looks neat. Once we've resolve the question about hex-encoding symbols, I would support merging this. |
|
(This isn't a breaking change, we just want cargo server-checks to stop complaining about a PR that was committed some time ago) |
|
great news: llvm/llvm-project#159420 fixes using quotes in I assume it'll land in Rust 1.91. What do we do?
|
|
MSRV moving is hard when we have customers on long term support toolchains. A build.rs version switch, or a feature flag, would be fine. I wonder if this is related to the quote escaping issue in LLVM 21. |
Implemented a version switch. I wouldn't do a feature flag, it's not very discoverable and it's nice you get the optimization without having to opt-in. We'll have to wait until the llvm fix lands in nightly/beta to merge this.
yep! basically:
|
|
This looks good to me and I'm inclined to merge, but I'd like to do some code size and compile time comparisons first. |
| // This wastes space, so we load the value with asm manually to avoid this. | ||
| let val_arm_optimized = quote!( | ||
| let res: u16; | ||
| unsafe { ::core::arch::asm!( |
There was a problem hiding this comment.
Unfortunately this assembly code doesn't work on Arm architectures prior to ARMv6T2 (i.e. ARMv4T, ARMv5TE and ARMv6). See Godbolt.
You might need to use https://docs.rs/arm-targets to work out which Arm core is being targeted.
There was a problem hiding this comment.
Or we could say "Yeah, but those targets have no users", merge it anyway and worry about fixing it if someone actually complains.
There was a problem hiding this comment.
Oh no. It doesn't work on thumbv6m-none-eabi either....
Requires #878 becausenot anymore yayasm!(... sym ..)breaks if the symbol name has quote characters.Defmt string indices are 16 bits, which can be loaded with a single
movw.However, the compiler doesn't know that, so it generates
movw+movtorldr rX, [pc, #offs]because it sees we're loading an address of a symbol, which could be any 32bit value.
This wastes space, so we load the value with asm manually to avoid this.