Skip to content

Instantly share code, notes, and snippets.

@ajeddeloh
Last active October 7, 2022 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajeddeloh/d6051efe54a1ddf367b5395b7a456008 to your computer and use it in GitHub Desktop.
Save ajeddeloh/d6051efe54a1ddf367b5395b7a456008 to your computer and use it in GitHub Desktop.
GCC Wont generate BFI
test.cc:
#include <stdint.h>
uint32_t emplace(uint32_t into, uint32_t what) {
constexpr uint32_t shift = 5;
constexpr uint32_t width = 4;
constexpr uint32_t mask = ((1 << width) - 1) << shift;
return (into & ~mask) | ((what << shift) & mask);
}
(abridged) test.s generated by arm-none-eabi-g++ -Wall -Wextra -mcpu=cortex-m4 test.cc -c -S -O3:
.LFB0:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
lsls r1, r1, #5
and r1, r1, #480
bic r0, r0, #480
orrs r0, r0, r1
bx lr
(abridged) test.s generated by clang -target arm-none-eabi -Wall -Wextra -mcpu=cortex-m4 test.cc -c -S -O3:
_Z7emplacejj:
.fnstart
bfi r0, r1, #5, #4
bx lr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment