Skip to content

Commit 10c81b1

Browse files
author
Fabrice Bellard
committed
fixed large performance regression with recent GCC versions
1 parent e2c01df commit 10c81b1

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎quickjs.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static inline JSValue __JS_NewShortBigInt(JSContext *ctx, int32_t d)
216216
#else /* !JS_NAN_BOXING */
217217

218218
typedef union JSValueUnion {
219-
int32_t int32;
219+
uint64_t uint64;
220220
double float64;
221221
void *ptr;
222222
#if JS_SHORT_BIG_INT_BITS == 32
@@ -236,13 +236,15 @@ typedef struct JSValue {
236236
#define JS_VALUE_GET_TAG(v) ((int32_t)(v).tag)
237237
/* same as JS_VALUE_GET_TAG, but return JS_TAG_FLOAT64 with NaN boxing */
238238
#define JS_VALUE_GET_NORM_TAG(v) JS_VALUE_GET_TAG(v)
239-
#define JS_VALUE_GET_INT(v) ((v).u.int32)
240-
#define JS_VALUE_GET_BOOL(v) ((v).u.int32)
239+
#define JS_VALUE_GET_INT(v) ((int)(v).u.uint64)
240+
#define JS_VALUE_GET_BOOL(v) ((int)(v).u.uint64)
241241
#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
242242
#define JS_VALUE_GET_SHORT_BIG_INT(v) ((v).u.short_big_int)
243243
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)
244244

245-
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
245+
/* avoid uninitialized data by using a 64 bit field even if only 32
246+
bits are needed because some compilers generate slower code */
247+
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .uint64 = (uint32_t)(val) }, tag }
246248
#define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag }
247249

248250
#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)

0 commit comments

Comments
 (0)