From 10c81b1989de2d2e8d482d252b160a34f215d3e2 Mon Sep 17 00:00:00 2001 From: Fabrice Bellard Date: Wed, 3 Jun 2026 15:48:17 +0200 Subject: [PATCH] fixed large performance regression with recent GCC versions --- quickjs.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/quickjs.h b/quickjs.h index 57574e6..476d735 100644 --- a/quickjs.h +++ b/quickjs.h @@ -216,7 +216,7 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int32_t d) #else /* !JS_NAN_BOXING */ typedef union JSValueUnion { - int32_t int32; + uint64_t uint64; double float64; void *ptr; #if JS_SHORT_BIG_INT_BITS == 32 @@ -236,13 +236,15 @@ typedef struct JSValue { #define JS_VALUE_GET_TAG(v) ((int32_t)(v).tag) /* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */ #define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v) -#define JS_VALUE_GET_INT(v) ((v).u.int32) -#define JS_VALUE_GET_BOOL(v) ((v).u.int32) +#define JS_VALUE_GET_INT(v) ((int)(v).u.uint64) +#define JS_VALUE_GET_BOOL(v) ((int)(v).u.uint64) #define JS_VALUE_GET_FLOAT64(v) ((v).u.float64) #define JS_VALUE_GET_SHORT_BIG_INT(v) ((v).u.short_big_int) #define JS_VALUE_GET_PTR(v) ((v).u.ptr) -#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag } +/* avoid uninitialized data by using a 64 bit field even if only 32 + bits are needed because some compilers generate slower code */ +#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .uint64 = (uint32_t)(val) }, tag } #define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag } #define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)