Added updating of lua generated header files for X86 architecture.
[jitcs.git] / include / jitcs_memref.h
blobfd740081f6621ef80b7f5f1d9a0e4cd790b6a89d
1 //===-- jitcs_memref.h - memory parameters in instructions -----*- C++ -*-===//
2 //
3 // A MemoryReference contains all data necessary to describe the memory
4 // parameter of a single hardware instruction. If a MemoryReference contains
5 // uses of a non-fixed virtual register, and is used in more than one
6 // instruction, copies will be created at register allocation time.
7 //
8 // TODO: The source looks rather ugly right now.
9 //
10 //===----------------------------------------------------------------------===//
12 #ifndef _JITCS_MEMREF_H_
13 #define _JITCS_MEMREF_H_
15 #include "jitcs_base.h"
16 #include "jitcs_ids.h"
18 namespace jitcs {
19 struct VirtualRegister;
21 template <int N> struct MemDataImpl {};
22 template <> struct MemDataImpl<4> {
23 union {
24 struct { VirtualRegister const *base, *index; } regs;
25 struct { u8* ptr; } global;
26 };
27 int offset;
28 int modeAndScale;
30 template <> struct MemDataImpl<8> {
31 union {
32 struct { VirtualRegister const *base, *index; } regs;
33 struct { u8* ptr; } global;
34 };
35 int offset;
36 int modeAndScale;
37 iptr _padding;
40 typedef MemDataImpl<sizeof(void*)> MemData;
41 static_assert((sizeof(MemData)&~15) == 0);
43 struct MemoryReference : MemData {
44 void setVRegSpillSlot(Ref<VirtualRegister> id) {
45 regs.base = id;
46 regs.index = nullptr;
47 offset = 0;
48 modeAndScale = MMODE_VRegSpillSlot;
50 void setBaseAndOffset(Ref<VirtualRegister> id, int o) {
51 regs.base = id;
52 regs.index = nullptr;
53 offset = o;
54 modeAndScale = MMODE_Base;
56 void setBaseIndexAndOffset(Ref<VirtualRegister> id, Ref<VirtualRegister> id2, int s, int o) {
57 regs.base = id;
58 regs.index = id2;
59 offset = o;
60 modeAndScale = MMODE_Base + (s << MMODE_Bits);
62 void setFPRelative(uint fp, int o) {
63 assert(fp >= 0 && fp < MMODE_FPCount);
64 offset = o;
65 modeAndScale = MMODE_SPRel + fp;
67 inline void setSPRelative(int o) {
68 setFPRelative(0, o);
70 void setGlobal(u8* p, int o) {
71 global.ptr = p;
72 offset = o;
73 modeAndScale = MMODE_Global;
76 MMode getMode() const { return static_cast<MMode>(modeAndScale & MMODE_Mask); }
77 int getScale() const { return modeAndScale >> MMODE_Mask; }
78 int getOffset() const { return offset; }
79 RefOrNull<VirtualRegister> getBaseReg() const { return regs.base; }
80 RefOrNull<VirtualRegister> getIndexReg() const { return regs.index; }
81 const u8* getGlobal() const { return global.ptr; }
83 void setBaseReg(RefOrNull<VirtualRegister> r) { regs.base = r; }
84 void setIndexReg(RefOrNull<VirtualRegister> r) { regs.index = r; }
87 } // end of namespace jitcs
89 #endif
90 // _JITCS_MEMREF_H_