Skip to content

Commit 13ee2ce

Browse files
Extract arm64 asm check
PiperOrigin-RevId: 823185820
1 parent 06d6548 commit 13ee2ce

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

upb/port/def.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ Error, UINTPTR_MAX is undefined
392392
#define UPB_PRESERVE_NONE
393393
#endif
394394

395+
#if defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__))
396+
#define UPB_ARM64_ASM 1
397+
#else
398+
#define UPB_ARM64_ASM 0
399+
#endif
400+
395401
/* This check is not fully robust: it does not require that we have "musttail"
396402
* support available. We need tail calls to avoid consuming arbitrary amounts
397403
* of stack space.

upb/port/undef.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@
8282
#undef UPB_XSAN
8383
#undef UPB_XSAN_STRUCT_SIZE
8484
#undef UPB_ENABLE_REF_CYCLE_CHECKS
85+
#undef UPB_ARM64_ASM

upb/wire/encode.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,9 @@ static char* encode_fixed32(char* ptr, upb_encstate* e, uint32_t val) {
141141

142142
#define UPB_PB_VARINT_MAX_LEN 10
143143

144-
// Need gnu extended inline asm; msan can't instrument stores in inline assembly
145-
#if defined(__aarch64__) && (defined(__GNUC__) || defined(__clang__)) && \
146-
!UPB_HAS_FEATURE(memory_sanitizer)
147-
#define UPB_ARM64_ASM
148-
#endif
149-
150-
#ifdef UPB_ARM64_ASM
151-
UPB_NOINLINE static char* encode_longvarint_arm64(char* ptr, upb_encstate* e,
152-
uint64_t val) {
144+
#if UPB_ARM64_ASM
145+
UPB_NOINLINE static char* encode_longvarint(char* ptr, upb_encstate* e,
146+
uint64_t val) {
153147
ptr = encode_reserve(ptr, e, UPB_PB_VARINT_MAX_LEN);
154148
uint64_t clz;
155149
__asm__("clz %[cnt], %[val]\n" : [cnt] "=r"(clz) : [val] "r"(val));
@@ -223,11 +217,7 @@ char* encode_varint(char* ptr, upb_encstate* e, uint64_t val) {
223217
*ptr = val;
224218
return ptr;
225219
} else {
226-
#ifdef UPB_ARM64_ASM
227-
return encode_longvarint_arm64(ptr, e, val);
228-
#else
229220
return encode_longvarint(ptr, e, val);
230-
#endif
231221
}
232222
}
233223

0 commit comments

Comments
 (0)