From ce9daa48572a345ffd95e41d9f64b9e4719a88fa Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 22 Sep 2022 02:25:32 -0700 Subject: 1 event loop per thread. Instead of 3. uWebSockets and uSockets will need to be upgraded to match the changes. Previously: - Bun had a separate kqueue/eventfd just for async wakeups. - Bun had a separate kqueue/epoll just for reading files non-blocking in the same thread This commit unifies it into one event loop per thread --- test/bun.js/ffi.test.fixture.callback.c | 35 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'test/bun.js/ffi.test.fixture.callback.c') diff --git a/test/bun.js/ffi.test.fixture.callback.c b/test/bun.js/ffi.test.fixture.callback.c index 7de63120f..cb38eebe8 100644 --- a/test/bun.js/ffi.test.fixture.callback.c +++ b/test/bun.js/ffi.test.fixture.callback.c @@ -147,23 +147,39 @@ static bool JSVALUE_IS_NUMBER(EncodedJSValue val) { } +// JSValue numbers-as-pointers are represented as a 52-bit integer +// Previously, the pointer was stored at the end of the 64-bit value +// Now, they're stored at the beginning of the 64-bit value +// This behavior change enables the JIT to handle it better +// It also is better readability when console.log(myPtr) static void* JSVALUE_TO_PTR(EncodedJSValue val) { - // must be a double if (val.asInt64 == TagValueNull) return 0; - return (void*)(val.asInt64 - DoubleEncodeOffset); + val.asInt64 -= DoubleEncodeOffset; + size_t ptr = (size_t)val.asDouble; + return (void*)ptr; } static EncodedJSValue PTR_TO_JSVALUE(void* ptr) { EncodedJSValue val; - if (ptr == 0) { - val.asInt64 = TagValueNull; - return val; + if (ptr == 0) + { + val.asInt64 = TagValueNull; + return val; } - val.asInt64 = (int64_t)ptr + DoubleEncodeOffset; + + val.asDouble = (double)(size_t)ptr; + val.asInt64 += DoubleEncodeOffset; return val; } +static EncodedJSValue DOUBLE_TO_JSVALUE(double val) { + EncodedJSValue res; + res.asDouble = val; + res.asInt64 += DoubleEncodeOffset; + return res; +} + static int32_t JSVALUE_TO_INT32(EncodedJSValue val) { return val.asInt64; } @@ -175,12 +191,7 @@ static EncodedJSValue INT32_TO_JSVALUE(int32_t val) { } -static EncodedJSValue DOUBLE_TO_JSVALUE(double val) { - EncodedJSValue res; - res.asDouble = val; - res.asInt64 += DoubleEncodeOffset; - return res; -} + static EncodedJSValue FLOAT_TO_JSVALUE(float val) { return DOUBLE_TO_JSVALUE((double)val); -- cgit v1.2.3