Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ if(LUAU_EXTERN_C)
target_compile_definitions(Luau.CodeGen PUBLIC LUACODEGEN_API=extern\"C\")
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND MSVC_VERSION GREATER_EQUAL 1924)
# disable partial redundancy elimination which regresses interpreter codegen substantially in VS2022:
# https://developercommunity.visualstudio.com/t/performance-regression-on-a-complex-interpreter-lo/1631863
set_source_files_properties(VM/src/lvmexecute.cpp PROPERTIES COMPILE_FLAGS /d2ssa-pre-)
endif()

if (NOT MSVC)
# disable support for math_errno which allows compilers to lower sqrt() into a single CPU instruction
target_compile_options(Luau.VM PRIVATE -fno-math-errno)
Expand Down
9 changes: 8 additions & 1 deletion Common/include/Luau/Common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once
#ifdef __clang__
#if __has_warning("-Wassume")
#pragma clang diagnostic ignored "-Wassume"
#endif
#endif

// Compiler codegen control macros
#ifdef _MSC_VER
Expand All @@ -10,6 +15,7 @@
#define LUAU_UNLIKELY(x) x
#define LUAU_UNREACHABLE() __assume(false)
#define LUAU_DEBUGBREAK() __debugbreak()
#define LUAU_ASSUME(x) __assume(x)
#else
#define LUAU_NORETURN __attribute__((__noreturn__))
#define LUAU_NOINLINE __attribute__((noinline))
Expand All @@ -18,6 +24,7 @@
#define LUAU_UNLIKELY(x) __builtin_expect(x, 0)
#define LUAU_UNREACHABLE() __builtin_unreachable()
#define LUAU_DEBUGBREAK() __builtin_trap()
#define LUAU_ASSUME(x) (void)sizeof(!!(x))
#endif

// LUAU_FALLTHROUGH is a C++11-compatible alternative to [[fallthrough]] for use in the VM library
Expand Down Expand Up @@ -65,7 +72,7 @@ LUAU_NOINLINE inline int assertCallHandler(const char* expression, const char* f
#define LUAU_ASSERT(expr) ((void)(!!(expr) || (Luau::assertCallHandler(#expr, __FILE__, __LINE__, __FUNCTION__) && (LUAU_DEBUGBREAK(), 0))))
#define LUAU_ASSERTENABLED
#else
#define LUAU_ASSERT(expr) (void)sizeof(!!(expr))
#define LUAU_ASSERT(expr) LUAU_ASSUME(expr)
#endif

namespace Luau
Expand Down
40 changes: 26 additions & 14 deletions VM/src/lvmexecute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ LUAU_DYNAMIC_FASTFLAG(LuauPopIncompleteCi)
if (L->status != 0) \
{ \
L->ci->savedpc--; \
goto exit; \
return; \
} \
} \
}
Expand Down Expand Up @@ -123,10 +123,12 @@ LUAU_DYNAMIC_FASTFLAG(LuauPopIncompleteCi)
#if VM_USE_CGOTO
#define VM_CASE(op) CASE_##op:
#define VM_NEXT() goto*(SingleStep ? &&dispatch : kDispatchTable[LUAU_INSN_OP(*pc)])
#define VM_START() VM_NEXT()
#define VM_CONTINUE(op) goto* kDispatchTable[uint8_t(op)]
#else
#define VM_CASE(op) case op:
#define VM_NEXT() goto dispatch
#define VM_NEXT() continue;
#define VM_START()
#define VM_CONTINUE(op) \
dispatchOp = uint8_t(op); \
goto dispatchContinue
Expand Down Expand Up @@ -231,10 +233,12 @@ static void luau_execute(lua_State* L)
base = L->base;
k = cl->l.p->k;

VM_NEXT(); // starts the interpreter "loop"
VM_START(); // starts the interpreter "loop"

{
while (true) {
#if VM_USE_CGOTO
dispatch:
#endif
// Note: this code doesn't always execute! on some platforms we use computed goto which bypasses all of this unless we run in single-step mode
// Therefore only ever put assertions here.
LUAU_ASSERT(base == L->base && L->base == L->ci->base);
Expand All @@ -249,7 +253,7 @@ static void luau_execute(lua_State* L)

// allow debugstep hook to put thread into error/yield state
if (L->status != 0)
goto exit;
return;
}

#if VM_USE_CGOTO
Expand Down Expand Up @@ -976,7 +980,7 @@ static void luau_execute(lua_State* L)

// yield
if (n < 0)
goto exit;
return;

// ci is our callinfo, cip is our parent
CallInfo* ci = L->ci;
Expand Down Expand Up @@ -1039,7 +1043,7 @@ static void luau_execute(lua_State* L)
// we're done!
if (LUAU_UNLIKELY(ci->flags & LUA_CALLINFO_RETURN))
{
goto exit;
return;
}

LUAU_ASSERT(isLua(L->ci));
Expand All @@ -1053,7 +1057,7 @@ static void luau_execute(lua_State* L)
if (L->global->ecb.enter(L, nextproto) == 1)
goto reentry;
else
goto exit;
return;
}
#endif

Expand Down Expand Up @@ -2371,12 +2375,17 @@ static void luau_execute(lua_State* L)

pc += LUAU_INSN_D(insn);
LUAU_ASSERT(unsigned(pc - cl->l.p->code) < unsigned(cl->l.p->sizecode));
VM_NEXT();
break;
}

index++;
}

if (unsigned(index) < unsigned(sizearray))
{
VM_NEXT();
}

int sizenode = 1 << h->lsizenode;

// then we advance index through the hash portion
Expand All @@ -2392,12 +2401,17 @@ static void luau_execute(lua_State* L)

pc += LUAU_INSN_D(insn);
LUAU_ASSERT(unsigned(pc - cl->l.p->code) < unsigned(cl->l.p->sizecode));
VM_NEXT();
break;
}

index++;
}

if (unsigned(index - sizearray) < unsigned(sizenode))
{
VM_NEXT();
}

// fallthrough to exit
pc++;
VM_NEXT();
Expand Down Expand Up @@ -2487,7 +2501,7 @@ static void luau_execute(lua_State* L)
if (L->global->ecb.enter(L, p) == 1)
goto reentry;
else
goto exit;
return;
#else
LUAU_ASSERT(!"Opcode is only valid when VM_HAS_NATIVE is defined");
LUAU_UNREACHABLE();
Expand Down Expand Up @@ -2975,7 +2989,7 @@ static void luau_execute(lua_State* L)

// allow debugbreak hook to put thread into error/yield state
if (L->status != 0)
goto exit;
return;
}

VM_CONTINUE(op);
Expand Down Expand Up @@ -3047,8 +3061,6 @@ static void luau_execute(lua_State* L)
#endif
}
}

exit:;
}

void luau_execute(lua_State* L)
Expand Down