Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/CodeGen/src/EmitCommonA64.h
2725 views
1
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2
#pragma once
3
4
#include "Luau/AssemblyBuilderA64.h"
5
6
#include "EmitCommon.h"
7
8
#include "lobject.h"
9
#include "ltm.h"
10
#include "lstate.h"
11
12
// AArch64 ABI reminder:
13
// Arguments: x0-x7, v0-v7
14
// Return: x0, v0 (or x8 that points to the address of the resulting structure)
15
// Volatile: x9-x15, v16-v31 ("caller-saved", any call may change them)
16
// Intra-procedure-call temporary: x16-x17 (any call or relocated jump may change them, as linker may point branches to veneers to perform long jumps)
17
// Non-volatile: x19-x28, v8-v15 ("callee-saved", preserved after calls, only bottom half of SIMD registers is preserved!)
18
// Reserved: x18: reserved for platform use; x29: frame pointer (unless omitted); x30: link register; x31: stack pointer
19
20
namespace Luau
21
{
22
namespace CodeGen
23
{
24
25
namespace A64
26
{
27
28
// Data that is very common to access is placed in non-volatile registers:
29
// 1. Constant registers (only loaded during codegen entry)
30
inline constexpr RegisterA64 rState = x19; // lua_State* L
31
inline constexpr RegisterA64 rNativeContext = x20; // NativeContext* context
32
inline constexpr RegisterA64 rGlobalState = x21; // global_State* L->global
33
34
// 2. Frame registers (reloaded when call frame changes; rBase is also reloaded after all calls that may reallocate stack)
35
inline constexpr RegisterA64 rConstants = x22; // TValue* k
36
inline constexpr RegisterA64 rClosure = x23; // Closure* cl
37
inline constexpr RegisterA64 rCode = x24; // Instruction* code
38
inline constexpr RegisterA64 rBase = x25; // StkId base
39
40
// Native code is as stackless as the interpreter, so we can place some data on the stack once and have it accessible at any point
41
// See CodeGenA64.cpp for layout
42
inline constexpr unsigned kStashSlots = 9; // stashed non-volatile registers
43
inline constexpr unsigned kTempSlots = 1; // 8 bytes of temporary space, such luxury!
44
inline constexpr unsigned kSpillSlots = 22; // slots for spilling temporary registers
45
46
static_assert(kSpillSlots % 2 == 0, "spill slots have to be sized in 16 byte TValue chunks, for valid extra register spill-over");
47
inline constexpr unsigned kExtraSpillSlots = 32;
48
static_assert(kExtraSpillSlots * 8 <= LUA_EXECUTION_CALLBACK_STORAGE, "can't use more extra slots than Luau global state provides");
49
50
inline constexpr unsigned kStackSize = (kStashSlots + kTempSlots + kSpillSlots) * 8;
51
52
inline constexpr AddressA64 sSpillArea = mem(sp, (kStashSlots + kTempSlots) * 8);
53
inline constexpr AddressA64 sTemporary = mem(sp, kStashSlots * 8);
54
55
inline void emitUpdateBase(AssemblyBuilderA64& build)
56
{
57
build.ldr(rBase, mem(rState, offsetof(lua_State, base)));
58
}
59
60
} // namespace A64
61
} // namespace CodeGen
62
} // namespace Luau
63
64