CACAO
X86_64ModRMOperand.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/x86_64/X86_64ModRMOperand.cpp - X86_64ModRMOperand
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
26 
27 namespace cacao {
28 namespace jit {
29 namespace compiler2 {
30 namespace x86_64 {
31 
33  return this;
34 }
35 
37  return this;
38 }
39 
42  if (op_size() > index)
44 }
45 
46 u1 X86_64ModRMOperand::getRex(const X86_64Register &reg, bool opsiz64) {
47  assert(base86_64);
48  const unsigned rex_w = 3;
49  const unsigned rex_r = 2;
50  const unsigned rex_x = 1;
51  const unsigned rex_b = 0;
52 
53  u1 rex = 0x40;
54 
55  // 64-bit operand size
56  if (opsiz64) {
57  rex |= (1 << rex_w);
58  }
59  if (reg.extented) {
60  rex |= (1 << rex_r);
61  }
62  if (base86_64 && base86_64->extented) {
63  rex |= (1 << rex_b);
64  }
65  if (index86_64 && index86_64->extented) {
66  rex |= (1 << rex_x);
67  }
68  return rex;
69 
70 }
71 
73  assert(base86_64);
74  return index || base86_64 == &RSP || base86_64 == &R12;
75 }
76 
78  assert(base86_64);
79  u1 rex = getRex(reg,false);
80 
81  u1 modrm_mod = 6;
82  u1 modrm_reg = 3;
83  u1 modrm_rm = 0;
84 
85  u1 mod = 0;
86  u1 rm = 0;
87  u1 modrm = 0;
88 
89  if (useDisp8()) {
90  // disp8
91  mod = 0x01; // 0b01
92  } else if (useDisp32()) {
93  // disp32
94  mod = 0x02; // 0b10
95  }
96  else {
97  // no disp
98  mod = 0x00; // 0b00
99  }
100 
101  if (useSIB()) {
102  rm = 0x04; // 0b100
103  }
104  else {
105  rm = base86_64->get_index();
106  }
107 
108  modrm = mod << modrm_mod;
109  modrm |= reg.get_index() << modrm_reg;
110  modrm |= rm << modrm_rm;
111 
112  return modrm;
113 }
114 
116  assert(base86_64);
117  u1 rex = getRex(reg,false);
118 
119  u1 sib_scale = 6;
120  u1 sib_index = 3;
121  u1 sib_base = 0;
122 
123  u1 sib = 0;
124 
125  sib = scale << sib_scale;
126  if (index86_64) {
127  sib |= index86_64->get_index() << sib_index;
128  }
129  else {
130  sib |= RSP.get_index() << sib_index;
131  }
132 
133  sib |= base86_64->get_index() << sib_base;
134 
135  return sib;
136 }
137 
139  return disp != 0 && fits_into<s1>(disp);
140 }
141 
143  return disp != 0 && !fits_into<s1>(disp);
144 }
145 
147  return disp;
148 }
149 
151  return 0xff & (disp >> 0);
152 }
153 
155  return 0xff & (disp >> 8);
156 }
157 
159  return 0xff & (disp >> 16);
160 }
161 
163  return 0xff & (disp >> 24);
164 }
165 
167  switch (type) {
168  case Type::ByteTypeID:
169  return Scale1;
170  case Type::ShortTypeID:
171  return Scale2;
172  case Type::IntTypeID:
173  case Type::FloatTypeID:
174  return Scale4;
175  case Type::LongTypeID:
176  case Type::DoubleTypeID:
178  return Scale8;
179  default:
180  break;
181  }
182  ABORT_MSG("type not supported", "x86_64 ModRMOperand::get_scale() type: " << type);
183  return Scale1;
184 }
185 
187  switch (scale) {
188  case 1:
189  return Scale1;
190  case 2:
191  return Scale2;
192  case 4:
193  return Scale4;
194  case 8:
195  return Scale8;
196  default:
197  break;
198  }
199  ABORT_MSG("type not supported", "x86_64 ModRMOperand::get_scale() type: " << scale);
200  return Scale1;
201 }
202 
203 } // end namespace x86_64
204 } // end namespace compiler2
205 } // end namespace jit
206 } // end namespace cacao
207 
208 
209 
210 /*
211  * These are local overrides for various environment variables in Emacs.
212  * Please do not remove this and leave it at the end of the file, where
213  * Emacs will automagically detect them.
214  * ---------------------------------------------------------------------
215  * Local variables:
216  * mode: c++
217  * indent-tabs-mode: t
218  * c-basic-offset: 4
219  * tab-width: 4
220  * End:
221  * vim:noexpandtab:sw=4:ts=4:
222  */
u1 getRex(const X86_64Register &reg, bool opsiz64)
X86_64Register * cast_to< X86_64Register >(Register *reg)
alloc::set< EdgeType >::type mod
uint8_t u1
Definition: types.hpp:40
GPRegister R12("R12", 0x4, true, 0xc *8, 8)
static ScaleFactor get_scale(Type::TypeID type)
int8_t s1
Definition: types.hpp:39
embedded_operand_list embedded_operands
TODO describe.
#define ABORT_MSG(EXPR_SHORT, EXPR_LONG)
Definition: logging.hpp:133
GPRegister RSP("RSP", 0x4, false, 0x4 *8, 8)