annotate src/cpu/x86/vm/assembler_x86_32.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 3d62cb85208d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_assembler_x86_32.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // Implementation of AddressLiteral
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 AddressLiteral::AddressLiteral(address target, relocInfo::relocType rtype) {
a61af66fc99e Initial load
duke
parents:
diff changeset
31 _is_lval = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 _target = target;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 switch (rtype) {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 case relocInfo::oop_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Oops are a special case. Normally they would be their own section
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // but in cases like icBuffer they are literals in the code stream that
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // we don't have a section for. We use none so that we get a literal address
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // which is always patchable.
a61af66fc99e Initial load
duke
parents:
diff changeset
39 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 case relocInfo::external_word_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
41 _rspec = external_word_Relocation::spec(target);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 case relocInfo::internal_word_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
44 _rspec = internal_word_Relocation::spec(target);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 case relocInfo::opt_virtual_call_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
47 _rspec = opt_virtual_call_Relocation::spec();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 case relocInfo::static_call_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _rspec = static_call_Relocation::spec();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 case relocInfo::runtime_call_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _rspec = runtime_call_Relocation::spec();
a61af66fc99e Initial load
duke
parents:
diff changeset
54 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 case relocInfo::poll_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
56 case relocInfo::poll_return_type:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 _rspec = Relocation::spec_simple(rtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
58 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 case relocInfo::none:
a61af66fc99e Initial load
duke
parents:
diff changeset
60 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
62 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65 }
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // Implementation of Address
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 Address Address::make_array(ArrayAddress adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // Not implementable on 64bit machines
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Should have been handled higher up the call chain.
a61af66fc99e Initial load
duke
parents:
diff changeset
73 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
75 AddressLiteral base = adr.base();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 Address index = adr.index();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 assert(index._disp == 0, "must not have disp"); // maybe it can?
a61af66fc99e Initial load
duke
parents:
diff changeset
78 Address array(index._base, index._index, index._scale, (intptr_t) base.target());
a61af66fc99e Initial load
duke
parents:
diff changeset
79 array._rspec = base._rspec;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return array;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 #endif // _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #ifndef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // exceedingly dangerous constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
87 Address::Address(address loc, RelocationHolder spec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 _base = noreg;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 _index = noreg;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _scale = no_scale;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _disp = (intptr_t) loc;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 _rspec = spec;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 #endif // _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 // Convert the raw encoding form into the form expected by the constructor for
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Address. An index of 4 (rsp) corresponds to having no index, so convert
a61af66fc99e Initial load
duke
parents:
diff changeset
98 // that to noreg for the Address constructor.
a61af66fc99e Initial load
duke
parents:
diff changeset
99 Address Address::make_raw(int base, int index, int scale, int disp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 bool valid_index = index != rsp->encoding();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (valid_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 Address madr(as_Register(base), as_Register(index), (Address::ScaleFactor)scale, in_ByteSize(disp));
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return madr;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 Address madr(as_Register(base), noreg, Address::no_scale, in_ByteSize(disp));
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return madr;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Implementation of Assembler
a61af66fc99e Initial load
duke
parents:
diff changeset
111
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int AbstractAssembler::code_fill_byte() {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 return (u_char)'\xF4'; // hlt
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // make this go away someday
a61af66fc99e Initial load
duke
parents:
diff changeset
117 void Assembler::emit_data(jint data, relocInfo::relocType rtype, int format) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 if (rtype == relocInfo::none)
a61af66fc99e Initial load
duke
parents:
diff changeset
119 emit_long(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 else emit_data(data, Relocation::spec_simple(rtype), format);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 void Assembler::emit_data(jint data, RelocationHolder const& rspec, int format) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 assert(imm32_operand == 0, "default format must be imm32 in this file");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 assert(inst_mark() != NULL, "must be inside InstructionMark");
a61af66fc99e Initial load
duke
parents:
diff changeset
127 if (rspec.type() != relocInfo::none) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
129 check_relocation(rspec, format);
a61af66fc99e Initial load
duke
parents:
diff changeset
130 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
131 // Do not use AbstractAssembler::relocate, which is not intended for
a61af66fc99e Initial load
duke
parents:
diff changeset
132 // embedded words. Instead, relocate to the enclosing instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // hack. call32 is too wide for mask so use disp32
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if (format == call32_operand)
a61af66fc99e Initial load
duke
parents:
diff changeset
136 code_section()->relocate(inst_mark(), rspec, disp32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 else
a61af66fc99e Initial load
duke
parents:
diff changeset
138 code_section()->relocate(inst_mark(), rspec, format);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 emit_long(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 assert(dst->has_byte_register(), "must have byte register");
a61af66fc99e Initial load
duke
parents:
diff changeset
146 assert(isByte(op1) && isByte(op2), "wrong opcode");
a61af66fc99e Initial load
duke
parents:
diff changeset
147 assert(isByte(imm8), "not a byte");
a61af66fc99e Initial load
duke
parents:
diff changeset
148 assert((op1 & 0x01) == 0, "should be 8bit operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
149 emit_byte(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
150 emit_byte(op2 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
151 emit_byte(imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void Assembler::emit_arith(int op1, int op2, Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 assert(isByte(op1) && isByte(op2), "wrong opcode");
a61af66fc99e Initial load
duke
parents:
diff changeset
157 assert((op1 & 0x01) == 1, "should be 32bit operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (is8bit(imm32)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 emit_byte(op1 | 0x02); // set sign bit
a61af66fc99e Initial load
duke
parents:
diff changeset
161 emit_byte(op2 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 emit_byte(imm32 & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 emit_byte(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
165 emit_byte(op2 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
166 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // immediate-to-memory forms
a61af66fc99e Initial load
duke
parents:
diff changeset
171 void Assembler::emit_arith_operand(int op1, Register rm, Address adr, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 assert((op1 & 0x01) == 1, "should be 32bit operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
173 assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 if (is8bit(imm32)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 emit_byte(op1 | 0x02); // set sign bit
a61af66fc99e Initial load
duke
parents:
diff changeset
176 emit_operand(rm,adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 emit_byte(imm32 & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 emit_byte(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
180 emit_operand(rm,adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184
a61af66fc99e Initial load
duke
parents:
diff changeset
185 void Assembler::emit_arith(int op1, int op2, Register dst, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
186 assert(isByte(op1) && isByte(op2), "wrong opcode");
a61af66fc99e Initial load
duke
parents:
diff changeset
187 assert((op1 & 0x01) == 1, "should be 32bit operation");
a61af66fc99e Initial load
duke
parents:
diff changeset
188 assert((op1 & 0x02) == 0, "sign-extension bit should not be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
189 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 emit_byte(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
191 emit_byte(op2 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
192 emit_data((int)obj, relocInfo::oop_type, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 void Assembler::emit_arith(int op1, int op2, Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
197 assert(isByte(op1) && isByte(op2), "wrong opcode");
a61af66fc99e Initial load
duke
parents:
diff changeset
198 emit_byte(op1);
a61af66fc99e Initial load
duke
parents:
diff changeset
199 emit_byte(op2 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202
a61af66fc99e Initial load
duke
parents:
diff changeset
203 void Assembler::emit_operand(Register reg,
a61af66fc99e Initial load
duke
parents:
diff changeset
204 Register base,
a61af66fc99e Initial load
duke
parents:
diff changeset
205 Register index,
a61af66fc99e Initial load
duke
parents:
diff changeset
206 Address::ScaleFactor scale,
a61af66fc99e Initial load
duke
parents:
diff changeset
207 int disp,
a61af66fc99e Initial load
duke
parents:
diff changeset
208 RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 relocInfo::relocType rtype = (relocInfo::relocType) rspec.type();
a61af66fc99e Initial load
duke
parents:
diff changeset
211 if (base->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (index->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 assert(scale != Address::no_scale, "inconsistent address");
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // [base + index*scale + disp]
a61af66fc99e Initial load
duke
parents:
diff changeset
215 if (disp == 0 && rtype == relocInfo::none && base != rbp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // [base + index*scale]
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // [00 reg 100][ss index base]
a61af66fc99e Initial load
duke
parents:
diff changeset
218 assert(index != rsp, "illegal addressing mode");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 emit_byte(0x04 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 emit_byte(scale << 6 | index->encoding() << 3 | base->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
221 } else if (is8bit(disp) && rtype == relocInfo::none) {
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // [base + index*scale + imm8]
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // [01 reg 100][ss index base] imm8
a61af66fc99e Initial load
duke
parents:
diff changeset
224 assert(index != rsp, "illegal addressing mode");
a61af66fc99e Initial load
duke
parents:
diff changeset
225 emit_byte(0x44 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 emit_byte(scale << 6 | index->encoding() << 3 | base->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
227 emit_byte(disp & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
228 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // [base + index*scale + imm32]
a61af66fc99e Initial load
duke
parents:
diff changeset
230 // [10 reg 100][ss index base] imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
231 assert(index != rsp, "illegal addressing mode");
a61af66fc99e Initial load
duke
parents:
diff changeset
232 emit_byte(0x84 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 emit_byte(scale << 6 | index->encoding() << 3 | base->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
234 emit_data(disp, rspec, disp32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 } else if (base == rsp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // [esp + disp]
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (disp == 0 && rtype == relocInfo::none) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // [esp]
a61af66fc99e Initial load
duke
parents:
diff changeset
240 // [00 reg 100][00 100 100]
a61af66fc99e Initial load
duke
parents:
diff changeset
241 emit_byte(0x04 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
242 emit_byte(0x24);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 } else if (is8bit(disp) && rtype == relocInfo::none) {
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // [esp + imm8]
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // [01 reg 100][00 100 100] imm8
a61af66fc99e Initial load
duke
parents:
diff changeset
246 emit_byte(0x44 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 emit_byte(0x24);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 emit_byte(disp & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // [esp + imm32]
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // [10 reg 100][00 100 100] imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
252 emit_byte(0x84 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
253 emit_byte(0x24);
a61af66fc99e Initial load
duke
parents:
diff changeset
254 emit_data(disp, rspec, disp32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // [base + disp]
a61af66fc99e Initial load
duke
parents:
diff changeset
258 assert(base != rsp, "illegal addressing mode");
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (disp == 0 && rtype == relocInfo::none && base != rbp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
260 // [base]
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // [00 reg base]
a61af66fc99e Initial load
duke
parents:
diff changeset
262 assert(base != rbp, "illegal addressing mode");
a61af66fc99e Initial load
duke
parents:
diff changeset
263 emit_byte(0x00 | reg->encoding() << 3 | base->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
264 } else if (is8bit(disp) && rtype == relocInfo::none) {
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // [base + imm8]
a61af66fc99e Initial load
duke
parents:
diff changeset
266 // [01 reg base] imm8
a61af66fc99e Initial load
duke
parents:
diff changeset
267 emit_byte(0x40 | reg->encoding() << 3 | base->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
268 emit_byte(disp & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // [base + imm32]
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // [10 reg base] imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
272 emit_byte(0x80 | reg->encoding() << 3 | base->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
273 emit_data(disp, rspec, disp32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 }
a61af66fc99e Initial load
duke
parents:
diff changeset
276 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 if (index->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 assert(scale != Address::no_scale, "inconsistent address");
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // [index*scale + disp]
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // [00 reg 100][ss index 101] imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
281 assert(index != rsp, "illegal addressing mode");
a61af66fc99e Initial load
duke
parents:
diff changeset
282 emit_byte(0x04 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
283 emit_byte(scale << 6 | index->encoding() << 3 | 0x05);
a61af66fc99e Initial load
duke
parents:
diff changeset
284 emit_data(disp, rspec, disp32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // [disp]
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // [00 reg 101] imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
288 emit_byte(0x05 | reg->encoding() << 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 emit_data(disp, rspec, disp32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // Secret local extension to Assembler::WhichOperand:
a61af66fc99e Initial load
duke
parents:
diff changeset
295 #define end_pc_operand (_WhichOperand_limit)
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 address Assembler::locate_operand(address inst, WhichOperand which) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // Decode the given instruction, and return the address of
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // an embedded 32-bit operand word.
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 // If "which" is disp32_operand, selects the displacement portion
a61af66fc99e Initial load
duke
parents:
diff changeset
302 // of an effective address specifier.
a61af66fc99e Initial load
duke
parents:
diff changeset
303 // If "which" is imm32_operand, selects the trailing immediate constant.
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // If "which" is call32_operand, selects the displacement of a call or jump.
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // Caller is responsible for ensuring that there is such an operand,
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // and that it is 32 bits wide.
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // If "which" is end_pc_operand, find the end of the instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 address ip = inst;
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 debug_only(bool has_imm32 = false);
a61af66fc99e Initial load
duke
parents:
diff changeset
313 int tail_size = 0; // other random bytes (#32, #16, etc.) at end of insn
a61af66fc99e Initial load
duke
parents:
diff changeset
314
a61af66fc99e Initial load
duke
parents:
diff changeset
315 again_after_prefix:
a61af66fc99e Initial load
duke
parents:
diff changeset
316 switch (0xFF & *ip++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
317
a61af66fc99e Initial load
duke
parents:
diff changeset
318 // These convenience macros generate groups of "case" labels for the switch.
a61af66fc99e Initial load
duke
parents:
diff changeset
319 #define REP4(x) (x)+0: case (x)+1: case (x)+2: case (x)+3
a61af66fc99e Initial load
duke
parents:
diff changeset
320 #define REP8(x) (x)+0: case (x)+1: case (x)+2: case (x)+3: \
a61af66fc99e Initial load
duke
parents:
diff changeset
321 case (x)+4: case (x)+5: case (x)+6: case (x)+7
a61af66fc99e Initial load
duke
parents:
diff changeset
322 #define REP16(x) REP8((x)+0): \
a61af66fc99e Initial load
duke
parents:
diff changeset
323 case REP8((x)+8)
a61af66fc99e Initial load
duke
parents:
diff changeset
324
a61af66fc99e Initial load
duke
parents:
diff changeset
325 case CS_segment:
a61af66fc99e Initial load
duke
parents:
diff changeset
326 case SS_segment:
a61af66fc99e Initial load
duke
parents:
diff changeset
327 case DS_segment:
a61af66fc99e Initial load
duke
parents:
diff changeset
328 case ES_segment:
a61af66fc99e Initial load
duke
parents:
diff changeset
329 case FS_segment:
a61af66fc99e Initial load
duke
parents:
diff changeset
330 case GS_segment:
a61af66fc99e Initial load
duke
parents:
diff changeset
331 assert(ip == inst+1, "only one prefix allowed");
a61af66fc99e Initial load
duke
parents:
diff changeset
332 goto again_after_prefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
333
a61af66fc99e Initial load
duke
parents:
diff changeset
334 case 0xFF: // pushl a; decl a; incl a; call a; jmp a
a61af66fc99e Initial load
duke
parents:
diff changeset
335 case 0x88: // movb a, r
a61af66fc99e Initial load
duke
parents:
diff changeset
336 case 0x89: // movl a, r
a61af66fc99e Initial load
duke
parents:
diff changeset
337 case 0x8A: // movb r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
338 case 0x8B: // movl r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
339 case 0x8F: // popl a
a61af66fc99e Initial load
duke
parents:
diff changeset
340 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
341
a61af66fc99e Initial load
duke
parents:
diff changeset
342 case 0x68: // pushl #32(oop?)
a61af66fc99e Initial load
duke
parents:
diff changeset
343 if (which == end_pc_operand) return ip + 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
344 assert(which == imm32_operand, "pushl has no disp32");
a61af66fc99e Initial load
duke
parents:
diff changeset
345 return ip; // not produced by emit_operand
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 case 0x66: // movw ... (size prefix)
a61af66fc99e Initial load
duke
parents:
diff changeset
348 switch (0xFF & *ip++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 case 0x8B: // movw r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
350 case 0x89: // movw a, r
a61af66fc99e Initial load
duke
parents:
diff changeset
351 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
352 case 0xC7: // movw a, #16
a61af66fc99e Initial load
duke
parents:
diff changeset
353 tail_size = 2; // the imm16
a61af66fc99e Initial load
duke
parents:
diff changeset
354 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
355 case 0x0F: // several SSE/SSE2 variants
a61af66fc99e Initial load
duke
parents:
diff changeset
356 ip--; // reparse the 0x0F
a61af66fc99e Initial load
duke
parents:
diff changeset
357 goto again_after_prefix;
a61af66fc99e Initial load
duke
parents:
diff changeset
358 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
359 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
361 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
362
a61af66fc99e Initial load
duke
parents:
diff changeset
363 case REP8(0xB8): // movl r, #32(oop?)
a61af66fc99e Initial load
duke
parents:
diff changeset
364 if (which == end_pc_operand) return ip + 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 assert(which == imm32_operand || which == disp32_operand, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
366 return ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 case 0x69: // imul r, a, #32
a61af66fc99e Initial load
duke
parents:
diff changeset
369 case 0xC7: // movl a, #32(oop?)
a61af66fc99e Initial load
duke
parents:
diff changeset
370 tail_size = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 debug_only(has_imm32 = true); // has both kinds of operands!
a61af66fc99e Initial load
duke
parents:
diff changeset
372 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 case 0x0F: // movx..., etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
375 switch (0xFF & *ip++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 case 0x12: // movlps
a61af66fc99e Initial load
duke
parents:
diff changeset
377 case 0x28: // movaps
a61af66fc99e Initial load
duke
parents:
diff changeset
378 case 0x2E: // ucomiss
a61af66fc99e Initial load
duke
parents:
diff changeset
379 case 0x2F: // comiss
a61af66fc99e Initial load
duke
parents:
diff changeset
380 case 0x54: // andps
a61af66fc99e Initial load
duke
parents:
diff changeset
381 case 0x55: // andnps
a61af66fc99e Initial load
duke
parents:
diff changeset
382 case 0x56: // orps
a61af66fc99e Initial load
duke
parents:
diff changeset
383 case 0x57: // xorps
a61af66fc99e Initial load
duke
parents:
diff changeset
384 case 0x6E: // movd
a61af66fc99e Initial load
duke
parents:
diff changeset
385 case 0x7E: // movd
a61af66fc99e Initial load
duke
parents:
diff changeset
386 case 0xAE: // ldmxcsr a
a61af66fc99e Initial load
duke
parents:
diff changeset
387 // amd side says it these have both operands but that doesn't
a61af66fc99e Initial load
duke
parents:
diff changeset
388 // appear to be true.
a61af66fc99e Initial load
duke
parents:
diff changeset
389 // debug_only(has_imm32 = true); // has both kinds of operands!
a61af66fc99e Initial load
duke
parents:
diff changeset
390 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 case 0xAD: // shrd r, a, %cl
a61af66fc99e Initial load
duke
parents:
diff changeset
393 case 0xAF: // imul r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
394 case 0xBE: // movsxb r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
395 case 0xBF: // movsxw r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
396 case 0xB6: // movzxb r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
397 case 0xB7: // movzxw r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
398 case REP16(0x40): // cmovl cc, r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
399 case 0xB0: // cmpxchgb
a61af66fc99e Initial load
duke
parents:
diff changeset
400 case 0xB1: // cmpxchg
a61af66fc99e Initial load
duke
parents:
diff changeset
401 case 0xC1: // xaddl
a61af66fc99e Initial load
duke
parents:
diff changeset
402 case 0xC7: // cmpxchg8
a61af66fc99e Initial load
duke
parents:
diff changeset
403 case REP16(0x90): // setcc a
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // fall out of the switch to decode the address
a61af66fc99e Initial load
duke
parents:
diff changeset
405 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
406 case 0xAC: // shrd r, a, #8
a61af66fc99e Initial load
duke
parents:
diff changeset
407 tail_size = 1; // the imm8
a61af66fc99e Initial load
duke
parents:
diff changeset
408 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 case REP16(0x80): // jcc rdisp32
a61af66fc99e Initial load
duke
parents:
diff changeset
410 if (which == end_pc_operand) return ip + 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 assert(which == call32_operand, "jcc has no disp32 or imm32");
a61af66fc99e Initial load
duke
parents:
diff changeset
412 return ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
414 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 case 0x81: // addl a, #32; addl r, #32
a61af66fc99e Initial load
duke
parents:
diff changeset
419 // also: orl, adcl, sbbl, andl, subl, xorl, cmpl
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // in the case of cmpl, the imm32 might be an oop
a61af66fc99e Initial load
duke
parents:
diff changeset
421 tail_size = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 debug_only(has_imm32 = true); // has both kinds of operands!
a61af66fc99e Initial load
duke
parents:
diff changeset
423 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 case 0x85: // test r/m, r
a61af66fc99e Initial load
duke
parents:
diff changeset
426 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
427
a61af66fc99e Initial load
duke
parents:
diff changeset
428 case 0x83: // addl a, #8; addl r, #8
a61af66fc99e Initial load
duke
parents:
diff changeset
429 // also: orl, adcl, sbbl, andl, subl, xorl, cmpl
a61af66fc99e Initial load
duke
parents:
diff changeset
430 tail_size = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 case 0x9B:
a61af66fc99e Initial load
duke
parents:
diff changeset
434 switch (0xFF & *ip++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
435 case 0xD9: // fnstcw a
a61af66fc99e Initial load
duke
parents:
diff changeset
436 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
438 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
441
a61af66fc99e Initial load
duke
parents:
diff changeset
442 case REP4(0x00): // addb a, r; addl a, r; addb r, a; addl r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
443 case REP4(0x10): // adc...
a61af66fc99e Initial load
duke
parents:
diff changeset
444 case REP4(0x20): // and...
a61af66fc99e Initial load
duke
parents:
diff changeset
445 case REP4(0x30): // xor...
a61af66fc99e Initial load
duke
parents:
diff changeset
446 case REP4(0x08): // or...
a61af66fc99e Initial load
duke
parents:
diff changeset
447 case REP4(0x18): // sbb...
a61af66fc99e Initial load
duke
parents:
diff changeset
448 case REP4(0x28): // sub...
a61af66fc99e Initial load
duke
parents:
diff changeset
449 case REP4(0x38): // cmp...
a61af66fc99e Initial load
duke
parents:
diff changeset
450 case 0xF7: // mull a
a61af66fc99e Initial load
duke
parents:
diff changeset
451 case 0x8D: // leal r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
452 case 0x87: // xchg r, a
a61af66fc99e Initial load
duke
parents:
diff changeset
453 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
454
a61af66fc99e Initial load
duke
parents:
diff changeset
455 case 0xC1: // sal a, #8; sar a, #8; shl a, #8; shr a, #8
a61af66fc99e Initial load
duke
parents:
diff changeset
456 case 0xC6: // movb a, #8
a61af66fc99e Initial load
duke
parents:
diff changeset
457 case 0x80: // cmpb a, #8
a61af66fc99e Initial load
duke
parents:
diff changeset
458 case 0x6B: // imul r, a, #8
a61af66fc99e Initial load
duke
parents:
diff changeset
459 tail_size = 1; // the imm8
a61af66fc99e Initial load
duke
parents:
diff changeset
460 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 case 0xE8: // call rdisp32
a61af66fc99e Initial load
duke
parents:
diff changeset
463 case 0xE9: // jmp rdisp32
a61af66fc99e Initial load
duke
parents:
diff changeset
464 if (which == end_pc_operand) return ip + 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
465 assert(which == call32_operand, "call has no disp32 or imm32");
a61af66fc99e Initial load
duke
parents:
diff changeset
466 return ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
467
a61af66fc99e Initial load
duke
parents:
diff changeset
468 case 0xD1: // sal a, 1; sar a, 1; shl a, 1; shr a, 1
a61af66fc99e Initial load
duke
parents:
diff changeset
469 case 0xD3: // sal a, %cl; sar a, %cl; shl a, %cl; shr a, %cl
a61af66fc99e Initial load
duke
parents:
diff changeset
470 case 0xD9: // fld_s a; fst_s a; fstp_s a; fldcw a
a61af66fc99e Initial load
duke
parents:
diff changeset
471 case 0xDD: // fld_d a; fst_d a; fstp_d a
a61af66fc99e Initial load
duke
parents:
diff changeset
472 case 0xDB: // fild_s a; fistp_s a; fld_x a; fstp_x a
a61af66fc99e Initial load
duke
parents:
diff changeset
473 case 0xDF: // fild_d a; fistp_d a
a61af66fc99e Initial load
duke
parents:
diff changeset
474 case 0xD8: // fadd_s a; fsubr_s a; fmul_s a; fdivr_s a; fcomp_s a
a61af66fc99e Initial load
duke
parents:
diff changeset
475 case 0xDC: // fadd_d a; fsubr_d a; fmul_d a; fdivr_d a; fcomp_d a
a61af66fc99e Initial load
duke
parents:
diff changeset
476 case 0xDE: // faddp_d a; fsubrp_d a; fmulp_d a; fdivrp_d a; fcompp_d a
a61af66fc99e Initial load
duke
parents:
diff changeset
477 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 case 0xF3: // For SSE
a61af66fc99e Initial load
duke
parents:
diff changeset
480 case 0xF2: // For SSE2
a61af66fc99e Initial load
duke
parents:
diff changeset
481 ip++; ip++;
a61af66fc99e Initial load
duke
parents:
diff changeset
482 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
483
a61af66fc99e Initial load
duke
parents:
diff changeset
484 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
485 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
486
a61af66fc99e Initial load
duke
parents:
diff changeset
487 #undef REP8
a61af66fc99e Initial load
duke
parents:
diff changeset
488 #undef REP16
a61af66fc99e Initial load
duke
parents:
diff changeset
489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 assert(which != call32_operand, "instruction is not a call, jmp, or jcc");
a61af66fc99e Initial load
duke
parents:
diff changeset
492 assert(which != imm32_operand || has_imm32, "instruction has no imm32 field");
a61af66fc99e Initial load
duke
parents:
diff changeset
493
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // parse the output of emit_operand
a61af66fc99e Initial load
duke
parents:
diff changeset
495 int op2 = 0xFF & *ip++;
a61af66fc99e Initial load
duke
parents:
diff changeset
496 int base = op2 & 0x07;
a61af66fc99e Initial load
duke
parents:
diff changeset
497 int op3 = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 const int b100 = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
499 const int b101 = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
500 if (base == b100 && (op2 >> 6) != 3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
501 op3 = 0xFF & *ip++;
a61af66fc99e Initial load
duke
parents:
diff changeset
502 base = op3 & 0x07; // refetch the base
a61af66fc99e Initial load
duke
parents:
diff changeset
503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // now ip points at the disp (if any)
a61af66fc99e Initial load
duke
parents:
diff changeset
505
a61af66fc99e Initial load
duke
parents:
diff changeset
506 switch (op2 >> 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
507 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // [00 reg 100][ss index base]
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // [00 reg 100][00 100 rsp]
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // [00 reg base]
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // [00 reg 100][ss index 101][disp32]
a61af66fc99e Initial load
duke
parents:
diff changeset
512 // [00 reg 101] [disp32]
a61af66fc99e Initial load
duke
parents:
diff changeset
513
a61af66fc99e Initial load
duke
parents:
diff changeset
514 if (base == b101) {
a61af66fc99e Initial load
duke
parents:
diff changeset
515 if (which == disp32_operand)
a61af66fc99e Initial load
duke
parents:
diff changeset
516 return ip; // caller wants the disp32
a61af66fc99e Initial load
duke
parents:
diff changeset
517 ip += 4; // skip the disp32
a61af66fc99e Initial load
duke
parents:
diff changeset
518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
519 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
520
a61af66fc99e Initial load
duke
parents:
diff changeset
521 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
522 // [01 reg 100][ss index base][disp8]
a61af66fc99e Initial load
duke
parents:
diff changeset
523 // [01 reg 100][00 100 rsp][disp8]
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // [01 reg base] [disp8]
a61af66fc99e Initial load
duke
parents:
diff changeset
525 ip += 1; // skip the disp8
a61af66fc99e Initial load
duke
parents:
diff changeset
526 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
527
a61af66fc99e Initial load
duke
parents:
diff changeset
528 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // [10 reg 100][ss index base][disp32]
a61af66fc99e Initial load
duke
parents:
diff changeset
530 // [10 reg 100][00 100 rsp][disp32]
a61af66fc99e Initial load
duke
parents:
diff changeset
531 // [10 reg base] [disp32]
a61af66fc99e Initial load
duke
parents:
diff changeset
532 if (which == disp32_operand)
a61af66fc99e Initial load
duke
parents:
diff changeset
533 return ip; // caller wants the disp32
a61af66fc99e Initial load
duke
parents:
diff changeset
534 ip += 4; // skip the disp32
a61af66fc99e Initial load
duke
parents:
diff changeset
535 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
536
a61af66fc99e Initial load
duke
parents:
diff changeset
537 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // [11 reg base] (not a memory addressing mode)
a61af66fc99e Initial load
duke
parents:
diff changeset
539 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 }
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 if (which == end_pc_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
543 return ip + tail_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
544 }
a61af66fc99e Initial load
duke
parents:
diff changeset
545
a61af66fc99e Initial load
duke
parents:
diff changeset
546 assert(which == imm32_operand, "instruction has only an imm32 field");
a61af66fc99e Initial load
duke
parents:
diff changeset
547 return ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
548 }
a61af66fc99e Initial load
duke
parents:
diff changeset
549
a61af66fc99e Initial load
duke
parents:
diff changeset
550 address Assembler::locate_next_instruction(address inst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
551 // Secretly share code with locate_operand:
a61af66fc99e Initial load
duke
parents:
diff changeset
552 return locate_operand(inst, end_pc_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 }
a61af66fc99e Initial load
duke
parents:
diff changeset
554
a61af66fc99e Initial load
duke
parents:
diff changeset
555
a61af66fc99e Initial load
duke
parents:
diff changeset
556 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
557 void Assembler::check_relocation(RelocationHolder const& rspec, int format) {
a61af66fc99e Initial load
duke
parents:
diff changeset
558 address inst = inst_mark();
a61af66fc99e Initial load
duke
parents:
diff changeset
559 assert(inst != NULL && inst < pc(), "must point to beginning of instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
560 address opnd;
a61af66fc99e Initial load
duke
parents:
diff changeset
561
a61af66fc99e Initial load
duke
parents:
diff changeset
562 Relocation* r = rspec.reloc();
a61af66fc99e Initial load
duke
parents:
diff changeset
563 if (r->type() == relocInfo::none) {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
565 } else if (r->is_call() || format == call32_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
566 // assert(format == imm32_operand, "cannot specify a nonzero format");
a61af66fc99e Initial load
duke
parents:
diff changeset
567 opnd = locate_operand(inst, call32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
568 } else if (r->is_data()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 assert(format == imm32_operand || format == disp32_operand, "format ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
570 opnd = locate_operand(inst, (WhichOperand)format);
a61af66fc99e Initial load
duke
parents:
diff changeset
571 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
572 assert(format == imm32_operand, "cannot specify a format");
a61af66fc99e Initial load
duke
parents:
diff changeset
573 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
574 }
a61af66fc99e Initial load
duke
parents:
diff changeset
575 assert(opnd == pc(), "must put operand where relocs can find it");
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
a61af66fc99e Initial load
duke
parents:
diff changeset
577 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579
a61af66fc99e Initial load
duke
parents:
diff changeset
580
a61af66fc99e Initial load
duke
parents:
diff changeset
581 void Assembler::emit_operand(Register reg, Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
582 emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
a61af66fc99e Initial load
duke
parents:
diff changeset
583 }
a61af66fc99e Initial load
duke
parents:
diff changeset
584
a61af66fc99e Initial load
duke
parents:
diff changeset
585
a61af66fc99e Initial load
duke
parents:
diff changeset
586 void Assembler::emit_farith(int b1, int b2, int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
587 assert(isByte(b1) && isByte(b2), "wrong opcode");
a61af66fc99e Initial load
duke
parents:
diff changeset
588 assert(0 <= i && i < 8, "illegal stack offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
589 emit_byte(b1);
a61af66fc99e Initial load
duke
parents:
diff changeset
590 emit_byte(b2 + i);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
592
a61af66fc99e Initial load
duke
parents:
diff changeset
593
a61af66fc99e Initial load
duke
parents:
diff changeset
594 void Assembler::pushad() {
a61af66fc99e Initial load
duke
parents:
diff changeset
595 emit_byte(0x60);
a61af66fc99e Initial load
duke
parents:
diff changeset
596 }
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598 void Assembler::popad() {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 emit_byte(0x61);
a61af66fc99e Initial load
duke
parents:
diff changeset
600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 void Assembler::pushfd() {
a61af66fc99e Initial load
duke
parents:
diff changeset
603 emit_byte(0x9C);
a61af66fc99e Initial load
duke
parents:
diff changeset
604 }
a61af66fc99e Initial load
duke
parents:
diff changeset
605
a61af66fc99e Initial load
duke
parents:
diff changeset
606 void Assembler::popfd() {
a61af66fc99e Initial load
duke
parents:
diff changeset
607 emit_byte(0x9D);
a61af66fc99e Initial load
duke
parents:
diff changeset
608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
609
a61af66fc99e Initial load
duke
parents:
diff changeset
610 void Assembler::pushl(int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
611 emit_byte(0x68);
a61af66fc99e Initial load
duke
parents:
diff changeset
612 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
613 }
a61af66fc99e Initial load
duke
parents:
diff changeset
614
a61af66fc99e Initial load
duke
parents:
diff changeset
615 #ifndef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
616 void Assembler::push_literal32(int32_t imm32, RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
618 emit_byte(0x68);
a61af66fc99e Initial load
duke
parents:
diff changeset
619 emit_data(imm32, rspec, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
620 }
a61af66fc99e Initial load
duke
parents:
diff changeset
621 #endif // _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
622
a61af66fc99e Initial load
duke
parents:
diff changeset
623 void Assembler::pushl(Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
624 emit_byte(0x50 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627
a61af66fc99e Initial load
duke
parents:
diff changeset
628 void Assembler::pushl(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
629 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
630 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
631 emit_operand(rsi, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 void Assembler::popl(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
635 emit_byte(0x58 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
636 }
a61af66fc99e Initial load
duke
parents:
diff changeset
637
a61af66fc99e Initial load
duke
parents:
diff changeset
638
a61af66fc99e Initial load
duke
parents:
diff changeset
639 void Assembler::popl(Address dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
640 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
641 emit_byte(0x8F);
a61af66fc99e Initial load
duke
parents:
diff changeset
642 emit_operand(rax, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
643 }
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645
a61af66fc99e Initial load
duke
parents:
diff changeset
646 void Assembler::prefix(Prefix p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
647 a_byte(p);
a61af66fc99e Initial load
duke
parents:
diff changeset
648 }
a61af66fc99e Initial load
duke
parents:
diff changeset
649
a61af66fc99e Initial load
duke
parents:
diff changeset
650
a61af66fc99e Initial load
duke
parents:
diff changeset
651 void Assembler::movb(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
652 assert(dst->has_byte_register(), "must have byte register");
a61af66fc99e Initial load
duke
parents:
diff changeset
653 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
654 emit_byte(0x8A);
a61af66fc99e Initial load
duke
parents:
diff changeset
655 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
656 }
a61af66fc99e Initial load
duke
parents:
diff changeset
657
a61af66fc99e Initial load
duke
parents:
diff changeset
658
a61af66fc99e Initial load
duke
parents:
diff changeset
659 void Assembler::movb(Address dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
661 emit_byte(0xC6);
a61af66fc99e Initial load
duke
parents:
diff changeset
662 emit_operand(rax, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
663 emit_byte(imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
664 }
a61af66fc99e Initial load
duke
parents:
diff changeset
665
a61af66fc99e Initial load
duke
parents:
diff changeset
666
a61af66fc99e Initial load
duke
parents:
diff changeset
667 void Assembler::movb(Address dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
668 assert(src->has_byte_register(), "must have byte register");
a61af66fc99e Initial load
duke
parents:
diff changeset
669 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
670 emit_byte(0x88);
a61af66fc99e Initial load
duke
parents:
diff changeset
671 emit_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
672 }
a61af66fc99e Initial load
duke
parents:
diff changeset
673
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 void Assembler::movw(Address dst, int imm16) {
a61af66fc99e Initial load
duke
parents:
diff changeset
676 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
677
a61af66fc99e Initial load
duke
parents:
diff changeset
678 emit_byte(0x66); // switch to 16-bit mode
a61af66fc99e Initial load
duke
parents:
diff changeset
679 emit_byte(0xC7);
a61af66fc99e Initial load
duke
parents:
diff changeset
680 emit_operand(rax, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
681 emit_word(imm16);
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683
a61af66fc99e Initial load
duke
parents:
diff changeset
684
a61af66fc99e Initial load
duke
parents:
diff changeset
685 void Assembler::movw(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
686 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
687 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
688 emit_byte(0x8B);
a61af66fc99e Initial load
duke
parents:
diff changeset
689 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
691
a61af66fc99e Initial load
duke
parents:
diff changeset
692
a61af66fc99e Initial load
duke
parents:
diff changeset
693 void Assembler::movw(Address dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
694 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
695 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 emit_byte(0x89);
a61af66fc99e Initial load
duke
parents:
diff changeset
697 emit_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
699
a61af66fc99e Initial load
duke
parents:
diff changeset
700
a61af66fc99e Initial load
duke
parents:
diff changeset
701 void Assembler::movl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
702 emit_byte(0xB8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
703 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
704 }
a61af66fc99e Initial load
duke
parents:
diff changeset
705
a61af66fc99e Initial load
duke
parents:
diff changeset
706 #ifndef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
707 void Assembler::mov_literal32(Register dst, int32_t imm32, RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
708
a61af66fc99e Initial load
duke
parents:
diff changeset
709 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
710 emit_byte(0xB8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
711 emit_data((int)imm32, rspec, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713 #endif // _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
714
a61af66fc99e Initial load
duke
parents:
diff changeset
715 void Assembler::movl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
716 emit_byte(0x8B);
a61af66fc99e Initial load
duke
parents:
diff changeset
717 emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
718 }
a61af66fc99e Initial load
duke
parents:
diff changeset
719
a61af66fc99e Initial load
duke
parents:
diff changeset
720
a61af66fc99e Initial load
duke
parents:
diff changeset
721 void Assembler::movl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
722 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
723 emit_byte(0x8B);
a61af66fc99e Initial load
duke
parents:
diff changeset
724 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726
a61af66fc99e Initial load
duke
parents:
diff changeset
727
a61af66fc99e Initial load
duke
parents:
diff changeset
728 void Assembler::movl(Address dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
729 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
730 emit_byte(0xC7);
a61af66fc99e Initial load
duke
parents:
diff changeset
731 emit_operand(rax, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
732 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
733 }
a61af66fc99e Initial load
duke
parents:
diff changeset
734
a61af66fc99e Initial load
duke
parents:
diff changeset
735 #ifndef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
736 void Assembler::mov_literal32(Address dst, int32_t imm32, RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
737 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
738 emit_byte(0xC7);
a61af66fc99e Initial load
duke
parents:
diff changeset
739 emit_operand(rax, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
740 emit_data((int)imm32, rspec, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
741 }
a61af66fc99e Initial load
duke
parents:
diff changeset
742 #endif // _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
743
a61af66fc99e Initial load
duke
parents:
diff changeset
744 void Assembler::movl(Address dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
746 emit_byte(0x89);
a61af66fc99e Initial load
duke
parents:
diff changeset
747 emit_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
748 }
a61af66fc99e Initial load
duke
parents:
diff changeset
749
a61af66fc99e Initial load
duke
parents:
diff changeset
750 void Assembler::movsxb(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
751 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
752 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
753 emit_byte(0xBE);
a61af66fc99e Initial load
duke
parents:
diff changeset
754 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
756
a61af66fc99e Initial load
duke
parents:
diff changeset
757 void Assembler::movsxb(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
758 assert(src->has_byte_register(), "must have byte register");
a61af66fc99e Initial load
duke
parents:
diff changeset
759 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
760 emit_byte(0xBE);
a61af66fc99e Initial load
duke
parents:
diff changeset
761 emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
762 }
a61af66fc99e Initial load
duke
parents:
diff changeset
763
a61af66fc99e Initial load
duke
parents:
diff changeset
764
a61af66fc99e Initial load
duke
parents:
diff changeset
765 void Assembler::movsxw(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
766 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
767 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
768 emit_byte(0xBF);
a61af66fc99e Initial load
duke
parents:
diff changeset
769 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
770 }
a61af66fc99e Initial load
duke
parents:
diff changeset
771
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773 void Assembler::movsxw(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
774 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
775 emit_byte(0xBF);
a61af66fc99e Initial load
duke
parents:
diff changeset
776 emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
777 }
a61af66fc99e Initial load
duke
parents:
diff changeset
778
a61af66fc99e Initial load
duke
parents:
diff changeset
779
a61af66fc99e Initial load
duke
parents:
diff changeset
780 void Assembler::movzxb(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
781 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
782 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
783 emit_byte(0xB6);
a61af66fc99e Initial load
duke
parents:
diff changeset
784 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
785 }
a61af66fc99e Initial load
duke
parents:
diff changeset
786
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788 void Assembler::movzxb(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
789 assert(src->has_byte_register(), "must have byte register");
a61af66fc99e Initial load
duke
parents:
diff changeset
790 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
791 emit_byte(0xB6);
a61af66fc99e Initial load
duke
parents:
diff changeset
792 emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
793 }
a61af66fc99e Initial load
duke
parents:
diff changeset
794
a61af66fc99e Initial load
duke
parents:
diff changeset
795
a61af66fc99e Initial load
duke
parents:
diff changeset
796 void Assembler::movzxw(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
797 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
798 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
799 emit_byte(0xB7);
a61af66fc99e Initial load
duke
parents:
diff changeset
800 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
801 }
a61af66fc99e Initial load
duke
parents:
diff changeset
802
a61af66fc99e Initial load
duke
parents:
diff changeset
803
a61af66fc99e Initial load
duke
parents:
diff changeset
804 void Assembler::movzxw(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
805 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
806 emit_byte(0xB7);
a61af66fc99e Initial load
duke
parents:
diff changeset
807 emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
808 }
a61af66fc99e Initial load
duke
parents:
diff changeset
809
a61af66fc99e Initial load
duke
parents:
diff changeset
810
a61af66fc99e Initial load
duke
parents:
diff changeset
811 void Assembler::cmovl(Condition cc, Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
812 guarantee(VM_Version::supports_cmov(), "illegal instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
813 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
814 emit_byte(0x40 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
815 emit_byte(0xC0 | (dst->encoding() << 3) | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
816 }
a61af66fc99e Initial load
duke
parents:
diff changeset
817
a61af66fc99e Initial load
duke
parents:
diff changeset
818
a61af66fc99e Initial load
duke
parents:
diff changeset
819 void Assembler::cmovl(Condition cc, Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
820 guarantee(VM_Version::supports_cmov(), "illegal instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // The code below seems to be wrong - however the manual is inconclusive
a61af66fc99e Initial load
duke
parents:
diff changeset
822 // do not use for now (remember to enable all callers when fixing this)
a61af66fc99e Initial load
duke
parents:
diff changeset
823 Unimplemented();
a61af66fc99e Initial load
duke
parents:
diff changeset
824 // wrong bytes?
a61af66fc99e Initial load
duke
parents:
diff changeset
825 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
826 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
827 emit_byte(0x40 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
828 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
829 }
a61af66fc99e Initial load
duke
parents:
diff changeset
830
a61af66fc99e Initial load
duke
parents:
diff changeset
831
a61af66fc99e Initial load
duke
parents:
diff changeset
832 void Assembler::prefetcht0(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
833 assert(VM_Version::supports_sse(), "must support");
a61af66fc99e Initial load
duke
parents:
diff changeset
834 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
835 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
836 emit_byte(0x18);
a61af66fc99e Initial load
duke
parents:
diff changeset
837 emit_operand(rcx, src); // 1, src
a61af66fc99e Initial load
duke
parents:
diff changeset
838 }
a61af66fc99e Initial load
duke
parents:
diff changeset
839
a61af66fc99e Initial load
duke
parents:
diff changeset
840
a61af66fc99e Initial load
duke
parents:
diff changeset
841 void Assembler::prefetcht1(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
842 assert(VM_Version::supports_sse(), "must support");
a61af66fc99e Initial load
duke
parents:
diff changeset
843 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
844 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
845 emit_byte(0x18);
a61af66fc99e Initial load
duke
parents:
diff changeset
846 emit_operand(rdx, src); // 2, src
a61af66fc99e Initial load
duke
parents:
diff changeset
847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
848
a61af66fc99e Initial load
duke
parents:
diff changeset
849
a61af66fc99e Initial load
duke
parents:
diff changeset
850 void Assembler::prefetcht2(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
851 assert(VM_Version::supports_sse(), "must support");
a61af66fc99e Initial load
duke
parents:
diff changeset
852 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
853 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
854 emit_byte(0x18);
a61af66fc99e Initial load
duke
parents:
diff changeset
855 emit_operand(rbx, src); // 3, src
a61af66fc99e Initial load
duke
parents:
diff changeset
856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
857
a61af66fc99e Initial load
duke
parents:
diff changeset
858
a61af66fc99e Initial load
duke
parents:
diff changeset
859 void Assembler::prefetchnta(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
860 assert(VM_Version::supports_sse2(), "must support");
a61af66fc99e Initial load
duke
parents:
diff changeset
861 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
862 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
863 emit_byte(0x18);
a61af66fc99e Initial load
duke
parents:
diff changeset
864 emit_operand(rax, src); // 0, src
a61af66fc99e Initial load
duke
parents:
diff changeset
865 }
a61af66fc99e Initial load
duke
parents:
diff changeset
866
a61af66fc99e Initial load
duke
parents:
diff changeset
867
a61af66fc99e Initial load
duke
parents:
diff changeset
868 void Assembler::prefetchw(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 assert(VM_Version::supports_3dnow(), "must support");
a61af66fc99e Initial load
duke
parents:
diff changeset
870 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
871 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
872 emit_byte(0x0D);
a61af66fc99e Initial load
duke
parents:
diff changeset
873 emit_operand(rcx, src); // 1, src
a61af66fc99e Initial load
duke
parents:
diff changeset
874 }
a61af66fc99e Initial load
duke
parents:
diff changeset
875
a61af66fc99e Initial load
duke
parents:
diff changeset
876
a61af66fc99e Initial load
duke
parents:
diff changeset
877 void Assembler::prefetchr(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
878 assert(VM_Version::supports_3dnow(), "must support");
a61af66fc99e Initial load
duke
parents:
diff changeset
879 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
880 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
881 emit_byte(0x0D);
a61af66fc99e Initial load
duke
parents:
diff changeset
882 emit_operand(rax, src); // 0, src
a61af66fc99e Initial load
duke
parents:
diff changeset
883 }
a61af66fc99e Initial load
duke
parents:
diff changeset
884
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 void Assembler::adcl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
887 emit_arith(0x81, 0xD0, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
888 }
a61af66fc99e Initial load
duke
parents:
diff changeset
889
a61af66fc99e Initial load
duke
parents:
diff changeset
890
a61af66fc99e Initial load
duke
parents:
diff changeset
891 void Assembler::adcl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
892 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
893 emit_byte(0x13);
a61af66fc99e Initial load
duke
parents:
diff changeset
894 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
895 }
a61af66fc99e Initial load
duke
parents:
diff changeset
896
a61af66fc99e Initial load
duke
parents:
diff changeset
897
a61af66fc99e Initial load
duke
parents:
diff changeset
898 void Assembler::adcl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
899 emit_arith(0x13, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
900 }
a61af66fc99e Initial load
duke
parents:
diff changeset
901
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903 void Assembler::addl(Address dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
904 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
905 emit_arith_operand(0x81,rax,dst,imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
906 }
a61af66fc99e Initial load
duke
parents:
diff changeset
907
a61af66fc99e Initial load
duke
parents:
diff changeset
908
a61af66fc99e Initial load
duke
parents:
diff changeset
909 void Assembler::addl(Address dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
910 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
911 emit_byte(0x01);
a61af66fc99e Initial load
duke
parents:
diff changeset
912 emit_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
913 }
a61af66fc99e Initial load
duke
parents:
diff changeset
914
a61af66fc99e Initial load
duke
parents:
diff changeset
915
a61af66fc99e Initial load
duke
parents:
diff changeset
916 void Assembler::addl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
917 emit_arith(0x81, 0xC0, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
918 }
a61af66fc99e Initial load
duke
parents:
diff changeset
919
a61af66fc99e Initial load
duke
parents:
diff changeset
920
a61af66fc99e Initial load
duke
parents:
diff changeset
921 void Assembler::addl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
922 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
923 emit_byte(0x03);
a61af66fc99e Initial load
duke
parents:
diff changeset
924 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
925 }
a61af66fc99e Initial load
duke
parents:
diff changeset
926
a61af66fc99e Initial load
duke
parents:
diff changeset
927
a61af66fc99e Initial load
duke
parents:
diff changeset
928 void Assembler::addl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
929 emit_arith(0x03, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
930 }
a61af66fc99e Initial load
duke
parents:
diff changeset
931
a61af66fc99e Initial load
duke
parents:
diff changeset
932
a61af66fc99e Initial load
duke
parents:
diff changeset
933 void Assembler::andl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
934 emit_arith(0x81, 0xE0, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
935 }
a61af66fc99e Initial load
duke
parents:
diff changeset
936
a61af66fc99e Initial load
duke
parents:
diff changeset
937
a61af66fc99e Initial load
duke
parents:
diff changeset
938 void Assembler::andl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
939 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
940 emit_byte(0x23);
a61af66fc99e Initial load
duke
parents:
diff changeset
941 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
942 }
a61af66fc99e Initial load
duke
parents:
diff changeset
943
a61af66fc99e Initial load
duke
parents:
diff changeset
944
a61af66fc99e Initial load
duke
parents:
diff changeset
945 void Assembler::andl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
946 emit_arith(0x23, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
948
a61af66fc99e Initial load
duke
parents:
diff changeset
949
a61af66fc99e Initial load
duke
parents:
diff changeset
950 void Assembler::cmpb(Address dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
951 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
952 emit_byte(0x80);
a61af66fc99e Initial load
duke
parents:
diff changeset
953 emit_operand(rdi, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
954 emit_byte(imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
955 }
a61af66fc99e Initial load
duke
parents:
diff changeset
956
a61af66fc99e Initial load
duke
parents:
diff changeset
957 void Assembler::cmpw(Address dst, int imm16) {
a61af66fc99e Initial load
duke
parents:
diff changeset
958 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
959 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
960 emit_byte(0x81);
a61af66fc99e Initial load
duke
parents:
diff changeset
961 emit_operand(rdi, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
962 emit_word(imm16);
a61af66fc99e Initial load
duke
parents:
diff changeset
963 }
a61af66fc99e Initial load
duke
parents:
diff changeset
964
a61af66fc99e Initial load
duke
parents:
diff changeset
965 void Assembler::cmpl(Address dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
966 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
967 emit_byte(0x81);
a61af66fc99e Initial load
duke
parents:
diff changeset
968 emit_operand(rdi, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
969 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
970 }
a61af66fc99e Initial load
duke
parents:
diff changeset
971
a61af66fc99e Initial load
duke
parents:
diff changeset
972 #ifndef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
973 void Assembler::cmp_literal32(Register src1, int32_t imm32, RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
974 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
975 emit_byte(0x81);
a61af66fc99e Initial load
duke
parents:
diff changeset
976 emit_byte(0xF8 | src1->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
977 emit_data(imm32, rspec, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
978 }
a61af66fc99e Initial load
duke
parents:
diff changeset
979
a61af66fc99e Initial load
duke
parents:
diff changeset
980 void Assembler::cmp_literal32(Address src1, int32_t imm32, RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
981 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
982 emit_byte(0x81);
a61af66fc99e Initial load
duke
parents:
diff changeset
983 emit_operand(rdi, src1);
a61af66fc99e Initial load
duke
parents:
diff changeset
984 emit_data(imm32, rspec, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
985 }
a61af66fc99e Initial load
duke
parents:
diff changeset
986 #endif // _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
987
a61af66fc99e Initial load
duke
parents:
diff changeset
988
a61af66fc99e Initial load
duke
parents:
diff changeset
989 void Assembler::cmpl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 emit_arith(0x81, 0xF8, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
991 }
a61af66fc99e Initial load
duke
parents:
diff changeset
992
a61af66fc99e Initial load
duke
parents:
diff changeset
993
a61af66fc99e Initial load
duke
parents:
diff changeset
994 void Assembler::cmpl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
995 emit_arith(0x3B, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
996 }
a61af66fc99e Initial load
duke
parents:
diff changeset
997
a61af66fc99e Initial load
duke
parents:
diff changeset
998
a61af66fc99e Initial load
duke
parents:
diff changeset
999 void Assembler::cmpl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 emit_byte(0x3B);
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1004
a61af66fc99e Initial load
duke
parents:
diff changeset
1005
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 void Assembler::decl(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 // Don't use it directly. Use MacroAssembler::decrement() instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 emit_byte(0x48 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 void Assembler::decl(Address dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 // Don't use it directly. Use MacroAssembler::decrement() instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 emit_operand(rcx, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1018
a61af66fc99e Initial load
duke
parents:
diff changeset
1019
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 void Assembler::idivl(Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 emit_byte(0xF7);
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 emit_byte(0xF8 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1024
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 void Assembler::cdql() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 emit_byte(0x99);
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1029
a61af66fc99e Initial load
duke
parents:
diff changeset
1030
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 void Assembler::imull(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 emit_byte(0xAF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1036
a61af66fc99e Initial load
duke
parents:
diff changeset
1037
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 void Assembler::imull(Register dst, Register src, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 if (is8bit(value)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 emit_byte(0x6B);
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 emit_byte(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 emit_byte(0x69);
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 emit_long(value);
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1049
a61af66fc99e Initial load
duke
parents:
diff changeset
1050
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 void Assembler::incl(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 // Don't use it directly. Use MacroAssembler::increment() instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 emit_byte(0x40 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1055
a61af66fc99e Initial load
duke
parents:
diff changeset
1056
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 void Assembler::incl(Address dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 // Don't use it directly. Use MacroAssembler::increment() instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 emit_operand(rax, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1063
a61af66fc99e Initial load
duke
parents:
diff changeset
1064
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 void Assembler::leal(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 emit_byte(0x8D);
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1070
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 void Assembler::mull(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 emit_byte(0xF7);
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 emit_operand(rsp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1076
a61af66fc99e Initial load
duke
parents:
diff changeset
1077
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 void Assembler::mull(Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 emit_byte(0xF7);
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 emit_byte(0xE0 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1082
a61af66fc99e Initial load
duke
parents:
diff changeset
1083
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 void Assembler::negl(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 emit_byte(0xF7);
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 emit_byte(0xD8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1088
a61af66fc99e Initial load
duke
parents:
diff changeset
1089
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 void Assembler::notl(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 emit_byte(0xF7);
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 emit_byte(0xD0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1094
a61af66fc99e Initial load
duke
parents:
diff changeset
1095
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 void Assembler::orl(Address dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 emit_byte(0x81);
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 emit_operand(rcx, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1102
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 void Assembler::orl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 emit_arith(0x81, 0xC8, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1106
a61af66fc99e Initial load
duke
parents:
diff changeset
1107
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 void Assembler::orl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 emit_byte(0x0B);
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1113
a61af66fc99e Initial load
duke
parents:
diff changeset
1114
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 void Assembler::orl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 emit_arith(0x0B, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1118
a61af66fc99e Initial load
duke
parents:
diff changeset
1119
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 void Assembler::rcll(Register dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 assert(isShiftCount(imm8), "illegal shift count");
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 if (imm8 == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 emit_byte(0xD1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 emit_byte(0xD0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 emit_byte(0xC1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 emit_byte(0xD0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 emit_byte(imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131
a61af66fc99e Initial load
duke
parents:
diff changeset
1132
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 void Assembler::sarl(Register dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 assert(isShiftCount(imm8), "illegal shift count");
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 if (imm8 == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 emit_byte(0xD1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 emit_byte(0xF8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 emit_byte(0xC1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 emit_byte(0xF8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 emit_byte(imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1144
a61af66fc99e Initial load
duke
parents:
diff changeset
1145
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 void Assembler::sarl(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 emit_byte(0xD3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 emit_byte(0xF8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1150
a61af66fc99e Initial load
duke
parents:
diff changeset
1151
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 void Assembler::sbbl(Address dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 emit_arith_operand(0x81,rbx,dst,imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1156
a61af66fc99e Initial load
duke
parents:
diff changeset
1157
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 void Assembler::sbbl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 emit_arith(0x81, 0xD8, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1161
a61af66fc99e Initial load
duke
parents:
diff changeset
1162
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 void Assembler::sbbl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 emit_byte(0x1B);
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1168
a61af66fc99e Initial load
duke
parents:
diff changeset
1169
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 void Assembler::sbbl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 emit_arith(0x1B, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1173
a61af66fc99e Initial load
duke
parents:
diff changeset
1174
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 void Assembler::shldl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 emit_byte(0xA5);
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 emit_byte(0xC0 | src->encoding() << 3 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1180
a61af66fc99e Initial load
duke
parents:
diff changeset
1181
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 void Assembler::shll(Register dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 assert(isShiftCount(imm8), "illegal shift count");
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 if (imm8 == 1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 emit_byte(0xD1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 emit_byte(0xE0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 emit_byte(0xC1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 emit_byte(0xE0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 emit_byte(imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1193
a61af66fc99e Initial load
duke
parents:
diff changeset
1194
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 void Assembler::shll(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 emit_byte(0xD3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 emit_byte(0xE0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1199
a61af66fc99e Initial load
duke
parents:
diff changeset
1200
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 void Assembler::shrdl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 emit_byte(0xAD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 emit_byte(0xC0 | src->encoding() << 3 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1206
a61af66fc99e Initial load
duke
parents:
diff changeset
1207
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 void Assembler::shrl(Register dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 assert(isShiftCount(imm8), "illegal shift count");
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 emit_byte(0xC1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 emit_byte(0xE8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 emit_byte(imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1214
a61af66fc99e Initial load
duke
parents:
diff changeset
1215
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 void Assembler::shrl(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 emit_byte(0xD3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 emit_byte(0xE8 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1220
a61af66fc99e Initial load
duke
parents:
diff changeset
1221
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 void Assembler::subl(Address dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 if (is8bit(imm32)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 emit_byte(0x83);
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 emit_operand(rbp, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 emit_byte(imm32 & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 emit_byte(0x81);
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 emit_operand(rbp, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1235
a61af66fc99e Initial load
duke
parents:
diff changeset
1236
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 void Assembler::subl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 emit_arith(0x81, 0xE8, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1240
a61af66fc99e Initial load
duke
parents:
diff changeset
1241
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 void Assembler::subl(Address dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 emit_byte(0x29);
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 emit_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1247
a61af66fc99e Initial load
duke
parents:
diff changeset
1248
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 void Assembler::subl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 emit_byte(0x2B);
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1254
a61af66fc99e Initial load
duke
parents:
diff changeset
1255
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 void Assembler::subl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 emit_arith(0x2B, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1259
a61af66fc99e Initial load
duke
parents:
diff changeset
1260
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 void Assembler::testb(Register dst, int imm8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 assert(dst->has_byte_register(), "must have byte register");
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 emit_arith_b(0xF6, 0xC0, dst, imm8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1265
a61af66fc99e Initial load
duke
parents:
diff changeset
1266
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 void Assembler::testl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 // not using emit_arith because test
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 // doesn't support sign-extension of
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 // 8bit operands
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 if (dst->encoding() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 emit_byte(0xA9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 emit_byte(0xF7);
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 emit_byte(0xC0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 emit_long(imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1279
a61af66fc99e Initial load
duke
parents:
diff changeset
1280
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 void Assembler::testl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 emit_arith(0x85, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1284
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 void Assembler::testl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 emit_byte(0x85);
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1290
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 void Assembler::xaddl(Address dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 emit_byte(0xC1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 emit_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1297
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 void Assembler::xorl(Register dst, int imm32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 emit_arith(0x81, 0xF0, dst, imm32);
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1301
a61af66fc99e Initial load
duke
parents:
diff changeset
1302
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 void Assembler::xorl(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 emit_byte(0x33);
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 emit_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1308
a61af66fc99e Initial load
duke
parents:
diff changeset
1309
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 void Assembler::xorl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 emit_arith(0x33, 0xC0, dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1313
a61af66fc99e Initial load
duke
parents:
diff changeset
1314
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 void Assembler::bswap(Register reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 emit_byte(0xC8 | reg->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1319
a61af66fc99e Initial load
duke
parents:
diff changeset
1320
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 void Assembler::lock() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 if (Atomics & 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 // Emit either nothing, a NOP, or a NOP: prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 emit_byte(0x90) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 emit_byte(0xF0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1329
a61af66fc99e Initial load
duke
parents:
diff changeset
1330
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 void Assembler::xchg(Register reg, Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 emit_byte(0x87);
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 emit_operand(reg, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1336
a61af66fc99e Initial load
duke
parents:
diff changeset
1337
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 void Assembler::xchgl(Register dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 emit_byte(0x87);
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 emit_byte(0xc0 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1342
a61af66fc99e Initial load
duke
parents:
diff changeset
1343
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 // The 32-bit cmpxchg compares the value at adr with the contents of rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 // and stores reg into adr if so; otherwise, the value at adr is loaded into rax,.
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 // The ZF is set if the compared values were equal, and cleared otherwise.
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 void Assembler::cmpxchg(Register reg, Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 if (Atomics & 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 // caveat: no instructionmark, so this isn't relocatable.
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 // Emit a synthetic, non-atomic, CAS equivalent.
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 // Beware. The synthetic form sets all ICCs, not just ZF.
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 // cmpxchg r,[m] is equivalent to rax, = CAS (m, rax, r)
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 cmpl (rax, adr) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 movl (rax, adr) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 if (reg != rax) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 Label L ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 jcc (Assembler::notEqual, L) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 movl (adr, reg) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 bind (L) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 emit_byte(0xB1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 emit_operand(reg, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1368
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 // The 64-bit cmpxchg compares the value at adr with the contents of rdx:rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 // and stores rcx:rbx into adr if so; otherwise, the value at adr is loaded
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 // into rdx:rax. The ZF is set if the compared values were equal, and cleared otherwise.
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 void Assembler::cmpxchg8(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 emit_byte(0xc7);
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 emit_operand(rcx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1378
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 void Assembler::hlt() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 emit_byte(0xF4);
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1382
a61af66fc99e Initial load
duke
parents:
diff changeset
1383
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 void Assembler::addr_nop_4() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 // 4 bytes: NOP DWORD PTR [EAX+0]
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 emit_byte(0x1F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 emit_byte(0x40); // emit_rm(cbuf, 0x1, EAX_enc, EAX_enc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 emit_byte(0); // 8-bits offset (1 byte)
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1391
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 void Assembler::addr_nop_5() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 // 5 bytes: NOP DWORD PTR [EAX+EAX*0+0] 8-bits offset
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 emit_byte(0x1F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 emit_byte(0x44); // emit_rm(cbuf, 0x1, EAX_enc, 0x4);
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 emit_byte(0x00); // emit_rm(cbuf, 0x0, EAX_enc, EAX_enc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 emit_byte(0); // 8-bits offset (1 byte)
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1400
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 void Assembler::addr_nop_7() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 // 7 bytes: NOP DWORD PTR [EAX+0] 32-bits offset
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 emit_byte(0x1F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 emit_byte(0x80); // emit_rm(cbuf, 0x2, EAX_enc, EAX_enc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 emit_long(0); // 32-bits offset (4 bytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1408
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 void Assembler::addr_nop_8() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 // 8 bytes: NOP DWORD PTR [EAX+EAX*0+0] 32-bits offset
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 emit_byte(0x1F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 emit_byte(0x84); // emit_rm(cbuf, 0x2, EAX_enc, 0x4);
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 emit_byte(0x00); // emit_rm(cbuf, 0x0, EAX_enc, EAX_enc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 emit_long(0); // 32-bits offset (4 bytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1417
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 void Assembler::nop(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 assert(i > 0, " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 if (UseAddressNop && VM_Version::is_intel()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 // Using multi-bytes nops "0x0F 0x1F [address]" for Intel
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 // 1: 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 // 2: 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 // 3: 0x66 0x66 0x90 (don't use "0x0F 0x1F 0x00" - need patching safe padding)
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 // 4: 0x0F 0x1F 0x40 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 // 5: 0x0F 0x1F 0x44 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 // 6: 0x66 0x0F 0x1F 0x44 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 // 7: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 // 8: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 // 9: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 // 10: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 // 11: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1434
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 // The rest coding is Intel specific - don't use consecutive address nops
a61af66fc99e Initial load
duke
parents:
diff changeset
1436
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 // 12: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 // 13: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 // 14: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 // 15: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x66 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1441
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 while(i >= 15) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 // For Intel don't generate consecutive addess nops (mix with regular nops)
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 i -= 15;
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 addr_nop_8();
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 emit_byte(0x90); // nop
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 switch (i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 case 14:
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 case 13:
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 case 12:
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 addr_nop_8();
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 emit_byte(0x90); // nop
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 case 11:
a61af66fc99e Initial load
duke
parents:
diff changeset
1467 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 case 10:
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 case 9:
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 case 8:
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 addr_nop_8();
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 case 7:
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 addr_nop_7();
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 case 6:
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 case 5:
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 addr_nop_5();
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 case 4:
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 addr_nop_4();
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 // Don't use "0x0F 0x1F 0x00" - need patching safe padding
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 emit_byte(0x90); // nop
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 assert(i == 0, " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 if (UseAddressNop && VM_Version::is_amd()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 // Using multi-bytes nops "0x0F 0x1F [address]" for AMD.
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 // 1: 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 // 2: 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 // 3: 0x66 0x66 0x90 (don't use "0x0F 0x1F 0x00" - need patching safe padding)
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 // 4: 0x0F 0x1F 0x40 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 // 5: 0x0F 0x1F 0x44 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 // 6: 0x66 0x0F 0x1F 0x44 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 // 7: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 // 8: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 // 9: 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 // 10: 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 // 11: 0x66 0x66 0x66 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1513
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 // The rest coding is AMD specific - use consecutive address nops
a61af66fc99e Initial load
duke
parents:
diff changeset
1515
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 // 12: 0x66 0x0F 0x1F 0x44 0x00 0x00 0x66 0x0F 0x1F 0x44 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 // 13: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00 0x66 0x0F 0x1F 0x44 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 // 14: 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 // 15: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x0F 0x1F 0x80 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 // 16: 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00 0x0F 0x1F 0x84 0x00 0x00 0x00 0x00 0x00
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 // Size prefixes (0x66) are added for larger sizes
a61af66fc99e Initial load
duke
parents:
diff changeset
1522
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 while(i >= 22) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 i -= 11;
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 addr_nop_8();
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 // Generate first nop for size between 21-12
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 switch (i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 case 21:
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 i -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 case 20:
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 case 19:
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 i -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1539 case 18:
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 case 17:
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 i -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 case 16:
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 case 15:
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 i -= 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 addr_nop_8();
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 case 14:
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 case 13:
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 i -= 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 addr_nop_7();
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1553 case 12:
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 i -= 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
1555 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1556 addr_nop_5();
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 assert(i < 12, " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1561
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 // Generate second nop for size between 11-1
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 switch (i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1564 case 11:
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 case 10:
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 case 9:
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 case 8:
a61af66fc99e Initial load
duke
parents:
diff changeset
1571 addr_nop_8();
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1573 case 7:
a61af66fc99e Initial load
duke
parents:
diff changeset
1574 addr_nop_7();
a61af66fc99e Initial load
duke
parents:
diff changeset
1575 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 case 6:
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1578 case 5:
a61af66fc99e Initial load
duke
parents:
diff changeset
1579 addr_nop_5();
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 case 4:
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 addr_nop_4();
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 // Don't use "0x0F 0x1F 0x00" - need patching safe padding
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1587 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 emit_byte(0x90); // nop
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 assert(i == 0, " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1595 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1597
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 // Using nops with size prefixes "0x66 0x90".
a61af66fc99e Initial load
duke
parents:
diff changeset
1599 // From AMD Optimization Guide:
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 // 1: 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 // 2: 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 // 3: 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 // 4: 0x66 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 // 5: 0x66 0x66 0x90 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 // 6: 0x66 0x66 0x90 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1606 // 7: 0x66 0x66 0x66 0x90 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 // 8: 0x66 0x66 0x66 0x90 0x66 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 // 9: 0x66 0x66 0x90 0x66 0x66 0x90 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 // 10: 0x66 0x66 0x66 0x90 0x66 0x66 0x90 0x66 0x66 0x90
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 while(i > 12) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 i -= 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
1613 emit_byte(0x66); // size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 emit_byte(0x90); // nop
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 // 1 - 12 nops
a61af66fc99e Initial load
duke
parents:
diff changeset
1619 if(i > 8) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 if(i > 9) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 i -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1624 i -= 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1626 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 emit_byte(0x90);
a61af66fc99e Initial load
duke
parents:
diff changeset
1628 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 // 1 - 8 nops
a61af66fc99e Initial load
duke
parents:
diff changeset
1630 if(i > 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 if(i > 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1632 i -= 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 i -= 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 emit_byte(0x90);
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 switch (i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1641 case 4:
a61af66fc99e Initial load
duke
parents:
diff changeset
1642 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 case 3:
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1645 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 emit_byte(0x90);
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 assert(i == 0, " ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1654
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 void Assembler::ret(int imm16) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 if (imm16 == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 emit_byte(0xC3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 emit_byte(0xC2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 emit_word(imm16);
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1663
a61af66fc99e Initial load
duke
parents:
diff changeset
1664
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 void Assembler::set_byte_if_not_zero(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 emit_byte(0x95);
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 emit_byte(0xE0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1670
a61af66fc99e Initial load
duke
parents:
diff changeset
1671
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 // copies a single word from [esi] to [edi]
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 void Assembler::smovl() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 emit_byte(0xA5);
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1676
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 // copies data from [esi] to [edi] using rcx double words (m32)
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 void Assembler::rep_movl() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 emit_byte(0xF3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1680 emit_byte(0xA5);
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1682
a61af66fc99e Initial load
duke
parents:
diff changeset
1683
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 // sets rcx double words (m32) with rax, value at [edi]
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 void Assembler::rep_set() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 emit_byte(0xF3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 emit_byte(0xAB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1689
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 // scans rcx double words (m32) at [edi] for occurance of rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 void Assembler::repne_scan() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 emit_byte(0xF2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 emit_byte(0xAF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1695
a61af66fc99e Initial load
duke
parents:
diff changeset
1696
a61af66fc99e Initial load
duke
parents:
diff changeset
1697 void Assembler::setb(Condition cc, Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 assert(0 <= cc && cc < 16, "illegal cc");
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 emit_byte(0x90 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 emit_byte(0xC0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1703
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 void Assembler::cld() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 emit_byte(0xfc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1707
a61af66fc99e Initial load
duke
parents:
diff changeset
1708 void Assembler::std() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 emit_byte(0xfd);
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1711
a61af66fc99e Initial load
duke
parents:
diff changeset
1712 void Assembler::emit_raw (unsigned char b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1713 emit_byte (b) ;
a61af66fc99e Initial load
duke
parents:
diff changeset
1714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1715
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 // Serializes memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 void Assembler::membar() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 // Memory barriers are only needed on multiprocessors
a61af66fc99e Initial load
duke
parents:
diff changeset
1719 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 if( VM_Version::supports_sse2() ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1721 emit_byte( 0x0F ); // MFENCE; faster blows no regs
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 emit_byte( 0xAE );
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 emit_byte( 0xF0 );
a61af66fc99e Initial load
duke
parents:
diff changeset
1724 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 // All usable chips support "locked" instructions which suffice
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 // as barriers, and are much faster than the alternative of
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 // using cpuid instruction. We use here a locked add [esp],0.
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 // This is conveniently otherwise a no-op except for blowing
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 // flags (which we save and restore.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 pushfd(); // Save eflags register
a61af66fc99e Initial load
duke
parents:
diff changeset
1731 lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 addl(Address(rsp, 0), 0);// Assert the lock# signal here
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 popfd(); // Restore eflags register
a61af66fc99e Initial load
duke
parents:
diff changeset
1734 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1735 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1736 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1737
a61af66fc99e Initial load
duke
parents:
diff changeset
1738 // Identify processor type and features
a61af66fc99e Initial load
duke
parents:
diff changeset
1739 void Assembler::cpuid() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1740 // Note: we can't assert VM_Version::supports_cpuid() here
a61af66fc99e Initial load
duke
parents:
diff changeset
1741 // because this instruction is used in the processor
a61af66fc99e Initial load
duke
parents:
diff changeset
1742 // identification code.
a61af66fc99e Initial load
duke
parents:
diff changeset
1743 emit_byte( 0x0F );
a61af66fc99e Initial load
duke
parents:
diff changeset
1744 emit_byte( 0xA2 );
a61af66fc99e Initial load
duke
parents:
diff changeset
1745 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1746
a61af66fc99e Initial load
duke
parents:
diff changeset
1747 void Assembler::call(Label& L, relocInfo::relocType rtype) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1748 if (L.is_bound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1749 const int long_size = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
1750 int offs = target(L) - pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
1751 assert(offs <= 0, "assembler error");
a61af66fc99e Initial load
duke
parents:
diff changeset
1752 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1753 // 1110 1000 #32-bit disp
a61af66fc99e Initial load
duke
parents:
diff changeset
1754 emit_byte(0xE8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1755 emit_data(offs - long_size, rtype, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1756 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1757 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1758 // 1110 1000 #32-bit disp
a61af66fc99e Initial load
duke
parents:
diff changeset
1759 L.add_patch_at(code(), locator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 emit_byte(0xE8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1761 emit_data(int(0), rtype, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1762 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1764
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 void Assembler::call(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1766 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1767 emit_byte(0xD0 | dst->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1768 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1769
a61af66fc99e Initial load
duke
parents:
diff changeset
1770
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 void Assembler::call(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1772 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1773 relocInfo::relocType rtype = adr.reloc();
a61af66fc99e Initial load
duke
parents:
diff changeset
1774 if (rtype != relocInfo::runtime_call_type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1775 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 emit_operand(rdx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1777 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1778 assert(false, "ack");
a61af66fc99e Initial load
duke
parents:
diff changeset
1779 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1780
a61af66fc99e Initial load
duke
parents:
diff changeset
1781 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1782
a61af66fc99e Initial load
duke
parents:
diff changeset
1783 void Assembler::call_literal(address dest, RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1784 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1785 emit_byte(0xE8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1786 intptr_t disp = dest - (_code_pos + sizeof(int32_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
1787 assert(dest != NULL, "must have a target");
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 emit_data(disp, rspec, call32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
1789
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1791
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 void Assembler::jmp(Register entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1794 emit_byte(0xE0 | entry->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1796
a61af66fc99e Initial load
duke
parents:
diff changeset
1797
a61af66fc99e Initial load
duke
parents:
diff changeset
1798 void Assembler::jmp(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 emit_operand(rsp, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1803
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 void Assembler::jmp_literal(address dest, RelocationHolder const& rspec) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1805 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1806 emit_byte(0xE9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 assert(dest != NULL, "must have a target");
a61af66fc99e Initial load
duke
parents:
diff changeset
1808 intptr_t disp = dest - (_code_pos + sizeof(int32_t));
a61af66fc99e Initial load
duke
parents:
diff changeset
1809 emit_data(disp, rspec.reloc(), call32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1811
a61af66fc99e Initial load
duke
parents:
diff changeset
1812 void Assembler::jmp(Label& L, relocInfo::relocType rtype) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1813 if (L.is_bound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1814 address entry = target(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
1815 assert(entry != NULL, "jmp most probably wrong");
a61af66fc99e Initial load
duke
parents:
diff changeset
1816 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1817 const int short_size = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1818 const int long_size = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
1819 intptr_t offs = entry - _code_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
1820 if (rtype == relocInfo::none && is8bit(offs - short_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1821 emit_byte(0xEB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1822 emit_byte((offs - short_size) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1823 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1824 emit_byte(0xE9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1825 emit_long(offs - long_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1826 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1827 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1828 // By default, forward jumps are always 32-bit displacements, since
a61af66fc99e Initial load
duke
parents:
diff changeset
1829 // we can't yet know where the label will be bound. If you're sure that
a61af66fc99e Initial load
duke
parents:
diff changeset
1830 // the forward jump will not run beyond 256 bytes, use jmpb to
a61af66fc99e Initial load
duke
parents:
diff changeset
1831 // force an 8-bit displacement.
a61af66fc99e Initial load
duke
parents:
diff changeset
1832 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1833 relocate(rtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
1834 L.add_patch_at(code(), locator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1835 emit_byte(0xE9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1836 emit_long(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1838 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1839
a61af66fc99e Initial load
duke
parents:
diff changeset
1840 void Assembler::jmpb(Label& L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1841 if (L.is_bound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1842 const int short_size = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1843 address entry = target(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
1844 assert(is8bit((entry - _code_pos) + short_size),
a61af66fc99e Initial load
duke
parents:
diff changeset
1845 "Dispacement too large for a short jmp");
a61af66fc99e Initial load
duke
parents:
diff changeset
1846 assert(entry != NULL, "jmp most probably wrong");
a61af66fc99e Initial load
duke
parents:
diff changeset
1847 intptr_t offs = entry - _code_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
1848 emit_byte(0xEB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1849 emit_byte((offs - short_size) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1850 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1851 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1852 L.add_patch_at(code(), locator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1853 emit_byte(0xEB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1854 emit_byte(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1856 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1857
a61af66fc99e Initial load
duke
parents:
diff changeset
1858 void Assembler::jcc(Condition cc, Label& L, relocInfo::relocType rtype) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1859 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1860 relocate(rtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
1861 assert((0 <= cc) && (cc < 16), "illegal cc");
a61af66fc99e Initial load
duke
parents:
diff changeset
1862 if (L.is_bound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1863 address dst = target(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
1864 assert(dst != NULL, "jcc most probably wrong");
a61af66fc99e Initial load
duke
parents:
diff changeset
1865
a61af66fc99e Initial load
duke
parents:
diff changeset
1866 const int short_size = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1867 const int long_size = 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
1868 int offs = (int)dst - ((int)_code_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
1869 if (rtype == relocInfo::none && is8bit(offs - short_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1870 // 0111 tttn #8-bit disp
a61af66fc99e Initial load
duke
parents:
diff changeset
1871 emit_byte(0x70 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1872 emit_byte((offs - short_size) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1873 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1874 // 0000 1111 1000 tttn #32-bit disp
a61af66fc99e Initial load
duke
parents:
diff changeset
1875 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1876 emit_byte(0x80 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1877 emit_long(offs - long_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
1878 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1879 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1880 // Note: could eliminate cond. jumps to this jump if condition
a61af66fc99e Initial load
duke
parents:
diff changeset
1881 // is the same however, seems to be rather unlikely case.
a61af66fc99e Initial load
duke
parents:
diff changeset
1882 // Note: use jccb() if label to be bound is very close to get
a61af66fc99e Initial load
duke
parents:
diff changeset
1883 // an 8-bit displacement
a61af66fc99e Initial load
duke
parents:
diff changeset
1884 L.add_patch_at(code(), locator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1885 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
1886 emit_byte(0x80 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1887 emit_long(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1888 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1890
a61af66fc99e Initial load
duke
parents:
diff changeset
1891 void Assembler::jccb(Condition cc, Label& L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1892 if (L.is_bound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1893 const int short_size = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1894 address entry = target(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
1895 assert(is8bit((intptr_t)entry - ((intptr_t)_code_pos + short_size)),
a61af66fc99e Initial load
duke
parents:
diff changeset
1896 "Dispacement too large for a short jmp");
a61af66fc99e Initial load
duke
parents:
diff changeset
1897 intptr_t offs = (intptr_t)entry - (intptr_t)_code_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
1898 // 0111 tttn #8-bit disp
a61af66fc99e Initial load
duke
parents:
diff changeset
1899 emit_byte(0x70 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1900 emit_byte((offs - short_size) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1901 jcc(cc, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
1902 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1903 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1904 L.add_patch_at(code(), locator());
a61af66fc99e Initial load
duke
parents:
diff changeset
1905 emit_byte(0x70 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
1906 emit_byte(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1907 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1908 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1909
a61af66fc99e Initial load
duke
parents:
diff changeset
1910 // FPU instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
1911
a61af66fc99e Initial load
duke
parents:
diff changeset
1912 void Assembler::fld1() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1913 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1914 emit_byte(0xE8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1915 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1916
a61af66fc99e Initial load
duke
parents:
diff changeset
1917
a61af66fc99e Initial load
duke
parents:
diff changeset
1918 void Assembler::fldz() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1919 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1920 emit_byte(0xEE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1921 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1922
a61af66fc99e Initial load
duke
parents:
diff changeset
1923
a61af66fc99e Initial load
duke
parents:
diff changeset
1924 void Assembler::fld_s(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1925 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1926 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1927 emit_operand(rax, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1928 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1929
a61af66fc99e Initial load
duke
parents:
diff changeset
1930
a61af66fc99e Initial load
duke
parents:
diff changeset
1931 void Assembler::fld_s (int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1932 emit_farith(0xD9, 0xC0, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
1933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1934
a61af66fc99e Initial load
duke
parents:
diff changeset
1935
a61af66fc99e Initial load
duke
parents:
diff changeset
1936 void Assembler::fld_d(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1937 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1938 emit_byte(0xDD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1939 emit_operand(rax, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1941
a61af66fc99e Initial load
duke
parents:
diff changeset
1942
a61af66fc99e Initial load
duke
parents:
diff changeset
1943 void Assembler::fld_x(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1944 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1945 emit_byte(0xDB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1946 emit_operand(rbp, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1948
a61af66fc99e Initial load
duke
parents:
diff changeset
1949
a61af66fc99e Initial load
duke
parents:
diff changeset
1950 void Assembler::fst_s(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1951 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1952 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1953 emit_operand(rdx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1954 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1955
a61af66fc99e Initial load
duke
parents:
diff changeset
1956
a61af66fc99e Initial load
duke
parents:
diff changeset
1957 void Assembler::fst_d(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1958 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1959 emit_byte(0xDD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1960 emit_operand(rdx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1961 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1962
a61af66fc99e Initial load
duke
parents:
diff changeset
1963
a61af66fc99e Initial load
duke
parents:
diff changeset
1964 void Assembler::fstp_s(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1965 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1966 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
1967 emit_operand(rbx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1969
a61af66fc99e Initial load
duke
parents:
diff changeset
1970
a61af66fc99e Initial load
duke
parents:
diff changeset
1971 void Assembler::fstp_d(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1972 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1973 emit_byte(0xDD);
a61af66fc99e Initial load
duke
parents:
diff changeset
1974 emit_operand(rbx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1975 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1976
a61af66fc99e Initial load
duke
parents:
diff changeset
1977
a61af66fc99e Initial load
duke
parents:
diff changeset
1978 void Assembler::fstp_x(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1979 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1980 emit_byte(0xDB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1981 emit_operand(rdi, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1983
a61af66fc99e Initial load
duke
parents:
diff changeset
1984
a61af66fc99e Initial load
duke
parents:
diff changeset
1985 void Assembler::fstp_d(int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1986 emit_farith(0xDD, 0xD8, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
1987 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1988
a61af66fc99e Initial load
duke
parents:
diff changeset
1989
a61af66fc99e Initial load
duke
parents:
diff changeset
1990 void Assembler::fild_s(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1991 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1992 emit_byte(0xDB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1993 emit_operand(rax, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
1994 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1995
a61af66fc99e Initial load
duke
parents:
diff changeset
1996
a61af66fc99e Initial load
duke
parents:
diff changeset
1997 void Assembler::fild_d(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1998 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
1999 emit_byte(0xDF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2000 emit_operand(rbp, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
2001 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2002
a61af66fc99e Initial load
duke
parents:
diff changeset
2003
a61af66fc99e Initial load
duke
parents:
diff changeset
2004 void Assembler::fistp_s(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2005 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2006 emit_byte(0xDB);
a61af66fc99e Initial load
duke
parents:
diff changeset
2007 emit_operand(rbx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
2008 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2009
a61af66fc99e Initial load
duke
parents:
diff changeset
2010
a61af66fc99e Initial load
duke
parents:
diff changeset
2011 void Assembler::fistp_d(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2012 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2013 emit_byte(0xDF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2014 emit_operand(rdi, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
2015 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2016
a61af66fc99e Initial load
duke
parents:
diff changeset
2017
a61af66fc99e Initial load
duke
parents:
diff changeset
2018 void Assembler::fist_s(Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2019 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2020 emit_byte(0xDB);
a61af66fc99e Initial load
duke
parents:
diff changeset
2021 emit_operand(rdx, adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
2022 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2023
a61af66fc99e Initial load
duke
parents:
diff changeset
2024
a61af66fc99e Initial load
duke
parents:
diff changeset
2025 void Assembler::fabs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2026 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2027 emit_byte(0xE1);
a61af66fc99e Initial load
duke
parents:
diff changeset
2028 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2029
a61af66fc99e Initial load
duke
parents:
diff changeset
2030
a61af66fc99e Initial load
duke
parents:
diff changeset
2031 void Assembler::fldln2() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2032 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2033 emit_byte(0xED);
a61af66fc99e Initial load
duke
parents:
diff changeset
2034 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2035
a61af66fc99e Initial load
duke
parents:
diff changeset
2036 void Assembler::fyl2x() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2037 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2038 emit_byte(0xF1);
a61af66fc99e Initial load
duke
parents:
diff changeset
2039 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2040
a61af66fc99e Initial load
duke
parents:
diff changeset
2041
a61af66fc99e Initial load
duke
parents:
diff changeset
2042 void Assembler::fldlg2() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2043 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2044 emit_byte(0xEC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2045 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2046
a61af66fc99e Initial load
duke
parents:
diff changeset
2047
a61af66fc99e Initial load
duke
parents:
diff changeset
2048 void Assembler::flog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2049 fldln2();
a61af66fc99e Initial load
duke
parents:
diff changeset
2050 fxch();
a61af66fc99e Initial load
duke
parents:
diff changeset
2051 fyl2x();
a61af66fc99e Initial load
duke
parents:
diff changeset
2052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2053
a61af66fc99e Initial load
duke
parents:
diff changeset
2054
a61af66fc99e Initial load
duke
parents:
diff changeset
2055 void Assembler::flog10() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2056 fldlg2();
a61af66fc99e Initial load
duke
parents:
diff changeset
2057 fxch();
a61af66fc99e Initial load
duke
parents:
diff changeset
2058 fyl2x();
a61af66fc99e Initial load
duke
parents:
diff changeset
2059 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2060
a61af66fc99e Initial load
duke
parents:
diff changeset
2061
a61af66fc99e Initial load
duke
parents:
diff changeset
2062 void Assembler::fsin() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2063 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2064 emit_byte(0xFE);
a61af66fc99e Initial load
duke
parents:
diff changeset
2065 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2066
a61af66fc99e Initial load
duke
parents:
diff changeset
2067
a61af66fc99e Initial load
duke
parents:
diff changeset
2068 void Assembler::fcos() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2069 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2070 emit_byte(0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2071 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2072
a61af66fc99e Initial load
duke
parents:
diff changeset
2073 void Assembler::ftan() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2074 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2075 emit_byte(0xF2);
a61af66fc99e Initial load
duke
parents:
diff changeset
2076 emit_byte(0xDD);
a61af66fc99e Initial load
duke
parents:
diff changeset
2077 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2078 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2079
a61af66fc99e Initial load
duke
parents:
diff changeset
2080 void Assembler::fsqrt() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2081 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2082 emit_byte(0xFA);
a61af66fc99e Initial load
duke
parents:
diff changeset
2083 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2084
a61af66fc99e Initial load
duke
parents:
diff changeset
2085
a61af66fc99e Initial load
duke
parents:
diff changeset
2086 void Assembler::fchs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2087 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2088 emit_byte(0xE0);
a61af66fc99e Initial load
duke
parents:
diff changeset
2089 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2090
a61af66fc99e Initial load
duke
parents:
diff changeset
2091
a61af66fc99e Initial load
duke
parents:
diff changeset
2092 void Assembler::fadd_s(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2093 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2094 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2095 emit_operand(rax, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2096 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2097
a61af66fc99e Initial load
duke
parents:
diff changeset
2098
a61af66fc99e Initial load
duke
parents:
diff changeset
2099 void Assembler::fadd_d(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2100 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2101 emit_byte(0xDC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2102 emit_operand(rax, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2104
a61af66fc99e Initial load
duke
parents:
diff changeset
2105
a61af66fc99e Initial load
duke
parents:
diff changeset
2106 void Assembler::fadd(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2107 emit_farith(0xD8, 0xC0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2109
a61af66fc99e Initial load
duke
parents:
diff changeset
2110
a61af66fc99e Initial load
duke
parents:
diff changeset
2111 void Assembler::fadda(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2112 emit_farith(0xDC, 0xC0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2114
a61af66fc99e Initial load
duke
parents:
diff changeset
2115
a61af66fc99e Initial load
duke
parents:
diff changeset
2116 void Assembler::fsub_d(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2117 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2118 emit_byte(0xDC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2119 emit_operand(rsp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2121
a61af66fc99e Initial load
duke
parents:
diff changeset
2122
a61af66fc99e Initial load
duke
parents:
diff changeset
2123 void Assembler::fsub_s(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2124 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2125 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2126 emit_operand(rsp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2128
a61af66fc99e Initial load
duke
parents:
diff changeset
2129
a61af66fc99e Initial load
duke
parents:
diff changeset
2130 void Assembler::fsubr_s(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2131 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2132 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2133 emit_operand(rbp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2135
a61af66fc99e Initial load
duke
parents:
diff changeset
2136
a61af66fc99e Initial load
duke
parents:
diff changeset
2137 void Assembler::fsubr_d(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2138 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2139 emit_byte(0xDC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2140 emit_operand(rbp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2142
a61af66fc99e Initial load
duke
parents:
diff changeset
2143
a61af66fc99e Initial load
duke
parents:
diff changeset
2144 void Assembler::fmul_s(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2145 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2146 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2147 emit_operand(rcx, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2149
a61af66fc99e Initial load
duke
parents:
diff changeset
2150
a61af66fc99e Initial load
duke
parents:
diff changeset
2151 void Assembler::fmul_d(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2152 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2153 emit_byte(0xDC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2154 emit_operand(rcx, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2156
a61af66fc99e Initial load
duke
parents:
diff changeset
2157
a61af66fc99e Initial load
duke
parents:
diff changeset
2158 void Assembler::fmul(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2159 emit_farith(0xD8, 0xC8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2161
a61af66fc99e Initial load
duke
parents:
diff changeset
2162
a61af66fc99e Initial load
duke
parents:
diff changeset
2163 void Assembler::fmula(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2164 emit_farith(0xDC, 0xC8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2166
a61af66fc99e Initial load
duke
parents:
diff changeset
2167
a61af66fc99e Initial load
duke
parents:
diff changeset
2168 void Assembler::fdiv_s(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2169 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2170 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2171 emit_operand(rsi, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2173
a61af66fc99e Initial load
duke
parents:
diff changeset
2174
a61af66fc99e Initial load
duke
parents:
diff changeset
2175 void Assembler::fdiv_d(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2176 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2177 emit_byte(0xDC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2178 emit_operand(rsi, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2180
a61af66fc99e Initial load
duke
parents:
diff changeset
2181
a61af66fc99e Initial load
duke
parents:
diff changeset
2182 void Assembler::fdivr_s(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2183 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2184 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2185 emit_operand(rdi, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2187
a61af66fc99e Initial load
duke
parents:
diff changeset
2188
a61af66fc99e Initial load
duke
parents:
diff changeset
2189 void Assembler::fdivr_d(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2190 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2191 emit_byte(0xDC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2192 emit_operand(rdi, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2194
a61af66fc99e Initial load
duke
parents:
diff changeset
2195
a61af66fc99e Initial load
duke
parents:
diff changeset
2196 void Assembler::fsub(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2197 emit_farith(0xD8, 0xE0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2199
a61af66fc99e Initial load
duke
parents:
diff changeset
2200
a61af66fc99e Initial load
duke
parents:
diff changeset
2201 void Assembler::fsuba(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2202 emit_farith(0xDC, 0xE8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2204
a61af66fc99e Initial load
duke
parents:
diff changeset
2205
a61af66fc99e Initial load
duke
parents:
diff changeset
2206 void Assembler::fsubr(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2207 emit_farith(0xD8, 0xE8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2209
a61af66fc99e Initial load
duke
parents:
diff changeset
2210
a61af66fc99e Initial load
duke
parents:
diff changeset
2211 void Assembler::fsubra(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2212 emit_farith(0xDC, 0xE0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2214
a61af66fc99e Initial load
duke
parents:
diff changeset
2215
a61af66fc99e Initial load
duke
parents:
diff changeset
2216 void Assembler::fdiv(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2217 emit_farith(0xD8, 0xF0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2219
a61af66fc99e Initial load
duke
parents:
diff changeset
2220
a61af66fc99e Initial load
duke
parents:
diff changeset
2221 void Assembler::fdiva(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2222 emit_farith(0xDC, 0xF8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2224
a61af66fc99e Initial load
duke
parents:
diff changeset
2225
a61af66fc99e Initial load
duke
parents:
diff changeset
2226 void Assembler::fdivr(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2227 emit_farith(0xD8, 0xF8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2229
a61af66fc99e Initial load
duke
parents:
diff changeset
2230
a61af66fc99e Initial load
duke
parents:
diff changeset
2231 void Assembler::fdivra(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2232 emit_farith(0xDC, 0xF0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2233 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2234
a61af66fc99e Initial load
duke
parents:
diff changeset
2235
a61af66fc99e Initial load
duke
parents:
diff changeset
2236 // Note: The Intel manual (Pentium Processor User's Manual, Vol.3, 1994)
a61af66fc99e Initial load
duke
parents:
diff changeset
2237 // is erroneous for some of the floating-point instructions below.
a61af66fc99e Initial load
duke
parents:
diff changeset
2238
a61af66fc99e Initial load
duke
parents:
diff changeset
2239 void Assembler::fdivp(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2240 emit_farith(0xDE, 0xF8, i); // ST(0) <- ST(0) / ST(1) and pop (Intel manual wrong)
a61af66fc99e Initial load
duke
parents:
diff changeset
2241 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2242
a61af66fc99e Initial load
duke
parents:
diff changeset
2243
a61af66fc99e Initial load
duke
parents:
diff changeset
2244 void Assembler::fdivrp(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2245 emit_farith(0xDE, 0xF0, i); // ST(0) <- ST(1) / ST(0) and pop (Intel manual wrong)
a61af66fc99e Initial load
duke
parents:
diff changeset
2246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2247
a61af66fc99e Initial load
duke
parents:
diff changeset
2248
a61af66fc99e Initial load
duke
parents:
diff changeset
2249 void Assembler::fsubp(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2250 emit_farith(0xDE, 0xE8, i); // ST(0) <- ST(0) - ST(1) and pop (Intel manual wrong)
a61af66fc99e Initial load
duke
parents:
diff changeset
2251 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2252
a61af66fc99e Initial load
duke
parents:
diff changeset
2253
a61af66fc99e Initial load
duke
parents:
diff changeset
2254 void Assembler::fsubrp(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2255 emit_farith(0xDE, 0xE0, i); // ST(0) <- ST(1) - ST(0) and pop (Intel manual wrong)
a61af66fc99e Initial load
duke
parents:
diff changeset
2256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2257
a61af66fc99e Initial load
duke
parents:
diff changeset
2258
a61af66fc99e Initial load
duke
parents:
diff changeset
2259 void Assembler::faddp(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2260 emit_farith(0xDE, 0xC0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2262
a61af66fc99e Initial load
duke
parents:
diff changeset
2263
a61af66fc99e Initial load
duke
parents:
diff changeset
2264 void Assembler::fmulp(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2265 emit_farith(0xDE, 0xC8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2267
a61af66fc99e Initial load
duke
parents:
diff changeset
2268
a61af66fc99e Initial load
duke
parents:
diff changeset
2269 void Assembler::fprem() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2270 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2271 emit_byte(0xF8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2273
a61af66fc99e Initial load
duke
parents:
diff changeset
2274
a61af66fc99e Initial load
duke
parents:
diff changeset
2275 void Assembler::fprem1() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2276 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2277 emit_byte(0xF5);
a61af66fc99e Initial load
duke
parents:
diff changeset
2278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2279
a61af66fc99e Initial load
duke
parents:
diff changeset
2280
a61af66fc99e Initial load
duke
parents:
diff changeset
2281 void Assembler::fxch(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2282 emit_farith(0xD9, 0xC8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2283 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2284
a61af66fc99e Initial load
duke
parents:
diff changeset
2285
a61af66fc99e Initial load
duke
parents:
diff changeset
2286 void Assembler::fincstp() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2287 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2288 emit_byte(0xF7);
a61af66fc99e Initial load
duke
parents:
diff changeset
2289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2290
a61af66fc99e Initial load
duke
parents:
diff changeset
2291
a61af66fc99e Initial load
duke
parents:
diff changeset
2292 void Assembler::fdecstp() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2293 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2294 emit_byte(0xF6);
a61af66fc99e Initial load
duke
parents:
diff changeset
2295 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2296
a61af66fc99e Initial load
duke
parents:
diff changeset
2297
a61af66fc99e Initial load
duke
parents:
diff changeset
2298 void Assembler::ffree(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2299 emit_farith(0xDD, 0xC0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2301
a61af66fc99e Initial load
duke
parents:
diff changeset
2302
a61af66fc99e Initial load
duke
parents:
diff changeset
2303 void Assembler::fcomp_s(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2304 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2305 emit_byte(0xD8);
a61af66fc99e Initial load
duke
parents:
diff changeset
2306 emit_operand(rbx, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2307 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2308
a61af66fc99e Initial load
duke
parents:
diff changeset
2309
a61af66fc99e Initial load
duke
parents:
diff changeset
2310 void Assembler::fcomp_d(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2311 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2312 emit_byte(0xDC);
a61af66fc99e Initial load
duke
parents:
diff changeset
2313 emit_operand(rbx, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2315
a61af66fc99e Initial load
duke
parents:
diff changeset
2316
a61af66fc99e Initial load
duke
parents:
diff changeset
2317 void Assembler::fcom(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2318 emit_farith(0xD8, 0xD0, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2319 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2320
a61af66fc99e Initial load
duke
parents:
diff changeset
2321
a61af66fc99e Initial load
duke
parents:
diff changeset
2322 void Assembler::fcomp(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2323 emit_farith(0xD8, 0xD8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2325
a61af66fc99e Initial load
duke
parents:
diff changeset
2326
a61af66fc99e Initial load
duke
parents:
diff changeset
2327 void Assembler::fcompp() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2328 emit_byte(0xDE);
a61af66fc99e Initial load
duke
parents:
diff changeset
2329 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2330 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2331
a61af66fc99e Initial load
duke
parents:
diff changeset
2332
a61af66fc99e Initial load
duke
parents:
diff changeset
2333 void Assembler::fucomi(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2334 // make sure the instruction is supported (introduced for P6, together with cmov)
a61af66fc99e Initial load
duke
parents:
diff changeset
2335 guarantee(VM_Version::supports_cmov(), "illegal instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
2336 emit_farith(0xDB, 0xE8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2338
a61af66fc99e Initial load
duke
parents:
diff changeset
2339
a61af66fc99e Initial load
duke
parents:
diff changeset
2340 void Assembler::fucomip(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2341 // make sure the instruction is supported (introduced for P6, together with cmov)
a61af66fc99e Initial load
duke
parents:
diff changeset
2342 guarantee(VM_Version::supports_cmov(), "illegal instruction");
a61af66fc99e Initial load
duke
parents:
diff changeset
2343 emit_farith(0xDF, 0xE8, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2345
a61af66fc99e Initial load
duke
parents:
diff changeset
2346
a61af66fc99e Initial load
duke
parents:
diff changeset
2347 void Assembler::ftst() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2348 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2349 emit_byte(0xE4);
a61af66fc99e Initial load
duke
parents:
diff changeset
2350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2351
a61af66fc99e Initial load
duke
parents:
diff changeset
2352
a61af66fc99e Initial load
duke
parents:
diff changeset
2353 void Assembler::fnstsw_ax() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2354 emit_byte(0xdF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2355 emit_byte(0xE0);
a61af66fc99e Initial load
duke
parents:
diff changeset
2356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2357
a61af66fc99e Initial load
duke
parents:
diff changeset
2358
a61af66fc99e Initial load
duke
parents:
diff changeset
2359 void Assembler::fwait() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2360 emit_byte(0x9B);
a61af66fc99e Initial load
duke
parents:
diff changeset
2361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2362
a61af66fc99e Initial load
duke
parents:
diff changeset
2363
a61af66fc99e Initial load
duke
parents:
diff changeset
2364 void Assembler::finit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2365 emit_byte(0x9B);
a61af66fc99e Initial load
duke
parents:
diff changeset
2366 emit_byte(0xDB);
a61af66fc99e Initial load
duke
parents:
diff changeset
2367 emit_byte(0xE3);
a61af66fc99e Initial load
duke
parents:
diff changeset
2368 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2369
a61af66fc99e Initial load
duke
parents:
diff changeset
2370
a61af66fc99e Initial load
duke
parents:
diff changeset
2371 void Assembler::fldcw(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2372 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2373 emit_byte(0xd9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2374 emit_operand(rbp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2376
a61af66fc99e Initial load
duke
parents:
diff changeset
2377
a61af66fc99e Initial load
duke
parents:
diff changeset
2378 void Assembler::fnstcw(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2379 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2380 emit_byte(0x9B);
a61af66fc99e Initial load
duke
parents:
diff changeset
2381 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2382 emit_operand(rdi, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2384
a61af66fc99e Initial load
duke
parents:
diff changeset
2385 void Assembler::fnsave(Address dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2386 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2387 emit_byte(0xDD);
a61af66fc99e Initial load
duke
parents:
diff changeset
2388 emit_operand(rsi, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2390
a61af66fc99e Initial load
duke
parents:
diff changeset
2391
a61af66fc99e Initial load
duke
parents:
diff changeset
2392 void Assembler::frstor(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2393 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2394 emit_byte(0xDD);
a61af66fc99e Initial load
duke
parents:
diff changeset
2395 emit_operand(rsp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2397
a61af66fc99e Initial load
duke
parents:
diff changeset
2398
a61af66fc99e Initial load
duke
parents:
diff changeset
2399 void Assembler::fldenv(Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2400 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2401 emit_byte(0xD9);
a61af66fc99e Initial load
duke
parents:
diff changeset
2402 emit_operand(rsp, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2404
a61af66fc99e Initial load
duke
parents:
diff changeset
2405
a61af66fc99e Initial load
duke
parents:
diff changeset
2406 void Assembler::sahf() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2407 emit_byte(0x9E);
a61af66fc99e Initial load
duke
parents:
diff changeset
2408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2409
a61af66fc99e Initial load
duke
parents:
diff changeset
2410 // MMX operations
a61af66fc99e Initial load
duke
parents:
diff changeset
2411 void Assembler::emit_operand(MMXRegister reg, Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2412 emit_operand((Register)reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
a61af66fc99e Initial load
duke
parents:
diff changeset
2413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2414
a61af66fc99e Initial load
duke
parents:
diff changeset
2415 void Assembler::movq( MMXRegister dst, Address src ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2416 assert( VM_Version::supports_mmx(), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
2417 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2418 emit_byte(0x6F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2419 emit_operand(dst,src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2421
a61af66fc99e Initial load
duke
parents:
diff changeset
2422 void Assembler::movq( Address dst, MMXRegister src ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2423 assert( VM_Version::supports_mmx(), "" );
a61af66fc99e Initial load
duke
parents:
diff changeset
2424 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2425 emit_byte(0x7F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2426 emit_operand(src,dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2428
a61af66fc99e Initial load
duke
parents:
diff changeset
2429 void Assembler::emms() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2430 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2431 emit_byte(0x77);
a61af66fc99e Initial load
duke
parents:
diff changeset
2432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2433
a61af66fc99e Initial load
duke
parents:
diff changeset
2434
a61af66fc99e Initial load
duke
parents:
diff changeset
2435
a61af66fc99e Initial load
duke
parents:
diff changeset
2436
a61af66fc99e Initial load
duke
parents:
diff changeset
2437 // SSE and SSE2 instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
2438 inline void Assembler::emit_sse_operand(XMMRegister reg, Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2439 assert(((Register)reg)->encoding() == reg->encoding(), "otherwise typecast is invalid");
a61af66fc99e Initial load
duke
parents:
diff changeset
2440 emit_operand((Register)reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
a61af66fc99e Initial load
duke
parents:
diff changeset
2441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2442 inline void Assembler::emit_sse_operand(Register reg, Address adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2443 emit_operand(reg, adr._base, adr._index, adr._scale, adr._disp, adr._rspec);
a61af66fc99e Initial load
duke
parents:
diff changeset
2444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2445
a61af66fc99e Initial load
duke
parents:
diff changeset
2446 inline void Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2447 emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
2448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2449 inline void Assembler::emit_sse_operand(XMMRegister dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2450 emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
2451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2452 inline void Assembler::emit_sse_operand(Register dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2453 emit_byte(0xC0 | dst->encoding() << 3 | src->encoding());
a61af66fc99e Initial load
duke
parents:
diff changeset
2454 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2455
a61af66fc99e Initial load
duke
parents:
diff changeset
2456
a61af66fc99e Initial load
duke
parents:
diff changeset
2457 // Macro for creation of SSE2 instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
2458 // The SSE2 instricution set is highly regular, so this macro saves
a61af66fc99e Initial load
duke
parents:
diff changeset
2459 // a lot of cut&paste
a61af66fc99e Initial load
duke
parents:
diff changeset
2460 // Each macro expansion creates two methods (same name with different
a61af66fc99e Initial load
duke
parents:
diff changeset
2461 // parameter list)
a61af66fc99e Initial load
duke
parents:
diff changeset
2462 //
a61af66fc99e Initial load
duke
parents:
diff changeset
2463 // Macro parameters:
a61af66fc99e Initial load
duke
parents:
diff changeset
2464 // * name: name of the created methods
a61af66fc99e Initial load
duke
parents:
diff changeset
2465 // * sse_version: either sse or sse2 for the assertion if instruction supported by processor
a61af66fc99e Initial load
duke
parents:
diff changeset
2466 // * prefix: first opcode byte of the instruction (or 0 if no prefix byte)
a61af66fc99e Initial load
duke
parents:
diff changeset
2467 // * opcode: last opcode byte of the instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
2468 // * conversion instruction have parameters of type Register instead of XMMRegister,
a61af66fc99e Initial load
duke
parents:
diff changeset
2469 // so this can also configured with macro parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
2470 #define emit_sse_instruction(name, sse_version, prefix, opcode, dst_register_type, src_register_type) \
a61af66fc99e Initial load
duke
parents:
diff changeset
2471 \
a61af66fc99e Initial load
duke
parents:
diff changeset
2472 void Assembler:: name (dst_register_type dst, Address src) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
2473 assert(VM_Version::supports_##sse_version(), ""); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2474 \
a61af66fc99e Initial load
duke
parents:
diff changeset
2475 InstructionMark im(this); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2476 if (prefix != 0) emit_byte(prefix); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2477 emit_byte(0x0F); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2478 emit_byte(opcode); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2479 emit_sse_operand(dst, src); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2480 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
2481 \
a61af66fc99e Initial load
duke
parents:
diff changeset
2482 void Assembler:: name (dst_register_type dst, src_register_type src) { \
a61af66fc99e Initial load
duke
parents:
diff changeset
2483 assert(VM_Version::supports_##sse_version(), ""); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2484 \
a61af66fc99e Initial load
duke
parents:
diff changeset
2485 if (prefix != 0) emit_byte(prefix); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2486 emit_byte(0x0F); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2487 emit_byte(opcode); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2488 emit_sse_operand(dst, src); \
a61af66fc99e Initial load
duke
parents:
diff changeset
2489 } \
a61af66fc99e Initial load
duke
parents:
diff changeset
2490
a61af66fc99e Initial load
duke
parents:
diff changeset
2491 emit_sse_instruction(addss, sse, 0xF3, 0x58, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2492 emit_sse_instruction(addsd, sse2, 0xF2, 0x58, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2493 emit_sse_instruction(subss, sse, 0xF3, 0x5C, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2494 emit_sse_instruction(subsd, sse2, 0xF2, 0x5C, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2495 emit_sse_instruction(mulss, sse, 0xF3, 0x59, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2496 emit_sse_instruction(mulsd, sse2, 0xF2, 0x59, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2497 emit_sse_instruction(divss, sse, 0xF3, 0x5E, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2498 emit_sse_instruction(divsd, sse2, 0xF2, 0x5E, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2499 emit_sse_instruction(sqrtss, sse, 0xF3, 0x51, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2500 emit_sse_instruction(sqrtsd, sse2, 0xF2, 0x51, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2501
a61af66fc99e Initial load
duke
parents:
diff changeset
2502 emit_sse_instruction(pxor, sse2, 0x66, 0xEF, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2503
a61af66fc99e Initial load
duke
parents:
diff changeset
2504 emit_sse_instruction(comiss, sse, 0, 0x2F, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2505 emit_sse_instruction(comisd, sse2, 0x66, 0x2F, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2506 emit_sse_instruction(ucomiss, sse, 0, 0x2E, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2507 emit_sse_instruction(ucomisd, sse2, 0x66, 0x2E, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2508
a61af66fc99e Initial load
duke
parents:
diff changeset
2509 emit_sse_instruction(cvtss2sd, sse2, 0xF3, 0x5A, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2510 emit_sse_instruction(cvtsd2ss, sse2, 0xF2, 0x5A, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2511 emit_sse_instruction(cvtsi2ss, sse, 0xF3, 0x2A, XMMRegister, Register);
a61af66fc99e Initial load
duke
parents:
diff changeset
2512 emit_sse_instruction(cvtsi2sd, sse2, 0xF2, 0x2A, XMMRegister, Register)
a61af66fc99e Initial load
duke
parents:
diff changeset
2513 emit_sse_instruction(cvtss2si, sse, 0xF3, 0x2D, Register, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2514 emit_sse_instruction(cvtsd2si, sse2, 0xF2, 0x2D, Register, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2515 emit_sse_instruction(cvttss2si, sse, 0xF3, 0x2C, Register, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2516 emit_sse_instruction(cvttsd2si, sse2, 0xF2, 0x2C, Register, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2517
a61af66fc99e Initial load
duke
parents:
diff changeset
2518 emit_sse_instruction(movss, sse, 0xF3, 0x10, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2519 emit_sse_instruction(movsd, sse2, 0xF2, 0x10, XMMRegister, XMMRegister)
a61af66fc99e Initial load
duke
parents:
diff changeset
2520
a61af66fc99e Initial load
duke
parents:
diff changeset
2521 emit_sse_instruction(movq, sse2, 0xF3, 0x7E, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2522 emit_sse_instruction(movd, sse2, 0x66, 0x6E, XMMRegister, Register);
a61af66fc99e Initial load
duke
parents:
diff changeset
2523 emit_sse_instruction(movdqa, sse2, 0x66, 0x6F, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2524
a61af66fc99e Initial load
duke
parents:
diff changeset
2525 emit_sse_instruction(punpcklbw, sse2, 0x66, 0x60, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2526
a61af66fc99e Initial load
duke
parents:
diff changeset
2527
a61af66fc99e Initial load
duke
parents:
diff changeset
2528 // Instruction not covered by macro
a61af66fc99e Initial load
duke
parents:
diff changeset
2529 void Assembler::movq(Address dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2530 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2531
a61af66fc99e Initial load
duke
parents:
diff changeset
2532 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2533 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2534 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2535 emit_byte(0xD6);
a61af66fc99e Initial load
duke
parents:
diff changeset
2536 emit_sse_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2537 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2538
a61af66fc99e Initial load
duke
parents:
diff changeset
2539 void Assembler::movd(Address dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2540 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2541
a61af66fc99e Initial load
duke
parents:
diff changeset
2542 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2543 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2544 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2545 emit_byte(0x7E);
a61af66fc99e Initial load
duke
parents:
diff changeset
2546 emit_sse_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2548
a61af66fc99e Initial load
duke
parents:
diff changeset
2549 void Assembler::movd(Register dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2550 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2551
a61af66fc99e Initial load
duke
parents:
diff changeset
2552 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2553 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2554 emit_byte(0x7E);
a61af66fc99e Initial load
duke
parents:
diff changeset
2555 emit_sse_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2556 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2557
a61af66fc99e Initial load
duke
parents:
diff changeset
2558 void Assembler::movdqa(Address dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2559 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2560
a61af66fc99e Initial load
duke
parents:
diff changeset
2561 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2562 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2563 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2564 emit_byte(0x7F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2565 emit_sse_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2566 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2567
a61af66fc99e Initial load
duke
parents:
diff changeset
2568 void Assembler::pshufd(XMMRegister dst, XMMRegister src, int mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2569 assert(isByte(mode), "invalid value");
a61af66fc99e Initial load
duke
parents:
diff changeset
2570 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2571
a61af66fc99e Initial load
duke
parents:
diff changeset
2572 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2573 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2574 emit_byte(0x70);
a61af66fc99e Initial load
duke
parents:
diff changeset
2575 emit_sse_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2576 emit_byte(mode & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2577 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2578
a61af66fc99e Initial load
duke
parents:
diff changeset
2579 void Assembler::pshufd(XMMRegister dst, Address src, int mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2580 assert(isByte(mode), "invalid value");
a61af66fc99e Initial load
duke
parents:
diff changeset
2581 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2582
a61af66fc99e Initial load
duke
parents:
diff changeset
2583 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2584 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2585 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2586 emit_byte(0x70);
a61af66fc99e Initial load
duke
parents:
diff changeset
2587 emit_sse_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2588 emit_byte(mode & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2590
a61af66fc99e Initial load
duke
parents:
diff changeset
2591 void Assembler::pshuflw(XMMRegister dst, XMMRegister src, int mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2592 assert(isByte(mode), "invalid value");
a61af66fc99e Initial load
duke
parents:
diff changeset
2593 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2594
a61af66fc99e Initial load
duke
parents:
diff changeset
2595 emit_byte(0xF2);
a61af66fc99e Initial load
duke
parents:
diff changeset
2596 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2597 emit_byte(0x70);
a61af66fc99e Initial load
duke
parents:
diff changeset
2598 emit_sse_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2599 emit_byte(mode & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2601
a61af66fc99e Initial load
duke
parents:
diff changeset
2602 void Assembler::pshuflw(XMMRegister dst, Address src, int mode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2603 assert(isByte(mode), "invalid value");
a61af66fc99e Initial load
duke
parents:
diff changeset
2604 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2605
a61af66fc99e Initial load
duke
parents:
diff changeset
2606 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2607 emit_byte(0xF2);
a61af66fc99e Initial load
duke
parents:
diff changeset
2608 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2609 emit_byte(0x70);
a61af66fc99e Initial load
duke
parents:
diff changeset
2610 emit_sse_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2611 emit_byte(mode & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2613
a61af66fc99e Initial load
duke
parents:
diff changeset
2614 void Assembler::psrlq(XMMRegister dst, int shift) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2615 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2616
a61af66fc99e Initial load
duke
parents:
diff changeset
2617 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2618 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2619 emit_byte(0x73);
a61af66fc99e Initial load
duke
parents:
diff changeset
2620 emit_sse_operand(xmm2, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2621 emit_byte(shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
2622 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2623
a61af66fc99e Initial load
duke
parents:
diff changeset
2624 void Assembler::movss( Address dst, XMMRegister src ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2625 assert(VM_Version::supports_sse(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2626
a61af66fc99e Initial load
duke
parents:
diff changeset
2627 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2628 emit_byte(0xF3); // single
a61af66fc99e Initial load
duke
parents:
diff changeset
2629 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2630 emit_byte(0x11); // store
a61af66fc99e Initial load
duke
parents:
diff changeset
2631 emit_sse_operand(src, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2632 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2633
a61af66fc99e Initial load
duke
parents:
diff changeset
2634 void Assembler::movsd( Address dst, XMMRegister src ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2635 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2636
a61af66fc99e Initial load
duke
parents:
diff changeset
2637 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2638 emit_byte(0xF2); // double
a61af66fc99e Initial load
duke
parents:
diff changeset
2639 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2640 emit_byte(0x11); // store
a61af66fc99e Initial load
duke
parents:
diff changeset
2641 emit_sse_operand(src,dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2643
a61af66fc99e Initial load
duke
parents:
diff changeset
2644 // New cpus require to use movaps and movapd to avoid partial register stall
a61af66fc99e Initial load
duke
parents:
diff changeset
2645 // when moving between registers.
a61af66fc99e Initial load
duke
parents:
diff changeset
2646 void Assembler::movaps(XMMRegister dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2647 assert(VM_Version::supports_sse(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2648
a61af66fc99e Initial load
duke
parents:
diff changeset
2649 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2650 emit_byte(0x28);
a61af66fc99e Initial load
duke
parents:
diff changeset
2651 emit_sse_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2653 void Assembler::movapd(XMMRegister dst, XMMRegister src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2654 assert(VM_Version::supports_sse2(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2655
a61af66fc99e Initial load
duke
parents:
diff changeset
2656 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2657 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2658 emit_byte(0x28);
a61af66fc99e Initial load
duke
parents:
diff changeset
2659 emit_sse_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2661
a61af66fc99e Initial load
duke
parents:
diff changeset
2662 // New cpus require to use movsd and movss to avoid partial register stall
a61af66fc99e Initial load
duke
parents:
diff changeset
2663 // when loading from memory. But for old Opteron use movlpd instead of movsd.
a61af66fc99e Initial load
duke
parents:
diff changeset
2664 // The selection is done in MacroAssembler::movdbl() and movflt().
a61af66fc99e Initial load
duke
parents:
diff changeset
2665 void Assembler::movlpd(XMMRegister dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2666 assert(VM_Version::supports_sse(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
2667
a61af66fc99e Initial load
duke
parents:
diff changeset
2668 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2669 emit_byte(0x66);
a61af66fc99e Initial load
duke
parents:
diff changeset
2670 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2671 emit_byte(0x12);
a61af66fc99e Initial load
duke
parents:
diff changeset
2672 emit_sse_operand(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2674
a61af66fc99e Initial load
duke
parents:
diff changeset
2675
a61af66fc99e Initial load
duke
parents:
diff changeset
2676 emit_sse_instruction(andps, sse, 0, 0x54, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2677 emit_sse_instruction(andpd, sse2, 0x66, 0x54, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2678 emit_sse_instruction(andnps, sse, 0, 0x55, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2679 emit_sse_instruction(andnpd, sse2, 0x66, 0x55, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2680 emit_sse_instruction(orps, sse, 0, 0x56, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2681 emit_sse_instruction(orpd, sse2, 0x66, 0x56, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2682 emit_sse_instruction(xorps, sse, 0, 0x57, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2683 emit_sse_instruction(xorpd, sse2, 0x66, 0x57, XMMRegister, XMMRegister);
a61af66fc99e Initial load
duke
parents:
diff changeset
2684
a61af66fc99e Initial load
duke
parents:
diff changeset
2685
a61af66fc99e Initial load
duke
parents:
diff changeset
2686 void Assembler::ldmxcsr( Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2687 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2688 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2689 emit_byte(0xAE);
a61af66fc99e Initial load
duke
parents:
diff changeset
2690 emit_operand(rdx /* 2 */, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2692
a61af66fc99e Initial load
duke
parents:
diff changeset
2693 void Assembler::stmxcsr( Address dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2694 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2695 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2696 emit_byte(0xAE);
a61af66fc99e Initial load
duke
parents:
diff changeset
2697 emit_operand(rbx /* 3 */, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2698 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2699
a61af66fc99e Initial load
duke
parents:
diff changeset
2700 // Implementation of MacroAssembler
a61af66fc99e Initial load
duke
parents:
diff changeset
2701
a61af66fc99e Initial load
duke
parents:
diff changeset
2702 Address MacroAssembler::as_Address(AddressLiteral adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2703 // amd64 always does this as a pc-rel
a61af66fc99e Initial load
duke
parents:
diff changeset
2704 // we can be absolute or disp based on the instruction type
a61af66fc99e Initial load
duke
parents:
diff changeset
2705 // jmp/call are displacements others are absolute
a61af66fc99e Initial load
duke
parents:
diff changeset
2706 assert(!adr.is_lval(), "must be rval");
a61af66fc99e Initial load
duke
parents:
diff changeset
2707
a61af66fc99e Initial load
duke
parents:
diff changeset
2708 return Address(adr.target(), adr.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2710
a61af66fc99e Initial load
duke
parents:
diff changeset
2711 Address MacroAssembler::as_Address(ArrayAddress adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2712 return Address::make_array(adr);
a61af66fc99e Initial load
duke
parents:
diff changeset
2713 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2714
a61af66fc99e Initial load
duke
parents:
diff changeset
2715 void MacroAssembler::fat_nop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
2716 // A 5 byte nop that is safe for patching (see patch_verified_entry)
a61af66fc99e Initial load
duke
parents:
diff changeset
2717 emit_byte(0x26); // es:
a61af66fc99e Initial load
duke
parents:
diff changeset
2718 emit_byte(0x2e); // cs:
a61af66fc99e Initial load
duke
parents:
diff changeset
2719 emit_byte(0x64); // fs:
a61af66fc99e Initial load
duke
parents:
diff changeset
2720 emit_byte(0x65); // gs:
a61af66fc99e Initial load
duke
parents:
diff changeset
2721 emit_byte(0x90);
a61af66fc99e Initial load
duke
parents:
diff changeset
2722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2723
a61af66fc99e Initial load
duke
parents:
diff changeset
2724 // 32bit can do a case table jump in one instruction but we no longer allow the base
a61af66fc99e Initial load
duke
parents:
diff changeset
2725 // to be installed in the Address class
a61af66fc99e Initial load
duke
parents:
diff changeset
2726 void MacroAssembler::jump(ArrayAddress entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2727 jmp(as_Address(entry));
a61af66fc99e Initial load
duke
parents:
diff changeset
2728 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2729
a61af66fc99e Initial load
duke
parents:
diff changeset
2730 void MacroAssembler::jump(AddressLiteral dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2731 jmp_literal(dst.target(), dst.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2732 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2733
a61af66fc99e Initial load
duke
parents:
diff changeset
2734 void MacroAssembler::jump_cc(Condition cc, AddressLiteral dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2735 assert((0 <= cc) && (cc < 16), "illegal cc");
a61af66fc99e Initial load
duke
parents:
diff changeset
2736
a61af66fc99e Initial load
duke
parents:
diff changeset
2737 InstructionMark im(this);
a61af66fc99e Initial load
duke
parents:
diff changeset
2738
a61af66fc99e Initial load
duke
parents:
diff changeset
2739 relocInfo::relocType rtype = dst.reloc();
a61af66fc99e Initial load
duke
parents:
diff changeset
2740 relocate(rtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
2741 const int short_size = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
2742 const int long_size = 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
2743 int offs = (int)dst.target() - ((int)_code_pos);
a61af66fc99e Initial load
duke
parents:
diff changeset
2744 if (rtype == relocInfo::none && is8bit(offs - short_size)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2745 // 0111 tttn #8-bit disp
a61af66fc99e Initial load
duke
parents:
diff changeset
2746 emit_byte(0x70 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
2747 emit_byte((offs - short_size) & 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
2748 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2749 // 0000 1111 1000 tttn #32-bit disp
a61af66fc99e Initial load
duke
parents:
diff changeset
2750 emit_byte(0x0F);
a61af66fc99e Initial load
duke
parents:
diff changeset
2751 emit_byte(0x80 | cc);
a61af66fc99e Initial load
duke
parents:
diff changeset
2752 emit_long(offs - long_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
2753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2755
a61af66fc99e Initial load
duke
parents:
diff changeset
2756 // Calls
a61af66fc99e Initial load
duke
parents:
diff changeset
2757 void MacroAssembler::call(Label& L, relocInfo::relocType rtype) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2758 Assembler::call(L, rtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
2759 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2760
a61af66fc99e Initial load
duke
parents:
diff changeset
2761 void MacroAssembler::call(Register entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2762 Assembler::call(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
2763 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2764
a61af66fc99e Initial load
duke
parents:
diff changeset
2765 void MacroAssembler::call(AddressLiteral entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2766 Assembler::call_literal(entry.target(), entry.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2767 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2768
a61af66fc99e Initial load
duke
parents:
diff changeset
2769
a61af66fc99e Initial load
duke
parents:
diff changeset
2770 void MacroAssembler::cmp8(AddressLiteral src1, int8_t imm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2771 Assembler::cmpb(as_Address(src1), imm);
a61af66fc99e Initial load
duke
parents:
diff changeset
2772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2773
a61af66fc99e Initial load
duke
parents:
diff changeset
2774 void MacroAssembler::cmp32(AddressLiteral src1, int32_t imm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2775 Assembler::cmpl(as_Address(src1), imm);
a61af66fc99e Initial load
duke
parents:
diff changeset
2776 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2777
a61af66fc99e Initial load
duke
parents:
diff changeset
2778 void MacroAssembler::cmp32(Register src1, AddressLiteral src2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2779 if (src2.is_lval()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2780 cmp_literal32(src1, (int32_t) src2.target(), src2.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2781 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2782 Assembler::cmpl(src1, as_Address(src2));
a61af66fc99e Initial load
duke
parents:
diff changeset
2783 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2784 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2785
a61af66fc99e Initial load
duke
parents:
diff changeset
2786 void MacroAssembler::cmp32(Register src1, int32_t imm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2787 Assembler::cmpl(src1, imm);
a61af66fc99e Initial load
duke
parents:
diff changeset
2788 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2789
a61af66fc99e Initial load
duke
parents:
diff changeset
2790 void MacroAssembler::cmp32(Register src1, Address src2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2791 Assembler::cmpl(src1, src2);
a61af66fc99e Initial load
duke
parents:
diff changeset
2792 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2793
a61af66fc99e Initial load
duke
parents:
diff changeset
2794 void MacroAssembler::cmpoop(Address src1, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2795 cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
a61af66fc99e Initial load
duke
parents:
diff changeset
2796 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2797
a61af66fc99e Initial load
duke
parents:
diff changeset
2798 void MacroAssembler::cmpoop(Register src1, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2799 cmp_literal32(src1, (int32_t)obj, oop_Relocation::spec_for_immediate());
a61af66fc99e Initial load
duke
parents:
diff changeset
2800 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2801
a61af66fc99e Initial load
duke
parents:
diff changeset
2802 void MacroAssembler::cmpptr(Register src1, AddressLiteral src2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2803 if (src2.is_lval()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2804 // compare the effect address of src2 to src1
a61af66fc99e Initial load
duke
parents:
diff changeset
2805 cmp_literal32(src1, (int32_t)src2.target(), src2.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2806 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2807 Assembler::cmpl(src1, as_Address(src2));
a61af66fc99e Initial load
duke
parents:
diff changeset
2808 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2809 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2810
a61af66fc99e Initial load
duke
parents:
diff changeset
2811 void MacroAssembler::cmpptr(Address src1, AddressLiteral src2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2812 assert(src2.is_lval(), "not a mem-mem compare");
a61af66fc99e Initial load
duke
parents:
diff changeset
2813 cmp_literal32(src1, (int32_t) src2.target(), src2.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2815
a61af66fc99e Initial load
duke
parents:
diff changeset
2816
a61af66fc99e Initial load
duke
parents:
diff changeset
2817 void MacroAssembler::cmpxchgptr(Register reg, AddressLiteral adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2818 cmpxchg(reg, as_Address(adr));
a61af66fc99e Initial load
duke
parents:
diff changeset
2819 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2820
a61af66fc99e Initial load
duke
parents:
diff changeset
2821 void MacroAssembler::increment(AddressLiteral dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2822 increment(as_Address(dst));
a61af66fc99e Initial load
duke
parents:
diff changeset
2823 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2824
a61af66fc99e Initial load
duke
parents:
diff changeset
2825 void MacroAssembler::increment(ArrayAddress dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2826 increment(as_Address(dst));
a61af66fc99e Initial load
duke
parents:
diff changeset
2827 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2828
a61af66fc99e Initial load
duke
parents:
diff changeset
2829 void MacroAssembler::lea(Register dst, AddressLiteral adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2830 // leal(dst, as_Address(adr));
a61af66fc99e Initial load
duke
parents:
diff changeset
2831 // see note in movl as to why we musr use a move
a61af66fc99e Initial load
duke
parents:
diff changeset
2832 mov_literal32(dst, (int32_t) adr.target(), adr.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2834
a61af66fc99e Initial load
duke
parents:
diff changeset
2835 void MacroAssembler::lea(Address dst, AddressLiteral adr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2836 // leal(dst, as_Address(adr));
a61af66fc99e Initial load
duke
parents:
diff changeset
2837 // see note in movl as to why we musr use a move
a61af66fc99e Initial load
duke
parents:
diff changeset
2838 mov_literal32(dst, (int32_t) adr.target(), adr.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2839 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2840
a61af66fc99e Initial load
duke
parents:
diff changeset
2841 void MacroAssembler::mov32(AddressLiteral dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2842 Assembler::movl(as_Address(dst), src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2843 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2844
a61af66fc99e Initial load
duke
parents:
diff changeset
2845 void MacroAssembler::mov32(Register dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2846 Assembler::movl(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2848
a61af66fc99e Initial load
duke
parents:
diff changeset
2849 void MacroAssembler::movbyte(ArrayAddress dst, int src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2850 movb(as_Address(dst), src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2852
a61af66fc99e Initial load
duke
parents:
diff changeset
2853 void MacroAssembler::movoop(Address dst, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2854 mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
a61af66fc99e Initial load
duke
parents:
diff changeset
2855 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2856
a61af66fc99e Initial load
duke
parents:
diff changeset
2857 void MacroAssembler::movoop(Register dst, jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2858 mov_literal32(dst, (int32_t)obj, oop_Relocation::spec_for_immediate());
a61af66fc99e Initial load
duke
parents:
diff changeset
2859 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2860
a61af66fc99e Initial load
duke
parents:
diff changeset
2861 void MacroAssembler::movptr(Register dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2862 if (src.is_lval()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2863 // essentially an lea
a61af66fc99e Initial load
duke
parents:
diff changeset
2864 mov_literal32(dst, (int32_t) src.target(), src.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2865 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2866 // mov 32bits from an absolute address
a61af66fc99e Initial load
duke
parents:
diff changeset
2867 movl(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2869 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2870
a61af66fc99e Initial load
duke
parents:
diff changeset
2871 void MacroAssembler::movptr(ArrayAddress dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2872 movl(as_Address(dst), src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2873 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2874
a61af66fc99e Initial load
duke
parents:
diff changeset
2875 void MacroAssembler::movptr(Register dst, ArrayAddress src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2876 movl(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2878
a61af66fc99e Initial load
duke
parents:
diff changeset
2879 void MacroAssembler::movflt(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2880 movss(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2881 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2882
a61af66fc99e Initial load
duke
parents:
diff changeset
2883 void MacroAssembler::movdbl(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2884 if (UseXmmLoadAndClearUpper) { movsd (dst, as_Address(src)); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
2885 else { movlpd(dst, as_Address(src)); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
2886 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2887
a61af66fc99e Initial load
duke
parents:
diff changeset
2888 void Assembler::pushoop(jobject obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2889 push_literal32((int32_t)obj, oop_Relocation::spec_for_immediate());
a61af66fc99e Initial load
duke
parents:
diff changeset
2890 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2891
a61af66fc99e Initial load
duke
parents:
diff changeset
2892
a61af66fc99e Initial load
duke
parents:
diff changeset
2893 void MacroAssembler::pushptr(AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2894 if (src.is_lval()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2895 push_literal32((int32_t)src.target(), src.rspec());
a61af66fc99e Initial load
duke
parents:
diff changeset
2896 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2897 pushl(as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2898 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2899 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2900
a61af66fc99e Initial load
duke
parents:
diff changeset
2901 void MacroAssembler::test32(Register src1, AddressLiteral src2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2902 // src2 must be rval
a61af66fc99e Initial load
duke
parents:
diff changeset
2903 testl(src1, as_Address(src2));
a61af66fc99e Initial load
duke
parents:
diff changeset
2904 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2905
a61af66fc99e Initial load
duke
parents:
diff changeset
2906 // FPU
a61af66fc99e Initial load
duke
parents:
diff changeset
2907
a61af66fc99e Initial load
duke
parents:
diff changeset
2908 void MacroAssembler::fld_x(AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2909 Assembler::fld_x(as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2910 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2911
a61af66fc99e Initial load
duke
parents:
diff changeset
2912 void MacroAssembler::fld_d(AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2913 fld_d(as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2914 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2915
a61af66fc99e Initial load
duke
parents:
diff changeset
2916 void MacroAssembler::fld_s(AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2917 fld_s(as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2918 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2919
a61af66fc99e Initial load
duke
parents:
diff changeset
2920 void MacroAssembler::fldcw(AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2921 Assembler::fldcw(as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2922 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2923
a61af66fc99e Initial load
duke
parents:
diff changeset
2924 void MacroAssembler::ldmxcsr(AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2925 Assembler::ldmxcsr(as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2926 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2927
a61af66fc99e Initial load
duke
parents:
diff changeset
2928 // SSE
a61af66fc99e Initial load
duke
parents:
diff changeset
2929
a61af66fc99e Initial load
duke
parents:
diff changeset
2930 void MacroAssembler::andpd(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2931 andpd(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2932 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2933
a61af66fc99e Initial load
duke
parents:
diff changeset
2934 void MacroAssembler::comisd(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2935 comisd(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2936 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2937
a61af66fc99e Initial load
duke
parents:
diff changeset
2938 void MacroAssembler::comiss(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2939 comiss(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2940 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2941
a61af66fc99e Initial load
duke
parents:
diff changeset
2942 void MacroAssembler::movsd(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2943 movsd(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2944 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2945
a61af66fc99e Initial load
duke
parents:
diff changeset
2946 void MacroAssembler::movss(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2947 movss(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2948 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2949
a61af66fc99e Initial load
duke
parents:
diff changeset
2950 void MacroAssembler::xorpd(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2951 xorpd(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2952 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2953
a61af66fc99e Initial load
duke
parents:
diff changeset
2954 void MacroAssembler::xorps(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2955 xorps(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2956 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2957
a61af66fc99e Initial load
duke
parents:
diff changeset
2958 void MacroAssembler::ucomisd(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2959 ucomisd(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2960 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2961
a61af66fc99e Initial load
duke
parents:
diff changeset
2962 void MacroAssembler::ucomiss(XMMRegister dst, AddressLiteral src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2963 ucomiss(dst, as_Address(src));
a61af66fc99e Initial load
duke
parents:
diff changeset
2964 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2965
a61af66fc99e Initial load
duke
parents:
diff changeset
2966 void MacroAssembler::null_check(Register reg, int offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2967 if (needs_explicit_null_check(offset)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2968 // provoke OS NULL exception if reg = NULL by
a61af66fc99e Initial load
duke
parents:
diff changeset
2969 // accessing M[reg] w/o changing any (non-CC) registers
a61af66fc99e Initial load
duke
parents:
diff changeset
2970 cmpl(rax, Address(reg, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
2971 // Note: should probably use testl(rax, Address(reg, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
2972 // may be shorter code (however, this version of
a61af66fc99e Initial load
duke
parents:
diff changeset
2973 // testl needs to be implemented first)
a61af66fc99e Initial load
duke
parents:
diff changeset
2974 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2975 // nothing to do, (later) access of M[reg + offset]
a61af66fc99e Initial load
duke
parents:
diff changeset
2976 // will provoke OS NULL exception if reg = NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
2977 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2978 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2979
a61af66fc99e Initial load
duke
parents:
diff changeset
2980
a61af66fc99e Initial load
duke
parents:
diff changeset
2981 int MacroAssembler::load_unsigned_byte(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2982 // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
a61af66fc99e Initial load
duke
parents:
diff changeset
2983 // and "3.9 Partial Register Penalties", p. 22).
a61af66fc99e Initial load
duke
parents:
diff changeset
2984 int off;
a61af66fc99e Initial load
duke
parents:
diff changeset
2985 if (VM_Version::is_P6() || src.uses(dst)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2986 off = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
2987 movzxb(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2988 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2989 xorl(dst, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
2990 off = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
2991 movb(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
2992 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2993 return off;
a61af66fc99e Initial load
duke
parents:
diff changeset
2994 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2995
a61af66fc99e Initial load
duke
parents:
diff changeset
2996
a61af66fc99e Initial load
duke
parents:
diff changeset
2997 int MacroAssembler::load_unsigned_word(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2998 // According to Intel Doc. AP-526, "Zero-Extension of Short", p.16,
a61af66fc99e Initial load
duke
parents:
diff changeset
2999 // and "3.9 Partial Register Penalties", p. 22).
a61af66fc99e Initial load
duke
parents:
diff changeset
3000 int off;
a61af66fc99e Initial load
duke
parents:
diff changeset
3001 if (VM_Version::is_P6() || src.uses(dst)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3002 off = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3003 movzxw(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3004 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3005 xorl(dst, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3006 off = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3007 movw(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3008 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3009 return off;
a61af66fc99e Initial load
duke
parents:
diff changeset
3010 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3011
a61af66fc99e Initial load
duke
parents:
diff changeset
3012
a61af66fc99e Initial load
duke
parents:
diff changeset
3013 int MacroAssembler::load_signed_byte(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3014 int off;
a61af66fc99e Initial load
duke
parents:
diff changeset
3015 if (VM_Version::is_P6()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3016 off = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3017 movsxb(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3018 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3019 off = load_unsigned_byte(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3020 shll(dst, 24);
a61af66fc99e Initial load
duke
parents:
diff changeset
3021 sarl(dst, 24);
a61af66fc99e Initial load
duke
parents:
diff changeset
3022 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3023 return off;
a61af66fc99e Initial load
duke
parents:
diff changeset
3024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3025
a61af66fc99e Initial load
duke
parents:
diff changeset
3026
a61af66fc99e Initial load
duke
parents:
diff changeset
3027 int MacroAssembler::load_signed_word(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3028 int off;
a61af66fc99e Initial load
duke
parents:
diff changeset
3029 if (VM_Version::is_P6()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3030 off = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3031 movsxw(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3032 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3033 off = load_unsigned_word(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3034 shll(dst, 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
3035 sarl(dst, 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
3036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3037 return off;
a61af66fc99e Initial load
duke
parents:
diff changeset
3038 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3039
a61af66fc99e Initial load
duke
parents:
diff changeset
3040
a61af66fc99e Initial load
duke
parents:
diff changeset
3041 void MacroAssembler::extend_sign(Register hi, Register lo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3042 // According to Intel Doc. AP-526, "Integer Divide", p.18.
a61af66fc99e Initial load
duke
parents:
diff changeset
3043 if (VM_Version::is_P6() && hi == rdx && lo == rax) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3044 cdql();
a61af66fc99e Initial load
duke
parents:
diff changeset
3045 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3046 movl(hi, lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
3047 sarl(hi, 31);
a61af66fc99e Initial load
duke
parents:
diff changeset
3048 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3049 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3050
a61af66fc99e Initial load
duke
parents:
diff changeset
3051
a61af66fc99e Initial load
duke
parents:
diff changeset
3052 void MacroAssembler::increment(Register reg, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3053 if (value == min_jint) {addl(reg, value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3054 if (value < 0) { decrement(reg, -value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3055 if (value == 0) { ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3056 if (value == 1 && UseIncDec) { incl(reg); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3057 /* else */ { addl(reg, value) ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3058 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3059
a61af66fc99e Initial load
duke
parents:
diff changeset
3060 void MacroAssembler::increment(Address dst, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3061 if (value == min_jint) {addl(dst, value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3062 if (value < 0) { decrement(dst, -value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3063 if (value == 0) { ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3064 if (value == 1 && UseIncDec) { incl(dst); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3065 /* else */ { addl(dst, value) ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3066 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3067
a61af66fc99e Initial load
duke
parents:
diff changeset
3068 void MacroAssembler::decrement(Register reg, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3069 if (value == min_jint) {subl(reg, value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3070 if (value < 0) { increment(reg, -value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3071 if (value == 0) { ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3072 if (value == 1 && UseIncDec) { decl(reg); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3073 /* else */ { subl(reg, value) ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3074 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3075
a61af66fc99e Initial load
duke
parents:
diff changeset
3076 void MacroAssembler::decrement(Address dst, int value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3077 if (value == min_jint) {subl(dst, value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3078 if (value < 0) { increment(dst, -value); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3079 if (value == 0) { ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3080 if (value == 1 && UseIncDec) { decl(dst); return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3081 /* else */ { subl(dst, value) ; return; }
a61af66fc99e Initial load
duke
parents:
diff changeset
3082 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3083
a61af66fc99e Initial load
duke
parents:
diff changeset
3084 void MacroAssembler::align(int modulus) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3085 if (offset() % modulus != 0) nop(modulus - (offset() % modulus));
a61af66fc99e Initial load
duke
parents:
diff changeset
3086 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3087
a61af66fc99e Initial load
duke
parents:
diff changeset
3088
a61af66fc99e Initial load
duke
parents:
diff changeset
3089 void MacroAssembler::enter() {
a61af66fc99e Initial load
duke
parents:
diff changeset
3090 pushl(rbp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3091 movl(rbp, rsp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3092 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3093
a61af66fc99e Initial load
duke
parents:
diff changeset
3094
a61af66fc99e Initial load
duke
parents:
diff changeset
3095 void MacroAssembler::leave() {
a61af66fc99e Initial load
duke
parents:
diff changeset
3096 movl(rsp, rbp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3097 popl(rbp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3098 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3099
a61af66fc99e Initial load
duke
parents:
diff changeset
3100 void MacroAssembler::set_last_Java_frame(Register java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
3101 Register last_java_sp,
a61af66fc99e Initial load
duke
parents:
diff changeset
3102 Register last_java_fp,
a61af66fc99e Initial load
duke
parents:
diff changeset
3103 address last_java_pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3104 // determine java_thread register
a61af66fc99e Initial load
duke
parents:
diff changeset
3105 if (!java_thread->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3106 java_thread = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
3107 get_thread(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
3108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3109 // determine last_java_sp register
a61af66fc99e Initial load
duke
parents:
diff changeset
3110 if (!last_java_sp->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3111 last_java_sp = rsp;
a61af66fc99e Initial load
duke
parents:
diff changeset
3112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3113
a61af66fc99e Initial load
duke
parents:
diff changeset
3114 // last_java_fp is optional
a61af66fc99e Initial load
duke
parents:
diff changeset
3115
a61af66fc99e Initial load
duke
parents:
diff changeset
3116 if (last_java_fp->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3117 movl(Address(java_thread, JavaThread::last_Java_fp_offset()), last_java_fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3119
a61af66fc99e Initial load
duke
parents:
diff changeset
3120 // last_java_pc is optional
a61af66fc99e Initial load
duke
parents:
diff changeset
3121
a61af66fc99e Initial load
duke
parents:
diff changeset
3122 if (last_java_pc != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3123 lea(Address(java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
3124 JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()),
a61af66fc99e Initial load
duke
parents:
diff changeset
3125 InternalAddress(last_java_pc));
a61af66fc99e Initial load
duke
parents:
diff changeset
3126
a61af66fc99e Initial load
duke
parents:
diff changeset
3127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3128 movl(Address(java_thread, JavaThread::last_Java_sp_offset()), last_java_sp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3130
a61af66fc99e Initial load
duke
parents:
diff changeset
3131 void MacroAssembler::reset_last_Java_frame(Register java_thread, bool clear_fp, bool clear_pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3132 // determine java_thread register
a61af66fc99e Initial load
duke
parents:
diff changeset
3133 if (!java_thread->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3134 java_thread = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
3135 get_thread(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
3136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3137 // we must set sp to zero to clear frame
a61af66fc99e Initial load
duke
parents:
diff changeset
3138 movl(Address(java_thread, JavaThread::last_Java_sp_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3139 if (clear_fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3140 movl(Address(java_thread, JavaThread::last_Java_fp_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3142
a61af66fc99e Initial load
duke
parents:
diff changeset
3143 if (clear_pc)
a61af66fc99e Initial load
duke
parents:
diff changeset
3144 movl(Address(java_thread, JavaThread::last_Java_pc_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3145
a61af66fc99e Initial load
duke
parents:
diff changeset
3146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3147
a61af66fc99e Initial load
duke
parents:
diff changeset
3148
a61af66fc99e Initial load
duke
parents:
diff changeset
3149
a61af66fc99e Initial load
duke
parents:
diff changeset
3150 // Implementation of call_VM versions
a61af66fc99e Initial load
duke
parents:
diff changeset
3151
a61af66fc99e Initial load
duke
parents:
diff changeset
3152 void MacroAssembler::call_VM_leaf_base(
a61af66fc99e Initial load
duke
parents:
diff changeset
3153 address entry_point,
a61af66fc99e Initial load
duke
parents:
diff changeset
3154 int number_of_arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
3155 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3156 call(RuntimeAddress(entry_point));
a61af66fc99e Initial load
duke
parents:
diff changeset
3157 increment(rsp, number_of_arguments * wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
3158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3159
a61af66fc99e Initial load
duke
parents:
diff changeset
3160
a61af66fc99e Initial load
duke
parents:
diff changeset
3161 void MacroAssembler::call_VM_base(
a61af66fc99e Initial load
duke
parents:
diff changeset
3162 Register oop_result,
a61af66fc99e Initial load
duke
parents:
diff changeset
3163 Register java_thread,
a61af66fc99e Initial load
duke
parents:
diff changeset
3164 Register last_java_sp,
a61af66fc99e Initial load
duke
parents:
diff changeset
3165 address entry_point,
a61af66fc99e Initial load
duke
parents:
diff changeset
3166 int number_of_arguments,
a61af66fc99e Initial load
duke
parents:
diff changeset
3167 bool check_exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
3168 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3169 // determine java_thread register
a61af66fc99e Initial load
duke
parents:
diff changeset
3170 if (!java_thread->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3171 java_thread = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
3172 get_thread(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
3173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3174 // determine last_java_sp register
a61af66fc99e Initial load
duke
parents:
diff changeset
3175 if (!last_java_sp->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3176 last_java_sp = rsp;
a61af66fc99e Initial load
duke
parents:
diff changeset
3177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3178 // debugging support
a61af66fc99e Initial load
duke
parents:
diff changeset
3179 assert(number_of_arguments >= 0 , "cannot have negative number of arguments");
a61af66fc99e Initial load
duke
parents:
diff changeset
3180 assert(java_thread != oop_result , "cannot use the same register for java_thread & oop_result");
a61af66fc99e Initial load
duke
parents:
diff changeset
3181 assert(java_thread != last_java_sp, "cannot use the same register for java_thread & last_java_sp");
a61af66fc99e Initial load
duke
parents:
diff changeset
3182 // push java thread (becomes first argument of C function)
a61af66fc99e Initial load
duke
parents:
diff changeset
3183 pushl(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
3184 // set last Java frame before call
a61af66fc99e Initial load
duke
parents:
diff changeset
3185 assert(last_java_sp != rbp, "this code doesn't work for last_java_sp == rbp, which currently can't portably work anyway since C2 doesn't save rbp,");
a61af66fc99e Initial load
duke
parents:
diff changeset
3186 // Only interpreter should have to set fp
a61af66fc99e Initial load
duke
parents:
diff changeset
3187 set_last_Java_frame(java_thread, last_java_sp, rbp, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
3188 // do the call
a61af66fc99e Initial load
duke
parents:
diff changeset
3189 call(RuntimeAddress(entry_point));
a61af66fc99e Initial load
duke
parents:
diff changeset
3190 // restore the thread (cannot use the pushed argument since arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
3191 // may be overwritten by C code generated by an optimizing compiler);
a61af66fc99e Initial load
duke
parents:
diff changeset
3192 // however can use the register value directly if it is callee saved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3193 if (java_thread == rdi || java_thread == rsi) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3194 // rdi & rsi are callee saved -> nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
3195 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
3196 guarantee(java_thread != rax, "change this code");
a61af66fc99e Initial load
duke
parents:
diff changeset
3197 pushl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3198 { Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
3199 get_thread(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3200 cmpl(java_thread, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3201 jcc(Assembler::equal, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3202 stop("MacroAssembler::call_VM_base: rdi not callee saved?");
a61af66fc99e Initial load
duke
parents:
diff changeset
3203 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3205 popl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3206 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
3207 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3208 get_thread(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
3209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3210 // reset last Java frame
a61af66fc99e Initial load
duke
parents:
diff changeset
3211 // Only interpreter should have to clear fp
a61af66fc99e Initial load
duke
parents:
diff changeset
3212 reset_last_Java_frame(java_thread, true, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
3213 // discard thread and arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
3214 addl(rsp, (1 + number_of_arguments)*wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
3215
a61af66fc99e Initial load
duke
parents:
diff changeset
3216 #ifndef CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
3217 // C++ interp handles this in the interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
3218 check_and_handle_popframe(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
3219 check_and_handle_earlyret(java_thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
3220 #endif /* CC_INTERP */
a61af66fc99e Initial load
duke
parents:
diff changeset
3221
a61af66fc99e Initial load
duke
parents:
diff changeset
3222 if (check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3223 // check for pending exceptions (java_thread is set upon return)
a61af66fc99e Initial load
duke
parents:
diff changeset
3224 cmpl(Address(java_thread, Thread::pending_exception_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
3225 jump_cc(Assembler::notEqual,
a61af66fc99e Initial load
duke
parents:
diff changeset
3226 RuntimeAddress(StubRoutines::forward_exception_entry()));
a61af66fc99e Initial load
duke
parents:
diff changeset
3227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3228
a61af66fc99e Initial load
duke
parents:
diff changeset
3229 // get oop result if there is one and reset the value in the thread
a61af66fc99e Initial load
duke
parents:
diff changeset
3230 if (oop_result->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3231 movl(oop_result, Address(java_thread, JavaThread::vm_result_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
3232 movl(Address(java_thread, JavaThread::vm_result_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
3233 verify_oop(oop_result);
a61af66fc99e Initial load
duke
parents:
diff changeset
3234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3236
a61af66fc99e Initial load
duke
parents:
diff changeset
3237
a61af66fc99e Initial load
duke
parents:
diff changeset
3238 void MacroAssembler::check_and_handle_popframe(Register java_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3240
a61af66fc99e Initial load
duke
parents:
diff changeset
3241 void MacroAssembler::check_and_handle_earlyret(Register java_thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3243
a61af66fc99e Initial load
duke
parents:
diff changeset
3244 void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3245 leal(rax, Address(rsp, (1 + number_of_arguments) * wordSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
3246 call_VM_base(oop_result, noreg, rax, entry_point, number_of_arguments, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3247 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3248
a61af66fc99e Initial load
duke
parents:
diff changeset
3249
a61af66fc99e Initial load
duke
parents:
diff changeset
3250 void MacroAssembler::call_VM(Register oop_result, address entry_point, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3251 Label C, E;
a61af66fc99e Initial load
duke
parents:
diff changeset
3252 call(C, relocInfo::none);
a61af66fc99e Initial load
duke
parents:
diff changeset
3253 jmp(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3254
a61af66fc99e Initial load
duke
parents:
diff changeset
3255 bind(C);
a61af66fc99e Initial load
duke
parents:
diff changeset
3256 call_VM_helper(oop_result, entry_point, 0, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3257 ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3258
a61af66fc99e Initial load
duke
parents:
diff changeset
3259 bind(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3261
a61af66fc99e Initial load
duke
parents:
diff changeset
3262
a61af66fc99e Initial load
duke
parents:
diff changeset
3263 void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3264 Label C, E;
a61af66fc99e Initial load
duke
parents:
diff changeset
3265 call(C, relocInfo::none);
a61af66fc99e Initial load
duke
parents:
diff changeset
3266 jmp(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3267
a61af66fc99e Initial load
duke
parents:
diff changeset
3268 bind(C);
a61af66fc99e Initial load
duke
parents:
diff changeset
3269 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3270 call_VM_helper(oop_result, entry_point, 1, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3271 ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3272
a61af66fc99e Initial load
duke
parents:
diff changeset
3273 bind(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3275
a61af66fc99e Initial load
duke
parents:
diff changeset
3276
a61af66fc99e Initial load
duke
parents:
diff changeset
3277 void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3278 Label C, E;
a61af66fc99e Initial load
duke
parents:
diff changeset
3279 call(C, relocInfo::none);
a61af66fc99e Initial load
duke
parents:
diff changeset
3280 jmp(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3281
a61af66fc99e Initial load
duke
parents:
diff changeset
3282 bind(C);
a61af66fc99e Initial load
duke
parents:
diff changeset
3283 pushl(arg_2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3284 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3285 call_VM_helper(oop_result, entry_point, 2, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3286 ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3287
a61af66fc99e Initial load
duke
parents:
diff changeset
3288 bind(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3290
a61af66fc99e Initial load
duke
parents:
diff changeset
3291
a61af66fc99e Initial load
duke
parents:
diff changeset
3292 void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3293 Label C, E;
a61af66fc99e Initial load
duke
parents:
diff changeset
3294 call(C, relocInfo::none);
a61af66fc99e Initial load
duke
parents:
diff changeset
3295 jmp(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3296
a61af66fc99e Initial load
duke
parents:
diff changeset
3297 bind(C);
a61af66fc99e Initial load
duke
parents:
diff changeset
3298 pushl(arg_3);
a61af66fc99e Initial load
duke
parents:
diff changeset
3299 pushl(arg_2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3300 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3301 call_VM_helper(oop_result, entry_point, 3, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3302 ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3303
a61af66fc99e Initial load
duke
parents:
diff changeset
3304 bind(E);
a61af66fc99e Initial load
duke
parents:
diff changeset
3305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3306
a61af66fc99e Initial load
duke
parents:
diff changeset
3307
a61af66fc99e Initial load
duke
parents:
diff changeset
3308 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, int number_of_arguments, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3309 call_VM_base(oop_result, noreg, last_java_sp, entry_point, number_of_arguments, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3310 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3311
a61af66fc99e Initial load
duke
parents:
diff changeset
3312
a61af66fc99e Initial load
duke
parents:
diff changeset
3313 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3314 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3315 call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3317
a61af66fc99e Initial load
duke
parents:
diff changeset
3318
a61af66fc99e Initial load
duke
parents:
diff changeset
3319 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3320 pushl(arg_2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3321 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3322 call_VM(oop_result, last_java_sp, entry_point, 2, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3323 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3324
a61af66fc99e Initial load
duke
parents:
diff changeset
3325
a61af66fc99e Initial load
duke
parents:
diff changeset
3326 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3327 pushl(arg_3);
a61af66fc99e Initial load
duke
parents:
diff changeset
3328 pushl(arg_2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3329 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3330 call_VM(oop_result, last_java_sp, entry_point, 3, check_exceptions);
a61af66fc99e Initial load
duke
parents:
diff changeset
3331 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3332
a61af66fc99e Initial load
duke
parents:
diff changeset
3333
a61af66fc99e Initial load
duke
parents:
diff changeset
3334 void MacroAssembler::call_VM_leaf(address entry_point, int number_of_arguments) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3335 call_VM_leaf_base(entry_point, number_of_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
3336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3337
a61af66fc99e Initial load
duke
parents:
diff changeset
3338
a61af66fc99e Initial load
duke
parents:
diff changeset
3339 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3340 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3341 call_VM_leaf(entry_point, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3342 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3343
a61af66fc99e Initial load
duke
parents:
diff changeset
3344
a61af66fc99e Initial load
duke
parents:
diff changeset
3345 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_1, Register arg_2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3346 pushl(arg_2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3347 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3348 call_VM_leaf(entry_point, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3350
a61af66fc99e Initial load
duke
parents:
diff changeset
3351
a61af66fc99e Initial load
duke
parents:
diff changeset
3352 void MacroAssembler::call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3353 pushl(arg_3);
a61af66fc99e Initial load
duke
parents:
diff changeset
3354 pushl(arg_2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3355 pushl(arg_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3356 call_VM_leaf(entry_point, 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
3357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3358
a61af66fc99e Initial load
duke
parents:
diff changeset
3359
a61af66fc99e Initial load
duke
parents:
diff changeset
3360 // Calls to C land
a61af66fc99e Initial load
duke
parents:
diff changeset
3361 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3362 // When entering C land, the rbp, & rsp of the last Java frame have to be recorded
a61af66fc99e Initial load
duke
parents:
diff changeset
3363 // in the (thread-local) JavaThread object. When leaving C land, the last Java fp
a61af66fc99e Initial load
duke
parents:
diff changeset
3364 // has to be reset to 0. This is required to allow proper stack traversal.
a61af66fc99e Initial load
duke
parents:
diff changeset
3365
a61af66fc99e Initial load
duke
parents:
diff changeset
3366 void MacroAssembler::store_check(Register obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3367 // Does a store check for the oop in register obj. The content of
a61af66fc99e Initial load
duke
parents:
diff changeset
3368 // register obj is destroyed afterwards.
a61af66fc99e Initial load
duke
parents:
diff changeset
3369 store_check_part_1(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
3370 store_check_part_2(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
3371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3372
a61af66fc99e Initial load
duke
parents:
diff changeset
3373
a61af66fc99e Initial load
duke
parents:
diff changeset
3374 void MacroAssembler::store_check(Register obj, Address dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3375 store_check(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
3376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3377
a61af66fc99e Initial load
duke
parents:
diff changeset
3378
a61af66fc99e Initial load
duke
parents:
diff changeset
3379 // split the store check operation so that other instructions can be scheduled inbetween
a61af66fc99e Initial load
duke
parents:
diff changeset
3380 void MacroAssembler::store_check_part_1(Register obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3381 BarrierSet* bs = Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
3382 assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
a61af66fc99e Initial load
duke
parents:
diff changeset
3383 shrl(obj, CardTableModRefBS::card_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
3384 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3385
a61af66fc99e Initial load
duke
parents:
diff changeset
3386
a61af66fc99e Initial load
duke
parents:
diff changeset
3387 void MacroAssembler::store_check_part_2(Register obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3388 BarrierSet* bs = Universe::heap()->barrier_set();
a61af66fc99e Initial load
duke
parents:
diff changeset
3389 assert(bs->kind() == BarrierSet::CardTableModRef, "Wrong barrier set kind");
a61af66fc99e Initial load
duke
parents:
diff changeset
3390 CardTableModRefBS* ct = (CardTableModRefBS*)bs;
a61af66fc99e Initial load
duke
parents:
diff changeset
3391 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
a61af66fc99e Initial load
duke
parents:
diff changeset
3392 ExternalAddress cardtable((address)ct->byte_map_base);
a61af66fc99e Initial load
duke
parents:
diff changeset
3393 Address index(noreg, obj, Address::times_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3394
a61af66fc99e Initial load
duke
parents:
diff changeset
3395 movb(as_Address(ArrayAddress(cardtable, index)), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3397
a61af66fc99e Initial load
duke
parents:
diff changeset
3398
a61af66fc99e Initial load
duke
parents:
diff changeset
3399 void MacroAssembler::c2bool(Register x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3400 // implements x == 0 ? 0 : 1
a61af66fc99e Initial load
duke
parents:
diff changeset
3401 // note: must only look at least-significant byte of x
a61af66fc99e Initial load
duke
parents:
diff changeset
3402 // since C-style booleans are stored in one byte
a61af66fc99e Initial load
duke
parents:
diff changeset
3403 // only! (was bug)
a61af66fc99e Initial load
duke
parents:
diff changeset
3404 andl(x, 0xFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
3405 setb(Assembler::notZero, x);
a61af66fc99e Initial load
duke
parents:
diff changeset
3406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3407
a61af66fc99e Initial load
duke
parents:
diff changeset
3408
a61af66fc99e Initial load
duke
parents:
diff changeset
3409 int MacroAssembler::corrected_idivl(Register reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3410 // Full implementation of Java idiv and irem; checks for
a61af66fc99e Initial load
duke
parents:
diff changeset
3411 // special case as described in JVM spec., p.243 & p.271.
a61af66fc99e Initial load
duke
parents:
diff changeset
3412 // The function returns the (pc) offset of the idivl
a61af66fc99e Initial load
duke
parents:
diff changeset
3413 // instruction - may be needed for implicit exceptions.
a61af66fc99e Initial load
duke
parents:
diff changeset
3414 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3415 // normal case special case
a61af66fc99e Initial load
duke
parents:
diff changeset
3416 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3417 // input : rax,: dividend min_int
a61af66fc99e Initial load
duke
parents:
diff changeset
3418 // reg: divisor (may not be rax,/rdx) -1
a61af66fc99e Initial load
duke
parents:
diff changeset
3419 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3420 // output: rax,: quotient (= rax, idiv reg) min_int
a61af66fc99e Initial load
duke
parents:
diff changeset
3421 // rdx: remainder (= rax, irem reg) 0
a61af66fc99e Initial load
duke
parents:
diff changeset
3422 assert(reg != rax && reg != rdx, "reg cannot be rax, or rdx register");
a61af66fc99e Initial load
duke
parents:
diff changeset
3423 const int min_int = 0x80000000;
a61af66fc99e Initial load
duke
parents:
diff changeset
3424 Label normal_case, special_case;
a61af66fc99e Initial load
duke
parents:
diff changeset
3425
a61af66fc99e Initial load
duke
parents:
diff changeset
3426 // check for special case
a61af66fc99e Initial load
duke
parents:
diff changeset
3427 cmpl(rax, min_int);
a61af66fc99e Initial load
duke
parents:
diff changeset
3428 jcc(Assembler::notEqual, normal_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
3429 xorl(rdx, rdx); // prepare rdx for possible special case (where remainder = 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
3430 cmpl(reg, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3431 jcc(Assembler::equal, special_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
3432
a61af66fc99e Initial load
duke
parents:
diff changeset
3433 // handle normal case
a61af66fc99e Initial load
duke
parents:
diff changeset
3434 bind(normal_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
3435 cdql();
a61af66fc99e Initial load
duke
parents:
diff changeset
3436 int idivl_offset = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
3437 idivl(reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
3438
a61af66fc99e Initial load
duke
parents:
diff changeset
3439 // normal and special case exit
a61af66fc99e Initial load
duke
parents:
diff changeset
3440 bind(special_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
3441
a61af66fc99e Initial load
duke
parents:
diff changeset
3442 return idivl_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
3443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3444
a61af66fc99e Initial load
duke
parents:
diff changeset
3445
a61af66fc99e Initial load
duke
parents:
diff changeset
3446 void MacroAssembler::lneg(Register hi, Register lo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3447 negl(lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
3448 adcl(hi, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3449 negl(hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3451
a61af66fc99e Initial load
duke
parents:
diff changeset
3452
a61af66fc99e Initial load
duke
parents:
diff changeset
3453 void MacroAssembler::lmul(int x_rsp_offset, int y_rsp_offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3454 // Multiplication of two Java long values stored on the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
3455 // as illustrated below. Result is in rdx:rax.
a61af66fc99e Initial load
duke
parents:
diff changeset
3456 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3457 // rsp ---> [ ?? ] \ \
a61af66fc99e Initial load
duke
parents:
diff changeset
3458 // .... | y_rsp_offset |
a61af66fc99e Initial load
duke
parents:
diff changeset
3459 // [ y_lo ] / (in bytes) | x_rsp_offset
a61af66fc99e Initial load
duke
parents:
diff changeset
3460 // [ y_hi ] | (in bytes)
a61af66fc99e Initial load
duke
parents:
diff changeset
3461 // .... |
a61af66fc99e Initial load
duke
parents:
diff changeset
3462 // [ x_lo ] /
a61af66fc99e Initial load
duke
parents:
diff changeset
3463 // [ x_hi ]
a61af66fc99e Initial load
duke
parents:
diff changeset
3464 // ....
a61af66fc99e Initial load
duke
parents:
diff changeset
3465 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3466 // Basic idea: lo(result) = lo(x_lo * y_lo)
a61af66fc99e Initial load
duke
parents:
diff changeset
3467 // hi(result) = hi(x_lo * y_lo) + lo(x_hi * y_lo) + lo(x_lo * y_hi)
a61af66fc99e Initial load
duke
parents:
diff changeset
3468 Address x_hi(rsp, x_rsp_offset + wordSize); Address x_lo(rsp, x_rsp_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
3469 Address y_hi(rsp, y_rsp_offset + wordSize); Address y_lo(rsp, y_rsp_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
3470 Label quick;
a61af66fc99e Initial load
duke
parents:
diff changeset
3471 // load x_hi, y_hi and check if quick
a61af66fc99e Initial load
duke
parents:
diff changeset
3472 // multiplication is possible
a61af66fc99e Initial load
duke
parents:
diff changeset
3473 movl(rbx, x_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3474 movl(rcx, y_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3475 movl(rax, rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
3476 orl(rbx, rcx); // rbx, = 0 <=> x_hi = 0 and y_hi = 0
a61af66fc99e Initial load
duke
parents:
diff changeset
3477 jcc(Assembler::zero, quick); // if rbx, = 0 do quick multiply
a61af66fc99e Initial load
duke
parents:
diff changeset
3478 // do full multiplication
a61af66fc99e Initial load
duke
parents:
diff changeset
3479 // 1st step
a61af66fc99e Initial load
duke
parents:
diff changeset
3480 mull(y_lo); // x_hi * y_lo
a61af66fc99e Initial load
duke
parents:
diff changeset
3481 movl(rbx, rax); // save lo(x_hi * y_lo) in rbx,
a61af66fc99e Initial load
duke
parents:
diff changeset
3482 // 2nd step
a61af66fc99e Initial load
duke
parents:
diff changeset
3483 movl(rax, x_lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
3484 mull(rcx); // x_lo * y_hi
a61af66fc99e Initial load
duke
parents:
diff changeset
3485 addl(rbx, rax); // add lo(x_lo * y_hi) to rbx,
a61af66fc99e Initial load
duke
parents:
diff changeset
3486 // 3rd step
a61af66fc99e Initial load
duke
parents:
diff changeset
3487 bind(quick); // note: rbx, = 0 if quick multiply!
a61af66fc99e Initial load
duke
parents:
diff changeset
3488 movl(rax, x_lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
3489 mull(y_lo); // x_lo * y_lo
a61af66fc99e Initial load
duke
parents:
diff changeset
3490 addl(rdx, rbx); // correct hi(x_lo * y_lo)
a61af66fc99e Initial load
duke
parents:
diff changeset
3491 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3492
a61af66fc99e Initial load
duke
parents:
diff changeset
3493
a61af66fc99e Initial load
duke
parents:
diff changeset
3494 void MacroAssembler::lshl(Register hi, Register lo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3495 // Java shift left long support (semantics as described in JVM spec., p.305)
a61af66fc99e Initial load
duke
parents:
diff changeset
3496 // (basic idea for shift counts s >= n: x << s == (x << n) << (s - n))
a61af66fc99e Initial load
duke
parents:
diff changeset
3497 // shift value is in rcx !
a61af66fc99e Initial load
duke
parents:
diff changeset
3498 assert(hi != rcx, "must not use rcx");
a61af66fc99e Initial load
duke
parents:
diff changeset
3499 assert(lo != rcx, "must not use rcx");
a61af66fc99e Initial load
duke
parents:
diff changeset
3500 const Register s = rcx; // shift count
a61af66fc99e Initial load
duke
parents:
diff changeset
3501 const int n = BitsPerWord;
a61af66fc99e Initial load
duke
parents:
diff changeset
3502 Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
3503 andl(s, 0x3f); // s := s & 0x3f (s < 0x40)
a61af66fc99e Initial load
duke
parents:
diff changeset
3504 cmpl(s, n); // if (s < n)
a61af66fc99e Initial load
duke
parents:
diff changeset
3505 jcc(Assembler::less, L); // else (s >= n)
a61af66fc99e Initial load
duke
parents:
diff changeset
3506 movl(hi, lo); // x := x << n
a61af66fc99e Initial load
duke
parents:
diff changeset
3507 xorl(lo, lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
3508 // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
a61af66fc99e Initial load
duke
parents:
diff changeset
3509 bind(L); // s (mod n) < n
a61af66fc99e Initial load
duke
parents:
diff changeset
3510 shldl(hi, lo); // x := x << s
a61af66fc99e Initial load
duke
parents:
diff changeset
3511 shll(lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
3512 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3513
a61af66fc99e Initial load
duke
parents:
diff changeset
3514
a61af66fc99e Initial load
duke
parents:
diff changeset
3515 void MacroAssembler::lshr(Register hi, Register lo, bool sign_extension) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3516 // Java shift right long support (semantics as described in JVM spec., p.306 & p.310)
a61af66fc99e Initial load
duke
parents:
diff changeset
3517 // (basic idea for shift counts s >= n: x >> s == (x >> n) >> (s - n))
a61af66fc99e Initial load
duke
parents:
diff changeset
3518 assert(hi != rcx, "must not use rcx");
a61af66fc99e Initial load
duke
parents:
diff changeset
3519 assert(lo != rcx, "must not use rcx");
a61af66fc99e Initial load
duke
parents:
diff changeset
3520 const Register s = rcx; // shift count
a61af66fc99e Initial load
duke
parents:
diff changeset
3521 const int n = BitsPerWord;
a61af66fc99e Initial load
duke
parents:
diff changeset
3522 Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
3523 andl(s, 0x3f); // s := s & 0x3f (s < 0x40)
a61af66fc99e Initial load
duke
parents:
diff changeset
3524 cmpl(s, n); // if (s < n)
a61af66fc99e Initial load
duke
parents:
diff changeset
3525 jcc(Assembler::less, L); // else (s >= n)
a61af66fc99e Initial load
duke
parents:
diff changeset
3526 movl(lo, hi); // x := x >> n
a61af66fc99e Initial load
duke
parents:
diff changeset
3527 if (sign_extension) sarl(hi, 31);
a61af66fc99e Initial load
duke
parents:
diff changeset
3528 else xorl(hi, hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3529 // Note: subl(s, n) is not needed since the Intel shift instructions work rcx mod n!
a61af66fc99e Initial load
duke
parents:
diff changeset
3530 bind(L); // s (mod n) < n
a61af66fc99e Initial load
duke
parents:
diff changeset
3531 shrdl(lo, hi); // x := x >> s
a61af66fc99e Initial load
duke
parents:
diff changeset
3532 if (sign_extension) sarl(hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3533 else shrl(hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3535
a61af66fc99e Initial load
duke
parents:
diff changeset
3536
a61af66fc99e Initial load
duke
parents:
diff changeset
3537 // Note: y_lo will be destroyed
a61af66fc99e Initial load
duke
parents:
diff changeset
3538 void MacroAssembler::lcmp2int(Register x_hi, Register x_lo, Register y_hi, Register y_lo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3539 // Long compare for Java (semantics as described in JVM spec.)
a61af66fc99e Initial load
duke
parents:
diff changeset
3540 Label high, low, done;
a61af66fc99e Initial load
duke
parents:
diff changeset
3541
a61af66fc99e Initial load
duke
parents:
diff changeset
3542 cmpl(x_hi, y_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3543 jcc(Assembler::less, low);
a61af66fc99e Initial load
duke
parents:
diff changeset
3544 jcc(Assembler::greater, high);
a61af66fc99e Initial load
duke
parents:
diff changeset
3545 // x_hi is the return register
a61af66fc99e Initial load
duke
parents:
diff changeset
3546 xorl(x_hi, x_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3547 cmpl(x_lo, y_lo);
a61af66fc99e Initial load
duke
parents:
diff changeset
3548 jcc(Assembler::below, low);
a61af66fc99e Initial load
duke
parents:
diff changeset
3549 jcc(Assembler::equal, done);
a61af66fc99e Initial load
duke
parents:
diff changeset
3550
a61af66fc99e Initial load
duke
parents:
diff changeset
3551 bind(high);
a61af66fc99e Initial load
duke
parents:
diff changeset
3552 xorl(x_hi, x_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3553 increment(x_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3554 jmp(done);
a61af66fc99e Initial load
duke
parents:
diff changeset
3555
a61af66fc99e Initial load
duke
parents:
diff changeset
3556 bind(low);
a61af66fc99e Initial load
duke
parents:
diff changeset
3557 xorl(x_hi, x_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3558 decrement(x_hi);
a61af66fc99e Initial load
duke
parents:
diff changeset
3559
a61af66fc99e Initial load
duke
parents:
diff changeset
3560 bind(done);
a61af66fc99e Initial load
duke
parents:
diff changeset
3561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3562
a61af66fc99e Initial load
duke
parents:
diff changeset
3563
a61af66fc99e Initial load
duke
parents:
diff changeset
3564 void MacroAssembler::save_rax(Register tmp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3565 if (tmp == noreg) pushl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3566 else if (tmp != rax) movl(tmp, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3567 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3568
a61af66fc99e Initial load
duke
parents:
diff changeset
3569
a61af66fc99e Initial load
duke
parents:
diff changeset
3570 void MacroAssembler::restore_rax(Register tmp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3571 if (tmp == noreg) popl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3572 else if (tmp != rax) movl(rax, tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3573 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3574
a61af66fc99e Initial load
duke
parents:
diff changeset
3575
a61af66fc99e Initial load
duke
parents:
diff changeset
3576 void MacroAssembler::fremr(Register tmp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3577 save_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3578 { Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
3579 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3580 fprem();
a61af66fc99e Initial load
duke
parents:
diff changeset
3581 fwait(); fnstsw_ax();
a61af66fc99e Initial load
duke
parents:
diff changeset
3582 sahf();
a61af66fc99e Initial load
duke
parents:
diff changeset
3583 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3585 restore_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3586 // Result is in ST0.
a61af66fc99e Initial load
duke
parents:
diff changeset
3587 // Note: fxch & fpop to get rid of ST1
a61af66fc99e Initial load
duke
parents:
diff changeset
3588 // (otherwise FPU stack could overflow eventually)
a61af66fc99e Initial load
duke
parents:
diff changeset
3589 fxch(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3590 fpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
3591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3592
a61af66fc99e Initial load
duke
parents:
diff changeset
3593
a61af66fc99e Initial load
duke
parents:
diff changeset
3594 static const double pi_4 = 0.7853981633974483;
a61af66fc99e Initial load
duke
parents:
diff changeset
3595
a61af66fc99e Initial load
duke
parents:
diff changeset
3596 void MacroAssembler::trigfunc(char trig, int num_fpu_regs_in_use) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3597 // A hand-coded argument reduction for values in fabs(pi/4, pi/2)
a61af66fc99e Initial load
duke
parents:
diff changeset
3598 // was attempted in this code; unfortunately it appears that the
a61af66fc99e Initial load
duke
parents:
diff changeset
3599 // switch to 80-bit precision and back causes this to be
a61af66fc99e Initial load
duke
parents:
diff changeset
3600 // unprofitable compared with simply performing a runtime call if
a61af66fc99e Initial load
duke
parents:
diff changeset
3601 // the argument is out of the (-pi/4, pi/4) range.
a61af66fc99e Initial load
duke
parents:
diff changeset
3602
a61af66fc99e Initial load
duke
parents:
diff changeset
3603 Register tmp = noreg;
a61af66fc99e Initial load
duke
parents:
diff changeset
3604 if (!VM_Version::supports_cmov()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3605 // fcmp needs a temporary so preserve rbx,
a61af66fc99e Initial load
duke
parents:
diff changeset
3606 tmp = rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
3607 pushl(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3608 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3609
a61af66fc99e Initial load
duke
parents:
diff changeset
3610 Label slow_case, done;
a61af66fc99e Initial load
duke
parents:
diff changeset
3611
a61af66fc99e Initial load
duke
parents:
diff changeset
3612 // x ?<= pi/4
a61af66fc99e Initial load
duke
parents:
diff changeset
3613 fld_d(ExternalAddress((address)&pi_4));
a61af66fc99e Initial load
duke
parents:
diff changeset
3614 fld_s(1); // Stack: X PI/4 X
a61af66fc99e Initial load
duke
parents:
diff changeset
3615 fabs(); // Stack: |X| PI/4 X
a61af66fc99e Initial load
duke
parents:
diff changeset
3616 fcmp(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3617 jcc(Assembler::above, slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
3618
a61af66fc99e Initial load
duke
parents:
diff changeset
3619 // fastest case: -pi/4 <= x <= pi/4
a61af66fc99e Initial load
duke
parents:
diff changeset
3620 switch(trig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3621 case 's':
a61af66fc99e Initial load
duke
parents:
diff changeset
3622 fsin();
a61af66fc99e Initial load
duke
parents:
diff changeset
3623 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3624 case 'c':
a61af66fc99e Initial load
duke
parents:
diff changeset
3625 fcos();
a61af66fc99e Initial load
duke
parents:
diff changeset
3626 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3627 case 't':
a61af66fc99e Initial load
duke
parents:
diff changeset
3628 ftan();
a61af66fc99e Initial load
duke
parents:
diff changeset
3629 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3630 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
3631 assert(false, "bad intrinsic");
a61af66fc99e Initial load
duke
parents:
diff changeset
3632 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3633 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3634 jmp(done);
a61af66fc99e Initial load
duke
parents:
diff changeset
3635
a61af66fc99e Initial load
duke
parents:
diff changeset
3636 // slow case: runtime call
a61af66fc99e Initial load
duke
parents:
diff changeset
3637 bind(slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
3638 // Preserve registers across runtime call
a61af66fc99e Initial load
duke
parents:
diff changeset
3639 pushad();
a61af66fc99e Initial load
duke
parents:
diff changeset
3640 int incoming_argument_and_return_value_offset = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
3641 if (num_fpu_regs_in_use > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3642 // Must preserve all other FPU regs (could alternatively convert
a61af66fc99e Initial load
duke
parents:
diff changeset
3643 // SharedRuntime::dsin and dcos into assembly routines known not to trash
a61af66fc99e Initial load
duke
parents:
diff changeset
3644 // FPU state, but can not trust C compiler)
a61af66fc99e Initial load
duke
parents:
diff changeset
3645 NEEDS_CLEANUP;
a61af66fc99e Initial load
duke
parents:
diff changeset
3646 // NOTE that in this case we also push the incoming argument to
a61af66fc99e Initial load
duke
parents:
diff changeset
3647 // the stack and restore it later; we also use this stack slot to
a61af66fc99e Initial load
duke
parents:
diff changeset
3648 // hold the return value from dsin or dcos.
a61af66fc99e Initial load
duke
parents:
diff changeset
3649 for (int i = 0; i < num_fpu_regs_in_use; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3650 subl(rsp, wordSize*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3651 fstp_d(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
3652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3653 incoming_argument_and_return_value_offset = 2*wordSize*(num_fpu_regs_in_use-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3654 fld_d(Address(rsp, incoming_argument_and_return_value_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
3655 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3656 subl(rsp, wordSize*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3657 fstp_d(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
3658 // NOTE: we must not use call_VM_leaf here because that requires a
a61af66fc99e Initial load
duke
parents:
diff changeset
3659 // complete interpreter frame in debug mode -- same bug as 4387334
a61af66fc99e Initial load
duke
parents:
diff changeset
3660 NEEDS_CLEANUP;
a61af66fc99e Initial load
duke
parents:
diff changeset
3661 // Need to add stack banging before this runtime call if it needs to
a61af66fc99e Initial load
duke
parents:
diff changeset
3662 // be taken; however, there is no generic stack banging routine at
a61af66fc99e Initial load
duke
parents:
diff changeset
3663 // the MacroAssembler level
a61af66fc99e Initial load
duke
parents:
diff changeset
3664 switch(trig) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3665 case 's':
a61af66fc99e Initial load
duke
parents:
diff changeset
3666 {
a61af66fc99e Initial load
duke
parents:
diff changeset
3667 call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dsin)));
a61af66fc99e Initial load
duke
parents:
diff changeset
3668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3669 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3670 case 'c':
a61af66fc99e Initial load
duke
parents:
diff changeset
3671 {
a61af66fc99e Initial load
duke
parents:
diff changeset
3672 call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dcos)));
a61af66fc99e Initial load
duke
parents:
diff changeset
3673 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3674 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3675 case 't':
a61af66fc99e Initial load
duke
parents:
diff changeset
3676 {
a61af66fc99e Initial load
duke
parents:
diff changeset
3677 call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtan)));
a61af66fc99e Initial load
duke
parents:
diff changeset
3678 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3679 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3680 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
3681 assert(false, "bad intrinsic");
a61af66fc99e Initial load
duke
parents:
diff changeset
3682 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
3683 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3684 addl(rsp, wordSize * 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3685 if (num_fpu_regs_in_use > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3686 // Must save return value to stack and then restore entire FPU stack
a61af66fc99e Initial load
duke
parents:
diff changeset
3687 fstp_d(Address(rsp, incoming_argument_and_return_value_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
3688 for (int i = 0; i < num_fpu_regs_in_use; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3689 fld_d(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
3690 addl(rsp, wordSize*2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3692 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3693 popad();
a61af66fc99e Initial load
duke
parents:
diff changeset
3694
a61af66fc99e Initial load
duke
parents:
diff changeset
3695 // Come here with result in F-TOS
a61af66fc99e Initial load
duke
parents:
diff changeset
3696 bind(done);
a61af66fc99e Initial load
duke
parents:
diff changeset
3697
a61af66fc99e Initial load
duke
parents:
diff changeset
3698 if (tmp != noreg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3699 popl(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3700 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3702
a61af66fc99e Initial load
duke
parents:
diff changeset
3703 void MacroAssembler::jC2(Register tmp, Label& L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3704 // set parity bit if FPU flag C2 is set (via rax)
a61af66fc99e Initial load
duke
parents:
diff changeset
3705 save_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3706 fwait(); fnstsw_ax();
a61af66fc99e Initial load
duke
parents:
diff changeset
3707 sahf();
a61af66fc99e Initial load
duke
parents:
diff changeset
3708 restore_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3709 // branch
a61af66fc99e Initial load
duke
parents:
diff changeset
3710 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3711 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3712
a61af66fc99e Initial load
duke
parents:
diff changeset
3713
a61af66fc99e Initial load
duke
parents:
diff changeset
3714 void MacroAssembler::jnC2(Register tmp, Label& L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3715 // set parity bit if FPU flag C2 is set (via rax)
a61af66fc99e Initial load
duke
parents:
diff changeset
3716 save_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3717 fwait(); fnstsw_ax();
a61af66fc99e Initial load
duke
parents:
diff changeset
3718 sahf();
a61af66fc99e Initial load
duke
parents:
diff changeset
3719 restore_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3720 // branch
a61af66fc99e Initial load
duke
parents:
diff changeset
3721 jcc(Assembler::noParity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3722 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3723
a61af66fc99e Initial load
duke
parents:
diff changeset
3724
a61af66fc99e Initial load
duke
parents:
diff changeset
3725 void MacroAssembler::fcmp(Register tmp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3726 fcmp(tmp, 1, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
3727 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3728
a61af66fc99e Initial load
duke
parents:
diff changeset
3729
a61af66fc99e Initial load
duke
parents:
diff changeset
3730 void MacroAssembler::fcmp(Register tmp, int index, bool pop_left, bool pop_right) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3731 assert(!pop_right || pop_left, "usage error");
a61af66fc99e Initial load
duke
parents:
diff changeset
3732 if (VM_Version::supports_cmov()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3733 assert(tmp == noreg, "unneeded temp");
a61af66fc99e Initial load
duke
parents:
diff changeset
3734 if (pop_left) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3735 fucomip(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
3736 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3737 fucomi(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
3738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3739 if (pop_right) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3740 fpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
3741 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3742 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3743 assert(tmp != noreg, "need temp");
a61af66fc99e Initial load
duke
parents:
diff changeset
3744 if (pop_left) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3745 if (pop_right) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3746 fcompp();
a61af66fc99e Initial load
duke
parents:
diff changeset
3747 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3748 fcomp(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
3749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3750 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3751 fcom(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
3752 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3753 // convert FPU condition into eflags condition via rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
3754 save_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3755 fwait(); fnstsw_ax();
a61af66fc99e Initial load
duke
parents:
diff changeset
3756 sahf();
a61af66fc99e Initial load
duke
parents:
diff changeset
3757 restore_rax(tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
3758 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3759 // condition codes set as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
3760 //
a61af66fc99e Initial load
duke
parents:
diff changeset
3761 // CF (corresponds to C0) if x < y
a61af66fc99e Initial load
duke
parents:
diff changeset
3762 // PF (corresponds to C2) if unordered
a61af66fc99e Initial load
duke
parents:
diff changeset
3763 // ZF (corresponds to C3) if x = y
a61af66fc99e Initial load
duke
parents:
diff changeset
3764 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3765
a61af66fc99e Initial load
duke
parents:
diff changeset
3766
a61af66fc99e Initial load
duke
parents:
diff changeset
3767 void MacroAssembler::fcmp2int(Register dst, bool unordered_is_less) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3768 fcmp2int(dst, unordered_is_less, 1, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
3769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3770
a61af66fc99e Initial load
duke
parents:
diff changeset
3771
a61af66fc99e Initial load
duke
parents:
diff changeset
3772 void MacroAssembler::fcmp2int(Register dst, bool unordered_is_less, int index, bool pop_left, bool pop_right) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3773 fcmp(VM_Version::supports_cmov() ? noreg : dst, index, pop_left, pop_right);
a61af66fc99e Initial load
duke
parents:
diff changeset
3774 Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
3775 if (unordered_is_less) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3776 movl(dst, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3777 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3778 jcc(Assembler::below , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3779 movl(dst, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3780 jcc(Assembler::equal , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3781 increment(dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3782 } else { // unordered is greater
a61af66fc99e Initial load
duke
parents:
diff changeset
3783 movl(dst, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3784 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3785 jcc(Assembler::above , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3786 movl(dst, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3787 jcc(Assembler::equal , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3788 decrement(dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3789 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3790 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3792
a61af66fc99e Initial load
duke
parents:
diff changeset
3793 void MacroAssembler::cmpss2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3794 ucomiss(opr1, opr2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3795
a61af66fc99e Initial load
duke
parents:
diff changeset
3796 Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
3797 if (unordered_is_less) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3798 movl(dst, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3799 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3800 jcc(Assembler::below , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3801 movl(dst, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3802 jcc(Assembler::equal , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3803 increment(dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3804 } else { // unordered is greater
a61af66fc99e Initial load
duke
parents:
diff changeset
3805 movl(dst, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3806 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3807 jcc(Assembler::above , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3808 movl(dst, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3809 jcc(Assembler::equal , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3810 decrement(dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3812 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3814
a61af66fc99e Initial load
duke
parents:
diff changeset
3815 void MacroAssembler::cmpsd2int(XMMRegister opr1, XMMRegister opr2, Register dst, bool unordered_is_less) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3816 ucomisd(opr1, opr2);
a61af66fc99e Initial load
duke
parents:
diff changeset
3817
a61af66fc99e Initial load
duke
parents:
diff changeset
3818 Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
3819 if (unordered_is_less) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3820 movl(dst, -1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3821 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3822 jcc(Assembler::below , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3823 movl(dst, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3824 jcc(Assembler::equal , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3825 increment(dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3826 } else { // unordered is greater
a61af66fc99e Initial load
duke
parents:
diff changeset
3827 movl(dst, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3828 jcc(Assembler::parity, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3829 jcc(Assembler::above , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3830 movl(dst, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
3831 jcc(Assembler::equal , L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3832 decrement(dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3834 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
3835 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3836
a61af66fc99e Initial load
duke
parents:
diff changeset
3837
a61af66fc99e Initial load
duke
parents:
diff changeset
3838
a61af66fc99e Initial load
duke
parents:
diff changeset
3839 void MacroAssembler::fpop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
3840 ffree();
a61af66fc99e Initial load
duke
parents:
diff changeset
3841 fincstp();
a61af66fc99e Initial load
duke
parents:
diff changeset
3842 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3843
a61af66fc99e Initial load
duke
parents:
diff changeset
3844
a61af66fc99e Initial load
duke
parents:
diff changeset
3845 void MacroAssembler::sign_extend_short(Register reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3846 if (VM_Version::is_P6()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3847 movsxw(reg, reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
3848 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3849 shll(reg, 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
3850 sarl(reg, 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
3851 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3852 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3853
a61af66fc99e Initial load
duke
parents:
diff changeset
3854
a61af66fc99e Initial load
duke
parents:
diff changeset
3855 void MacroAssembler::sign_extend_byte(Register reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3856 if (VM_Version::is_P6() && reg->has_byte_register()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3857 movsxb(reg, reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
3858 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3859 shll(reg, 24);
a61af66fc99e Initial load
duke
parents:
diff changeset
3860 sarl(reg, 24);
a61af66fc99e Initial load
duke
parents:
diff changeset
3861 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3862 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3863
a61af66fc99e Initial load
duke
parents:
diff changeset
3864
a61af66fc99e Initial load
duke
parents:
diff changeset
3865 void MacroAssembler::division_with_shift (Register reg, int shift_value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3866 assert (shift_value > 0, "illegal shift value");
a61af66fc99e Initial load
duke
parents:
diff changeset
3867 Label _is_positive;
a61af66fc99e Initial load
duke
parents:
diff changeset
3868 testl (reg, reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
3869 jcc (Assembler::positive, _is_positive);
a61af66fc99e Initial load
duke
parents:
diff changeset
3870 int offset = (1 << shift_value) - 1 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
3871
a61af66fc99e Initial load
duke
parents:
diff changeset
3872 increment(reg, offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
3873
a61af66fc99e Initial load
duke
parents:
diff changeset
3874 bind (_is_positive);
a61af66fc99e Initial load
duke
parents:
diff changeset
3875 sarl(reg, shift_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
3876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3877
a61af66fc99e Initial load
duke
parents:
diff changeset
3878
a61af66fc99e Initial load
duke
parents:
diff changeset
3879 void MacroAssembler::round_to(Register reg, int modulus) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3880 addl(reg, modulus - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
3881 andl(reg, -modulus);
a61af66fc99e Initial load
duke
parents:
diff changeset
3882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3883
a61af66fc99e Initial load
duke
parents:
diff changeset
3884 // C++ bool manipulation
a61af66fc99e Initial load
duke
parents:
diff changeset
3885
a61af66fc99e Initial load
duke
parents:
diff changeset
3886 void MacroAssembler::movbool(Register dst, Address src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3887 if(sizeof(bool) == 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
3888 movb(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3889 else if(sizeof(bool) == 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
3890 movw(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3891 else if(sizeof(bool) == 4)
a61af66fc99e Initial load
duke
parents:
diff changeset
3892 movl(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3893 else
a61af66fc99e Initial load
duke
parents:
diff changeset
3894 // unsupported
a61af66fc99e Initial load
duke
parents:
diff changeset
3895 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
3896 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3897
a61af66fc99e Initial load
duke
parents:
diff changeset
3898 void MacroAssembler::movbool(Address dst, bool boolconst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3899 if(sizeof(bool) == 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
3900 movb(dst, (int) boolconst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3901 else if(sizeof(bool) == 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
3902 movw(dst, (int) boolconst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3903 else if(sizeof(bool) == 4)
a61af66fc99e Initial load
duke
parents:
diff changeset
3904 movl(dst, (int) boolconst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3905 else
a61af66fc99e Initial load
duke
parents:
diff changeset
3906 // unsupported
a61af66fc99e Initial load
duke
parents:
diff changeset
3907 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
3908 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3909
a61af66fc99e Initial load
duke
parents:
diff changeset
3910 void MacroAssembler::movbool(Address dst, Register src) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3911 if(sizeof(bool) == 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
3912 movb(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3913 else if(sizeof(bool) == 2)
a61af66fc99e Initial load
duke
parents:
diff changeset
3914 movw(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3915 else if(sizeof(bool) == 4)
a61af66fc99e Initial load
duke
parents:
diff changeset
3916 movl(dst, src);
a61af66fc99e Initial load
duke
parents:
diff changeset
3917 else
a61af66fc99e Initial load
duke
parents:
diff changeset
3918 // unsupported
a61af66fc99e Initial load
duke
parents:
diff changeset
3919 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
3920 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3921
a61af66fc99e Initial load
duke
parents:
diff changeset
3922 void MacroAssembler::testbool(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3923 if(sizeof(bool) == 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
3924 testb(dst, (int) 0xff);
a61af66fc99e Initial load
duke
parents:
diff changeset
3925 else if(sizeof(bool) == 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3926 // testw implementation needed for two byte bools
a61af66fc99e Initial load
duke
parents:
diff changeset
3927 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
3928 } else if(sizeof(bool) == 4)
a61af66fc99e Initial load
duke
parents:
diff changeset
3929 testl(dst, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
3930 else
a61af66fc99e Initial load
duke
parents:
diff changeset
3931 // unsupported
a61af66fc99e Initial load
duke
parents:
diff changeset
3932 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
3933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3934
a61af66fc99e Initial load
duke
parents:
diff changeset
3935 void MacroAssembler::verify_oop(Register reg, const char* s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3936 if (!VerifyOops) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
3937 // Pass register number to verify_oop_subroutine
a61af66fc99e Initial load
duke
parents:
diff changeset
3938 char* b = new char[strlen(s) + 50];
a61af66fc99e Initial load
duke
parents:
diff changeset
3939 sprintf(b, "verify_oop: %s: %s", reg->name(), s);
a61af66fc99e Initial load
duke
parents:
diff changeset
3940 pushl(rax); // save rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
3941 pushl(reg); // pass register argument
a61af66fc99e Initial load
duke
parents:
diff changeset
3942 ExternalAddress buffer((address) b);
a61af66fc99e Initial load
duke
parents:
diff changeset
3943 pushptr(buffer.addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
3944 // call indirectly to solve generation ordering problem
a61af66fc99e Initial load
duke
parents:
diff changeset
3945 movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
a61af66fc99e Initial load
duke
parents:
diff changeset
3946 call(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3947 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3948
a61af66fc99e Initial load
duke
parents:
diff changeset
3949
a61af66fc99e Initial load
duke
parents:
diff changeset
3950 void MacroAssembler::verify_oop_addr(Address addr, const char* s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3951 if (!VerifyOops) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
3952 // QQQ fix this
a61af66fc99e Initial load
duke
parents:
diff changeset
3953 // Address adjust(addr.base(), addr.index(), addr.scale(), addr.disp() + BytesPerWord);
a61af66fc99e Initial load
duke
parents:
diff changeset
3954 // Pass register number to verify_oop_subroutine
a61af66fc99e Initial load
duke
parents:
diff changeset
3955 char* b = new char[strlen(s) + 50];
a61af66fc99e Initial load
duke
parents:
diff changeset
3956 sprintf(b, "verify_oop_addr: %s", s);
a61af66fc99e Initial load
duke
parents:
diff changeset
3957 pushl(rax); // save rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
3958 // addr may contain rsp so we will have to adjust it based on the push
a61af66fc99e Initial load
duke
parents:
diff changeset
3959 // we just did
a61af66fc99e Initial load
duke
parents:
diff changeset
3960 if (addr.uses(rsp)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3961 leal(rax, addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
3962 pushl(Address(rax, BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
3963 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
3964 pushl(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
3965 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3966 ExternalAddress buffer((address) b);
a61af66fc99e Initial load
duke
parents:
diff changeset
3967 // pass msg argument
a61af66fc99e Initial load
duke
parents:
diff changeset
3968 pushptr(buffer.addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
3969 // call indirectly to solve generation ordering problem
a61af66fc99e Initial load
duke
parents:
diff changeset
3970 movptr(rax, ExternalAddress(StubRoutines::verify_oop_subroutine_entry_address()));
a61af66fc99e Initial load
duke
parents:
diff changeset
3971 call(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
3972 // Caller pops the arguments and restores rax, from the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
3973 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3974
a61af66fc99e Initial load
duke
parents:
diff changeset
3975
a61af66fc99e Initial load
duke
parents:
diff changeset
3976 void MacroAssembler::stop(const char* msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3977 ExternalAddress message((address)msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
3978 // push address of message
a61af66fc99e Initial load
duke
parents:
diff changeset
3979 pushptr(message.addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
3980 { Label L; call(L, relocInfo::none); bind(L); } // push eip
a61af66fc99e Initial load
duke
parents:
diff changeset
3981 pushad(); // push registers
a61af66fc99e Initial load
duke
parents:
diff changeset
3982 call(RuntimeAddress(CAST_FROM_FN_PTR(address, MacroAssembler::debug)));
a61af66fc99e Initial load
duke
parents:
diff changeset
3983 hlt();
a61af66fc99e Initial load
duke
parents:
diff changeset
3984 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3985
a61af66fc99e Initial load
duke
parents:
diff changeset
3986
a61af66fc99e Initial load
duke
parents:
diff changeset
3987 void MacroAssembler::warn(const char* msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
3988 push_CPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
3989
a61af66fc99e Initial load
duke
parents:
diff changeset
3990 ExternalAddress message((address) msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
3991 // push address of message
a61af66fc99e Initial load
duke
parents:
diff changeset
3992 pushptr(message.addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
3993
a61af66fc99e Initial load
duke
parents:
diff changeset
3994 call(RuntimeAddress(CAST_FROM_FN_PTR(address, warning)));
a61af66fc99e Initial load
duke
parents:
diff changeset
3995 addl(rsp, wordSize); // discard argument
a61af66fc99e Initial load
duke
parents:
diff changeset
3996 pop_CPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
3997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
3998
a61af66fc99e Initial load
duke
parents:
diff changeset
3999
a61af66fc99e Initial load
duke
parents:
diff changeset
4000 void MacroAssembler::debug(int rdi, int rsi, int rbp, int rsp, int rbx, int rdx, int rcx, int rax, int eip, char* msg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4001 // In order to get locks to work, we need to fake a in_VM state
a61af66fc99e Initial load
duke
parents:
diff changeset
4002 JavaThread* thread = JavaThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
4003 JavaThreadState saved_state = thread->thread_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4004 thread->set_thread_state(_thread_in_vm);
a61af66fc99e Initial load
duke
parents:
diff changeset
4005 if (ShowMessageBoxOnError) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4006 JavaThread* thread = JavaThread::current();
a61af66fc99e Initial load
duke
parents:
diff changeset
4007 JavaThreadState saved_state = thread->thread_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4008 thread->set_thread_state(_thread_in_vm);
a61af66fc99e Initial load
duke
parents:
diff changeset
4009 ttyLocker ttyl;
a61af66fc99e Initial load
duke
parents:
diff changeset
4010 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4011 BytecodeCounter::print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4012 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4013 // To see where a verify_oop failed, get $ebx+40/X for this frame.
a61af66fc99e Initial load
duke
parents:
diff changeset
4014 // This is the value of eip which points to where verify_oop will return.
a61af66fc99e Initial load
duke
parents:
diff changeset
4015 if (os::message_box(msg, "Execution stopped, print registers?")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4016 tty->print_cr("eip = 0x%08x", eip);
a61af66fc99e Initial load
duke
parents:
diff changeset
4017 tty->print_cr("rax, = 0x%08x", rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
4018 tty->print_cr("rbx, = 0x%08x", rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4019 tty->print_cr("rcx = 0x%08x", rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4020 tty->print_cr("rdx = 0x%08x", rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4021 tty->print_cr("rdi = 0x%08x", rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
4022 tty->print_cr("rsi = 0x%08x", rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
4023 tty->print_cr("rbp, = 0x%08x", rbp);
a61af66fc99e Initial load
duke
parents:
diff changeset
4024 tty->print_cr("rsp = 0x%08x", rsp);
a61af66fc99e Initial load
duke
parents:
diff changeset
4025 BREAKPOINT;
a61af66fc99e Initial load
duke
parents:
diff changeset
4026 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4027 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4028 ::tty->print_cr("=============== DEBUG MESSAGE: %s ================\n", msg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4029 assert(false, "DEBUG MESSAGE");
a61af66fc99e Initial load
duke
parents:
diff changeset
4030 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4031 ThreadStateTransition::transition(thread, _thread_in_vm, saved_state);
a61af66fc99e Initial load
duke
parents:
diff changeset
4032 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4033
a61af66fc99e Initial load
duke
parents:
diff changeset
4034
a61af66fc99e Initial load
duke
parents:
diff changeset
4035
a61af66fc99e Initial load
duke
parents:
diff changeset
4036 void MacroAssembler::os_breakpoint() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4037 // instead of directly emitting a breakpoint, call os:breakpoint for better debugability
a61af66fc99e Initial load
duke
parents:
diff changeset
4038 // (e.g., MSVC can't call ps() otherwise)
a61af66fc99e Initial load
duke
parents:
diff changeset
4039 call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
a61af66fc99e Initial load
duke
parents:
diff changeset
4040 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4041
a61af66fc99e Initial load
duke
parents:
diff changeset
4042
a61af66fc99e Initial load
duke
parents:
diff changeset
4043 void MacroAssembler::push_fTOS() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4044 subl(rsp, 2 * wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4045 fstp_d(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
4046 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4047
a61af66fc99e Initial load
duke
parents:
diff changeset
4048
a61af66fc99e Initial load
duke
parents:
diff changeset
4049 void MacroAssembler::pop_fTOS() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4050 fld_d(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
4051 addl(rsp, 2 * wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4053
a61af66fc99e Initial load
duke
parents:
diff changeset
4054
a61af66fc99e Initial load
duke
parents:
diff changeset
4055 void MacroAssembler::empty_FPU_stack() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4056 if (VM_Version::supports_mmx()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4057 emms();
a61af66fc99e Initial load
duke
parents:
diff changeset
4058 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4059 for (int i = 8; i-- > 0; ) ffree(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
4060 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4062
a61af66fc99e Initial load
duke
parents:
diff changeset
4063
a61af66fc99e Initial load
duke
parents:
diff changeset
4064 class ControlWord {
a61af66fc99e Initial load
duke
parents:
diff changeset
4065 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4066 int32_t _value;
a61af66fc99e Initial load
duke
parents:
diff changeset
4067
a61af66fc99e Initial load
duke
parents:
diff changeset
4068 int rounding_control() const { return (_value >> 10) & 3 ; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4069 int precision_control() const { return (_value >> 8) & 3 ; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4070 bool precision() const { return ((_value >> 5) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4071 bool underflow() const { return ((_value >> 4) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4072 bool overflow() const { return ((_value >> 3) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4073 bool zero_divide() const { return ((_value >> 2) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4074 bool denormalized() const { return ((_value >> 1) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4075 bool invalid() const { return ((_value >> 0) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4076
a61af66fc99e Initial load
duke
parents:
diff changeset
4077 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4078 // rounding control
a61af66fc99e Initial load
duke
parents:
diff changeset
4079 const char* rc;
a61af66fc99e Initial load
duke
parents:
diff changeset
4080 switch (rounding_control()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4081 case 0: rc = "round near"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4082 case 1: rc = "round down"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4083 case 2: rc = "round up "; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4084 case 3: rc = "chop "; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4085 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4086 // precision control
a61af66fc99e Initial load
duke
parents:
diff changeset
4087 const char* pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
4088 switch (precision_control()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4089 case 0: pc = "24 bits "; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4090 case 1: pc = "reserved"; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4091 case 2: pc = "53 bits "; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4092 case 3: pc = "64 bits "; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
4093 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4094 // flags
a61af66fc99e Initial load
duke
parents:
diff changeset
4095 char f[9];
a61af66fc99e Initial load
duke
parents:
diff changeset
4096 f[0] = ' ';
a61af66fc99e Initial load
duke
parents:
diff changeset
4097 f[1] = ' ';
a61af66fc99e Initial load
duke
parents:
diff changeset
4098 f[2] = (precision ()) ? 'P' : 'p';
a61af66fc99e Initial load
duke
parents:
diff changeset
4099 f[3] = (underflow ()) ? 'U' : 'u';
a61af66fc99e Initial load
duke
parents:
diff changeset
4100 f[4] = (overflow ()) ? 'O' : 'o';
a61af66fc99e Initial load
duke
parents:
diff changeset
4101 f[5] = (zero_divide ()) ? 'Z' : 'z';
a61af66fc99e Initial load
duke
parents:
diff changeset
4102 f[6] = (denormalized()) ? 'D' : 'd';
a61af66fc99e Initial load
duke
parents:
diff changeset
4103 f[7] = (invalid ()) ? 'I' : 'i';
a61af66fc99e Initial load
duke
parents:
diff changeset
4104 f[8] = '\x0';
a61af66fc99e Initial load
duke
parents:
diff changeset
4105 // output
a61af66fc99e Initial load
duke
parents:
diff changeset
4106 printf("%04x masks = %s, %s, %s", _value & 0xFFFF, f, rc, pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
4107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4108
a61af66fc99e Initial load
duke
parents:
diff changeset
4109 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4110
a61af66fc99e Initial load
duke
parents:
diff changeset
4111
a61af66fc99e Initial load
duke
parents:
diff changeset
4112 class StatusWord {
a61af66fc99e Initial load
duke
parents:
diff changeset
4113 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4114 int32_t _value;
a61af66fc99e Initial load
duke
parents:
diff changeset
4115
a61af66fc99e Initial load
duke
parents:
diff changeset
4116 bool busy() const { return ((_value >> 15) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4117 bool C3() const { return ((_value >> 14) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4118 bool C2() const { return ((_value >> 10) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4119 bool C1() const { return ((_value >> 9) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4120 bool C0() const { return ((_value >> 8) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4121 int top() const { return (_value >> 11) & 7 ; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4122 bool error_status() const { return ((_value >> 7) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4123 bool stack_fault() const { return ((_value >> 6) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4124 bool precision() const { return ((_value >> 5) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4125 bool underflow() const { return ((_value >> 4) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4126 bool overflow() const { return ((_value >> 3) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4127 bool zero_divide() const { return ((_value >> 2) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4128 bool denormalized() const { return ((_value >> 1) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4129 bool invalid() const { return ((_value >> 0) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4130
a61af66fc99e Initial load
duke
parents:
diff changeset
4131 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4132 // condition codes
a61af66fc99e Initial load
duke
parents:
diff changeset
4133 char c[5];
a61af66fc99e Initial load
duke
parents:
diff changeset
4134 c[0] = (C3()) ? '3' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4135 c[1] = (C2()) ? '2' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4136 c[2] = (C1()) ? '1' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4137 c[3] = (C0()) ? '0' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4138 c[4] = '\x0';
a61af66fc99e Initial load
duke
parents:
diff changeset
4139 // flags
a61af66fc99e Initial load
duke
parents:
diff changeset
4140 char f[9];
a61af66fc99e Initial load
duke
parents:
diff changeset
4141 f[0] = (error_status()) ? 'E' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4142 f[1] = (stack_fault ()) ? 'S' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4143 f[2] = (precision ()) ? 'P' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4144 f[3] = (underflow ()) ? 'U' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4145 f[4] = (overflow ()) ? 'O' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4146 f[5] = (zero_divide ()) ? 'Z' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4147 f[6] = (denormalized()) ? 'D' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4148 f[7] = (invalid ()) ? 'I' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4149 f[8] = '\x0';
a61af66fc99e Initial load
duke
parents:
diff changeset
4150 // output
a61af66fc99e Initial load
duke
parents:
diff changeset
4151 printf("%04x flags = %s, cc = %s, top = %d", _value & 0xFFFF, f, c, top());
a61af66fc99e Initial load
duke
parents:
diff changeset
4152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4153
a61af66fc99e Initial load
duke
parents:
diff changeset
4154 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4155
a61af66fc99e Initial load
duke
parents:
diff changeset
4156
a61af66fc99e Initial load
duke
parents:
diff changeset
4157 class TagWord {
a61af66fc99e Initial load
duke
parents:
diff changeset
4158 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4159 int32_t _value;
a61af66fc99e Initial load
duke
parents:
diff changeset
4160
a61af66fc99e Initial load
duke
parents:
diff changeset
4161 int tag_at(int i) const { return (_value >> (i*2)) & 3; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4162
a61af66fc99e Initial load
duke
parents:
diff changeset
4163 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4164 printf("%04x", _value & 0xFFFF);
a61af66fc99e Initial load
duke
parents:
diff changeset
4165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4166
a61af66fc99e Initial load
duke
parents:
diff changeset
4167 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4168
a61af66fc99e Initial load
duke
parents:
diff changeset
4169
a61af66fc99e Initial load
duke
parents:
diff changeset
4170 class FPU_Register {
a61af66fc99e Initial load
duke
parents:
diff changeset
4171 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4172 int32_t _m0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4173 int32_t _m1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4174 int16_t _ex;
a61af66fc99e Initial load
duke
parents:
diff changeset
4175
a61af66fc99e Initial load
duke
parents:
diff changeset
4176 bool is_indefinite() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4177 return _ex == -1 && _m1 == (int32_t)0xC0000000 && _m0 == 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4179
a61af66fc99e Initial load
duke
parents:
diff changeset
4180 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4181 char sign = (_ex < 0) ? '-' : '+';
a61af66fc99e Initial load
duke
parents:
diff changeset
4182 const char* kind = (_ex == 0x7FFF || _ex == (int16_t)-1) ? "NaN" : " ";
a61af66fc99e Initial load
duke
parents:
diff changeset
4183 printf("%c%04hx.%08x%08x %s", sign, _ex, _m1, _m0, kind);
a61af66fc99e Initial load
duke
parents:
diff changeset
4184 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4185
a61af66fc99e Initial load
duke
parents:
diff changeset
4186 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4187
a61af66fc99e Initial load
duke
parents:
diff changeset
4188
a61af66fc99e Initial load
duke
parents:
diff changeset
4189 class FPU_State {
a61af66fc99e Initial load
duke
parents:
diff changeset
4190 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4191 enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
4192 register_size = 10,
a61af66fc99e Initial load
duke
parents:
diff changeset
4193 number_of_registers = 8,
a61af66fc99e Initial load
duke
parents:
diff changeset
4194 register_mask = 7
a61af66fc99e Initial load
duke
parents:
diff changeset
4195 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4196
a61af66fc99e Initial load
duke
parents:
diff changeset
4197 ControlWord _control_word;
a61af66fc99e Initial load
duke
parents:
diff changeset
4198 StatusWord _status_word;
a61af66fc99e Initial load
duke
parents:
diff changeset
4199 TagWord _tag_word;
a61af66fc99e Initial load
duke
parents:
diff changeset
4200 int32_t _error_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
4201 int32_t _error_selector;
a61af66fc99e Initial load
duke
parents:
diff changeset
4202 int32_t _data_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
4203 int32_t _data_selector;
a61af66fc99e Initial load
duke
parents:
diff changeset
4204 int8_t _register[register_size * number_of_registers];
a61af66fc99e Initial load
duke
parents:
diff changeset
4205
a61af66fc99e Initial load
duke
parents:
diff changeset
4206 int tag_for_st(int i) const { return _tag_word.tag_at((_status_word.top() + i) & register_mask); }
a61af66fc99e Initial load
duke
parents:
diff changeset
4207 FPU_Register* st(int i) const { return (FPU_Register*)&_register[register_size * i]; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4208
a61af66fc99e Initial load
duke
parents:
diff changeset
4209 const char* tag_as_string(int tag) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4210 switch (tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4211 case 0: return "valid";
a61af66fc99e Initial load
duke
parents:
diff changeset
4212 case 1: return "zero";
a61af66fc99e Initial load
duke
parents:
diff changeset
4213 case 2: return "special";
a61af66fc99e Initial load
duke
parents:
diff changeset
4214 case 3: return "empty";
a61af66fc99e Initial load
duke
parents:
diff changeset
4215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4216 ShouldNotReachHere()
a61af66fc99e Initial load
duke
parents:
diff changeset
4217 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
4218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4219
a61af66fc99e Initial load
duke
parents:
diff changeset
4220 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4221 // print computation registers
a61af66fc99e Initial load
duke
parents:
diff changeset
4222 { int t = _status_word.top();
a61af66fc99e Initial load
duke
parents:
diff changeset
4223 for (int i = 0; i < number_of_registers; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4224 int j = (i - t) & register_mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
4225 printf("%c r%d = ST%d = ", (j == 0 ? '*' : ' '), i, j);
a61af66fc99e Initial load
duke
parents:
diff changeset
4226 st(j)->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4227 printf(" %s\n", tag_as_string(_tag_word.tag_at(i)));
a61af66fc99e Initial load
duke
parents:
diff changeset
4228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4230 printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4231 // print control registers
a61af66fc99e Initial load
duke
parents:
diff changeset
4232 printf("ctrl = "); _control_word.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4233 printf("stat = "); _status_word .print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4234 printf("tags = "); _tag_word .print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4236
a61af66fc99e Initial load
duke
parents:
diff changeset
4237 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4238
a61af66fc99e Initial load
duke
parents:
diff changeset
4239
a61af66fc99e Initial load
duke
parents:
diff changeset
4240 class Flag_Register {
a61af66fc99e Initial load
duke
parents:
diff changeset
4241 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4242 int32_t _value;
a61af66fc99e Initial load
duke
parents:
diff changeset
4243
a61af66fc99e Initial load
duke
parents:
diff changeset
4244 bool overflow() const { return ((_value >> 11) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4245 bool direction() const { return ((_value >> 10) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4246 bool sign() const { return ((_value >> 7) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4247 bool zero() const { return ((_value >> 6) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4248 bool auxiliary_carry() const { return ((_value >> 4) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4249 bool parity() const { return ((_value >> 2) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4250 bool carry() const { return ((_value >> 0) & 1) != 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
4251
a61af66fc99e Initial load
duke
parents:
diff changeset
4252 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4253 // flags
a61af66fc99e Initial load
duke
parents:
diff changeset
4254 char f[8];
a61af66fc99e Initial load
duke
parents:
diff changeset
4255 f[0] = (overflow ()) ? 'O' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4256 f[1] = (direction ()) ? 'D' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4257 f[2] = (sign ()) ? 'S' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4258 f[3] = (zero ()) ? 'Z' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4259 f[4] = (auxiliary_carry()) ? 'A' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4260 f[5] = (parity ()) ? 'P' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4261 f[6] = (carry ()) ? 'C' : '-';
a61af66fc99e Initial load
duke
parents:
diff changeset
4262 f[7] = '\x0';
a61af66fc99e Initial load
duke
parents:
diff changeset
4263 // output
a61af66fc99e Initial load
duke
parents:
diff changeset
4264 printf("%08x flags = %s", _value, f);
a61af66fc99e Initial load
duke
parents:
diff changeset
4265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4266
a61af66fc99e Initial load
duke
parents:
diff changeset
4267 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4268
a61af66fc99e Initial load
duke
parents:
diff changeset
4269
a61af66fc99e Initial load
duke
parents:
diff changeset
4270 class IU_Register {
a61af66fc99e Initial load
duke
parents:
diff changeset
4271 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4272 int32_t _value;
a61af66fc99e Initial load
duke
parents:
diff changeset
4273
a61af66fc99e Initial load
duke
parents:
diff changeset
4274 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4275 printf("%08x %11d", _value, _value);
a61af66fc99e Initial load
duke
parents:
diff changeset
4276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4277
a61af66fc99e Initial load
duke
parents:
diff changeset
4278 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4279
a61af66fc99e Initial load
duke
parents:
diff changeset
4280
a61af66fc99e Initial load
duke
parents:
diff changeset
4281 class IU_State {
a61af66fc99e Initial load
duke
parents:
diff changeset
4282 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4283 Flag_Register _eflags;
a61af66fc99e Initial load
duke
parents:
diff changeset
4284 IU_Register _rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
4285 IU_Register _rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
4286 IU_Register _rbp;
a61af66fc99e Initial load
duke
parents:
diff changeset
4287 IU_Register _rsp;
a61af66fc99e Initial load
duke
parents:
diff changeset
4288 IU_Register _rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
4289 IU_Register _rdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
4290 IU_Register _rcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
4291 IU_Register _rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
4292
a61af66fc99e Initial load
duke
parents:
diff changeset
4293 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4294 // computation registers
a61af66fc99e Initial load
duke
parents:
diff changeset
4295 printf("rax, = "); _rax.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4296 printf("rbx, = "); _rbx.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4297 printf("rcx = "); _rcx.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4298 printf("rdx = "); _rdx.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4299 printf("rdi = "); _rdi.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4300 printf("rsi = "); _rsi.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4301 printf("rbp, = "); _rbp.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4302 printf("rsp = "); _rsp.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4303 printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4304 // control registers
a61af66fc99e Initial load
duke
parents:
diff changeset
4305 printf("flgs = "); _eflags.print(); printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4307 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4308
a61af66fc99e Initial load
duke
parents:
diff changeset
4309
a61af66fc99e Initial load
duke
parents:
diff changeset
4310 class CPU_State {
a61af66fc99e Initial load
duke
parents:
diff changeset
4311 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
4312 FPU_State _fpu_state;
a61af66fc99e Initial load
duke
parents:
diff changeset
4313 IU_State _iu_state;
a61af66fc99e Initial load
duke
parents:
diff changeset
4314
a61af66fc99e Initial load
duke
parents:
diff changeset
4315 void print() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
4316 printf("--------------------------------------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4317 _iu_state .print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4318 printf("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4319 _fpu_state.print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4320 printf("--------------------------------------------------\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4322
a61af66fc99e Initial load
duke
parents:
diff changeset
4323 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4324
a61af66fc99e Initial load
duke
parents:
diff changeset
4325
a61af66fc99e Initial load
duke
parents:
diff changeset
4326 static void _print_CPU_state(CPU_State* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4327 state->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4328 };
a61af66fc99e Initial load
duke
parents:
diff changeset
4329
a61af66fc99e Initial load
duke
parents:
diff changeset
4330
a61af66fc99e Initial load
duke
parents:
diff changeset
4331 void MacroAssembler::print_CPU_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4332 push_CPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4333 pushl(rsp); // pass CPU state
a61af66fc99e Initial load
duke
parents:
diff changeset
4334 call(RuntimeAddress(CAST_FROM_FN_PTR(address, _print_CPU_state)));
a61af66fc99e Initial load
duke
parents:
diff changeset
4335 addl(rsp, wordSize); // discard argument
a61af66fc99e Initial load
duke
parents:
diff changeset
4336 pop_CPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4338
a61af66fc99e Initial load
duke
parents:
diff changeset
4339
a61af66fc99e Initial load
duke
parents:
diff changeset
4340 static bool _verify_FPU(int stack_depth, char* s, CPU_State* state) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4341 static int counter = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4342 FPU_State* fs = &state->_fpu_state;
a61af66fc99e Initial load
duke
parents:
diff changeset
4343 counter++;
a61af66fc99e Initial load
duke
parents:
diff changeset
4344 // For leaf calls, only verify that the top few elements remain empty.
a61af66fc99e Initial load
duke
parents:
diff changeset
4345 // We only need 1 empty at the top for C2 code.
a61af66fc99e Initial load
duke
parents:
diff changeset
4346 if( stack_depth < 0 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4347 if( fs->tag_for_st(7) != 3 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4348 printf("FPR7 not empty\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
4349 state->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4350 assert(false, "error");
a61af66fc99e Initial load
duke
parents:
diff changeset
4351 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4353 return true; // All other stack states do not matter
a61af66fc99e Initial load
duke
parents:
diff changeset
4354 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4355
a61af66fc99e Initial load
duke
parents:
diff changeset
4356 assert((fs->_control_word._value & 0xffff) == StubRoutines::_fpu_cntrl_wrd_std,
a61af66fc99e Initial load
duke
parents:
diff changeset
4357 "bad FPU control word");
a61af66fc99e Initial load
duke
parents:
diff changeset
4358
a61af66fc99e Initial load
duke
parents:
diff changeset
4359 // compute stack depth
a61af66fc99e Initial load
duke
parents:
diff changeset
4360 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
4361 while (i < FPU_State::number_of_registers && fs->tag_for_st(i) < 3) i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
4362 int d = i;
a61af66fc99e Initial load
duke
parents:
diff changeset
4363 while (i < FPU_State::number_of_registers && fs->tag_for_st(i) == 3) i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
4364 // verify findings
a61af66fc99e Initial load
duke
parents:
diff changeset
4365 if (i != FPU_State::number_of_registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4366 // stack not contiguous
a61af66fc99e Initial load
duke
parents:
diff changeset
4367 printf("%s: stack not contiguous at ST%d\n", s, i);
a61af66fc99e Initial load
duke
parents:
diff changeset
4368 state->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4369 assert(false, "error");
a61af66fc99e Initial load
duke
parents:
diff changeset
4370 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4372 // check if computed stack depth corresponds to expected stack depth
a61af66fc99e Initial load
duke
parents:
diff changeset
4373 if (stack_depth < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4374 // expected stack depth is -stack_depth or less
a61af66fc99e Initial load
duke
parents:
diff changeset
4375 if (d > -stack_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4376 // too many elements on the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
4377 printf("%s: <= %d stack elements expected but found %d\n", s, -stack_depth, d);
a61af66fc99e Initial load
duke
parents:
diff changeset
4378 state->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4379 assert(false, "error");
a61af66fc99e Initial load
duke
parents:
diff changeset
4380 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4382 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4383 // expected stack depth is stack_depth
a61af66fc99e Initial load
duke
parents:
diff changeset
4384 if (d != stack_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4385 // wrong stack depth
a61af66fc99e Initial load
duke
parents:
diff changeset
4386 printf("%s: %d stack elements expected but found %d\n", s, stack_depth, d);
a61af66fc99e Initial load
duke
parents:
diff changeset
4387 state->print();
a61af66fc99e Initial load
duke
parents:
diff changeset
4388 assert(false, "error");
a61af66fc99e Initial load
duke
parents:
diff changeset
4389 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4390 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4392 // everything is cool
a61af66fc99e Initial load
duke
parents:
diff changeset
4393 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
4394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4395
a61af66fc99e Initial load
duke
parents:
diff changeset
4396
a61af66fc99e Initial load
duke
parents:
diff changeset
4397 void MacroAssembler::verify_FPU(int stack_depth, const char* s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4398 if (!VerifyFPU) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
4399 push_CPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4400 pushl(rsp); // pass CPU state
a61af66fc99e Initial load
duke
parents:
diff changeset
4401 ExternalAddress msg((address) s);
a61af66fc99e Initial load
duke
parents:
diff changeset
4402 // pass message string s
a61af66fc99e Initial load
duke
parents:
diff changeset
4403 pushptr(msg.addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
4404 pushl(stack_depth); // pass stack depth
a61af66fc99e Initial load
duke
parents:
diff changeset
4405 call(RuntimeAddress(CAST_FROM_FN_PTR(address, _verify_FPU)));
a61af66fc99e Initial load
duke
parents:
diff changeset
4406 addl(rsp, 3 * wordSize); // discard arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
4407 // check for error
a61af66fc99e Initial load
duke
parents:
diff changeset
4408 { Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
4409 testl(rax, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
4410 jcc(Assembler::notZero, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
4411 int3(); // break if error condition
a61af66fc99e Initial load
duke
parents:
diff changeset
4412 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
4413 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4414 pop_CPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4416
a61af66fc99e Initial load
duke
parents:
diff changeset
4417
a61af66fc99e Initial load
duke
parents:
diff changeset
4418 void MacroAssembler::push_IU_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4419 pushad();
a61af66fc99e Initial load
duke
parents:
diff changeset
4420 pushfd();
a61af66fc99e Initial load
duke
parents:
diff changeset
4421 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4422
a61af66fc99e Initial load
duke
parents:
diff changeset
4423
a61af66fc99e Initial load
duke
parents:
diff changeset
4424 void MacroAssembler::pop_IU_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4425 popfd();
a61af66fc99e Initial load
duke
parents:
diff changeset
4426 popad();
a61af66fc99e Initial load
duke
parents:
diff changeset
4427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4428
a61af66fc99e Initial load
duke
parents:
diff changeset
4429
a61af66fc99e Initial load
duke
parents:
diff changeset
4430 void MacroAssembler::push_FPU_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4431 subl(rsp, FPUStateSizeInWords * wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4432 fnsave(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
4433 fwait();
a61af66fc99e Initial load
duke
parents:
diff changeset
4434 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4435
a61af66fc99e Initial load
duke
parents:
diff changeset
4436
a61af66fc99e Initial load
duke
parents:
diff changeset
4437 void MacroAssembler::pop_FPU_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4438 frstor(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
4439 addl(rsp, FPUStateSizeInWords * wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4440 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4441
a61af66fc99e Initial load
duke
parents:
diff changeset
4442
a61af66fc99e Initial load
duke
parents:
diff changeset
4443 void MacroAssembler::push_CPU_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4444 push_IU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4445 push_FPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4446 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4447
a61af66fc99e Initial load
duke
parents:
diff changeset
4448
a61af66fc99e Initial load
duke
parents:
diff changeset
4449 void MacroAssembler::pop_CPU_state() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4450 pop_FPU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4451 pop_IU_state();
a61af66fc99e Initial load
duke
parents:
diff changeset
4452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4453
a61af66fc99e Initial load
duke
parents:
diff changeset
4454
a61af66fc99e Initial load
duke
parents:
diff changeset
4455 void MacroAssembler::push_callee_saved_registers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4456 pushl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
4457 pushl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
4458 pushl(rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4459 pushl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4460 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4461
a61af66fc99e Initial load
duke
parents:
diff changeset
4462
a61af66fc99e Initial load
duke
parents:
diff changeset
4463 void MacroAssembler::pop_callee_saved_registers() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4464 popl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4465 popl(rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4466 popl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
4467 popl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
4468 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4469
a61af66fc99e Initial load
duke
parents:
diff changeset
4470
a61af66fc99e Initial load
duke
parents:
diff changeset
4471 void MacroAssembler::set_word_if_not_zero(Register dst) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4472 xorl(dst, dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
4473 set_byte_if_not_zero(dst);
a61af66fc99e Initial load
duke
parents:
diff changeset
4474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4475
a61af66fc99e Initial load
duke
parents:
diff changeset
4476 // Write serialization page so VM thread can do a pseudo remote membar.
a61af66fc99e Initial load
duke
parents:
diff changeset
4477 // We use the current thread pointer to calculate a thread specific
a61af66fc99e Initial load
duke
parents:
diff changeset
4478 // offset to write to within the page. This minimizes bus traffic
a61af66fc99e Initial load
duke
parents:
diff changeset
4479 // due to cache line collision.
a61af66fc99e Initial load
duke
parents:
diff changeset
4480 void MacroAssembler::serialize_memory(Register thread, Register tmp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4481 movl(tmp, thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
4482 shrl(tmp, os::get_serialize_page_shift_count());
a61af66fc99e Initial load
duke
parents:
diff changeset
4483 andl(tmp, (os::vm_page_size() - sizeof(int)));
a61af66fc99e Initial load
duke
parents:
diff changeset
4484
a61af66fc99e Initial load
duke
parents:
diff changeset
4485 Address index(noreg, tmp, Address::times_1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4486 ExternalAddress page(os::get_memory_serialize_page());
a61af66fc99e Initial load
duke
parents:
diff changeset
4487
a61af66fc99e Initial load
duke
parents:
diff changeset
4488 movptr(ArrayAddress(page, index), tmp);
a61af66fc99e Initial load
duke
parents:
diff changeset
4489 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4490
a61af66fc99e Initial load
duke
parents:
diff changeset
4491
a61af66fc99e Initial load
duke
parents:
diff changeset
4492 void MacroAssembler::verify_tlab() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4493 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
4494 if (UseTLAB && VerifyOops) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4495 Label next, ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
4496 Register t1 = rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
4497 Register thread_reg = rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
4498
a61af66fc99e Initial load
duke
parents:
diff changeset
4499 pushl(t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4500 pushl(thread_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4501 get_thread(thread_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4502
a61af66fc99e Initial load
duke
parents:
diff changeset
4503 movl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4504 cmpl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_start_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4505 jcc(Assembler::aboveEqual, next);
a61af66fc99e Initial load
duke
parents:
diff changeset
4506 stop("assert(top >= start)");
a61af66fc99e Initial load
duke
parents:
diff changeset
4507 should_not_reach_here();
a61af66fc99e Initial load
duke
parents:
diff changeset
4508
a61af66fc99e Initial load
duke
parents:
diff changeset
4509 bind(next);
a61af66fc99e Initial load
duke
parents:
diff changeset
4510 movl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4511 cmpl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4512 jcc(Assembler::aboveEqual, ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
4513 stop("assert(top <= end)");
a61af66fc99e Initial load
duke
parents:
diff changeset
4514 should_not_reach_here();
a61af66fc99e Initial load
duke
parents:
diff changeset
4515
a61af66fc99e Initial load
duke
parents:
diff changeset
4516 bind(ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
4517 popl(thread_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4518 popl(t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4520 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
4521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4522
a61af66fc99e Initial load
duke
parents:
diff changeset
4523
a61af66fc99e Initial load
duke
parents:
diff changeset
4524 // Defines obj, preserves var_size_in_bytes
a61af66fc99e Initial load
duke
parents:
diff changeset
4525 void MacroAssembler::eden_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
4526 Register t1, Label& slow_case) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4527 assert(obj == rax, "obj must be in rax, for cmpxchg");
a61af66fc99e Initial load
duke
parents:
diff changeset
4528 assert_different_registers(obj, var_size_in_bytes, t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4529 Register end = t1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4530 Label retry;
a61af66fc99e Initial load
duke
parents:
diff changeset
4531 bind(retry);
a61af66fc99e Initial load
duke
parents:
diff changeset
4532 ExternalAddress heap_top((address) Universe::heap()->top_addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
4533 movptr(obj, heap_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
4534 if (var_size_in_bytes == noreg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4535 leal(end, Address(obj, con_size_in_bytes));
a61af66fc99e Initial load
duke
parents:
diff changeset
4536 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4537 leal(end, Address(obj, var_size_in_bytes, Address::times_1));
a61af66fc99e Initial load
duke
parents:
diff changeset
4538 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4539 // if end < obj then we wrapped around => object too long => slow case
a61af66fc99e Initial load
duke
parents:
diff changeset
4540 cmpl(end, obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
4541 jcc(Assembler::below, slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
4542 cmpptr(end, ExternalAddress((address) Universe::heap()->end_addr()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4543 jcc(Assembler::above, slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
4544 // Compare obj with the top addr, and if still equal, store the new top addr in
a61af66fc99e Initial load
duke
parents:
diff changeset
4545 // end at the address of the top addr pointer. Sets ZF if was equal, and clears
a61af66fc99e Initial load
duke
parents:
diff changeset
4546 // it otherwise. Use lock prefix for atomicity on MPs.
a61af66fc99e Initial load
duke
parents:
diff changeset
4547 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4548 lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
4549 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4550 cmpxchgptr(end, heap_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
4551 jcc(Assembler::notEqual, retry);
a61af66fc99e Initial load
duke
parents:
diff changeset
4552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4553
a61af66fc99e Initial load
duke
parents:
diff changeset
4554
a61af66fc99e Initial load
duke
parents:
diff changeset
4555 // Defines obj, preserves var_size_in_bytes, okay for t2 == var_size_in_bytes.
a61af66fc99e Initial load
duke
parents:
diff changeset
4556 void MacroAssembler::tlab_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes,
a61af66fc99e Initial load
duke
parents:
diff changeset
4557 Register t1, Register t2, Label& slow_case) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4558 assert_different_registers(obj, t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
4559 assert_different_registers(obj, var_size_in_bytes, t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4560 Register end = t2;
a61af66fc99e Initial load
duke
parents:
diff changeset
4561 Register thread = t1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4562
a61af66fc99e Initial load
duke
parents:
diff changeset
4563 verify_tlab();
a61af66fc99e Initial load
duke
parents:
diff changeset
4564
a61af66fc99e Initial load
duke
parents:
diff changeset
4565 get_thread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
4566
a61af66fc99e Initial load
duke
parents:
diff changeset
4567 movl(obj, Address(thread, JavaThread::tlab_top_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4568 if (var_size_in_bytes == noreg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4569 leal(end, Address(obj, con_size_in_bytes));
a61af66fc99e Initial load
duke
parents:
diff changeset
4570 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4571 leal(end, Address(obj, var_size_in_bytes, Address::times_1));
a61af66fc99e Initial load
duke
parents:
diff changeset
4572 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4573 cmpl(end, Address(thread, JavaThread::tlab_end_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4574 jcc(Assembler::above, slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
4575
a61af66fc99e Initial load
duke
parents:
diff changeset
4576 // update the tlab top pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
4577 movl(Address(thread, JavaThread::tlab_top_offset()), end);
a61af66fc99e Initial load
duke
parents:
diff changeset
4578
a61af66fc99e Initial load
duke
parents:
diff changeset
4579 // recover var_size_in_bytes if necessary
a61af66fc99e Initial load
duke
parents:
diff changeset
4580 if (var_size_in_bytes == end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4581 subl(var_size_in_bytes, obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
4582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4583 verify_tlab();
a61af66fc99e Initial load
duke
parents:
diff changeset
4584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4585
a61af66fc99e Initial load
duke
parents:
diff changeset
4586 // Preserves rbx, and rdx.
a61af66fc99e Initial load
duke
parents:
diff changeset
4587 void MacroAssembler::tlab_refill(Label& retry, Label& try_eden, Label& slow_case) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4588 Register top = rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
4589 Register t1 = rcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
4590 Register t2 = rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
4591 Register thread_reg = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
4592 assert_different_registers(top, thread_reg, t1, t2, /* preserve: */ rbx, rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
4593 Label do_refill, discard_tlab;
a61af66fc99e Initial load
duke
parents:
diff changeset
4594
a61af66fc99e Initial load
duke
parents:
diff changeset
4595 if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4596 // No allocation in the shared eden.
a61af66fc99e Initial load
duke
parents:
diff changeset
4597 jmp(slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
4598 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4599
a61af66fc99e Initial load
duke
parents:
diff changeset
4600 get_thread(thread_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4601
a61af66fc99e Initial load
duke
parents:
diff changeset
4602 movl(top, Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4603 movl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4604
a61af66fc99e Initial load
duke
parents:
diff changeset
4605 // calculate amount of free space
a61af66fc99e Initial load
duke
parents:
diff changeset
4606 subl(t1, top);
a61af66fc99e Initial load
duke
parents:
diff changeset
4607 shrl(t1, LogHeapWordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4608
a61af66fc99e Initial load
duke
parents:
diff changeset
4609 // Retain tlab and allocate object in shared space if
a61af66fc99e Initial load
duke
parents:
diff changeset
4610 // the amount free in the tlab is too large to discard.
a61af66fc99e Initial load
duke
parents:
diff changeset
4611 cmpl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4612 jcc(Assembler::lessEqual, discard_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
4613
a61af66fc99e Initial load
duke
parents:
diff changeset
4614 // Retain
a61af66fc99e Initial load
duke
parents:
diff changeset
4615 movl(t2, ThreadLocalAllocBuffer::refill_waste_limit_increment());
a61af66fc99e Initial load
duke
parents:
diff changeset
4616 addl(Address(thread_reg, in_bytes(JavaThread::tlab_refill_waste_limit_offset())), t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
4617 if (TLABStats) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4618 // increment number of slow_allocations
a61af66fc99e Initial load
duke
parents:
diff changeset
4619 addl(Address(thread_reg, in_bytes(JavaThread::tlab_slow_allocations_offset())), 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4620 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4621 jmp(try_eden);
a61af66fc99e Initial load
duke
parents:
diff changeset
4622
a61af66fc99e Initial load
duke
parents:
diff changeset
4623 bind(discard_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
4624 if (TLABStats) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4625 // increment number of refills
a61af66fc99e Initial load
duke
parents:
diff changeset
4626 addl(Address(thread_reg, in_bytes(JavaThread::tlab_number_of_refills_offset())), 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4627 // accumulate wastage -- t1 is amount free in tlab
a61af66fc99e Initial load
duke
parents:
diff changeset
4628 addl(Address(thread_reg, in_bytes(JavaThread::tlab_fast_refill_waste_offset())), t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4629 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4630
a61af66fc99e Initial load
duke
parents:
diff changeset
4631 // if tlab is currently allocated (top or end != null) then
a61af66fc99e Initial load
duke
parents:
diff changeset
4632 // fill [top, end + alignment_reserve) with array object
a61af66fc99e Initial load
duke
parents:
diff changeset
4633 testl (top, top);
a61af66fc99e Initial load
duke
parents:
diff changeset
4634 jcc(Assembler::zero, do_refill);
a61af66fc99e Initial load
duke
parents:
diff changeset
4635
a61af66fc99e Initial load
duke
parents:
diff changeset
4636 // set up the mark word
a61af66fc99e Initial load
duke
parents:
diff changeset
4637 movl(Address(top, oopDesc::mark_offset_in_bytes()), (int)markOopDesc::prototype()->copy_set_hash(0x2));
a61af66fc99e Initial load
duke
parents:
diff changeset
4638 // set the length to the remaining space
a61af66fc99e Initial load
duke
parents:
diff changeset
4639 subl(t1, typeArrayOopDesc::header_size(T_INT));
a61af66fc99e Initial load
duke
parents:
diff changeset
4640 addl(t1, ThreadLocalAllocBuffer::alignment_reserve());
a61af66fc99e Initial load
duke
parents:
diff changeset
4641 shll(t1, log2_intptr(HeapWordSize/sizeof(jint)));
a61af66fc99e Initial load
duke
parents:
diff changeset
4642 movl(Address(top, arrayOopDesc::length_offset_in_bytes()), t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4643 // set klass to intArrayKlass
a61af66fc99e Initial load
duke
parents:
diff changeset
4644 // dubious reloc why not an oop reloc?
a61af66fc99e Initial load
duke
parents:
diff changeset
4645 movptr(t1, ExternalAddress((address) Universe::intArrayKlassObj_addr()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4646 movl(Address(top, oopDesc::klass_offset_in_bytes()), t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4647
a61af66fc99e Initial load
duke
parents:
diff changeset
4648 // refill the tlab with an eden allocation
a61af66fc99e Initial load
duke
parents:
diff changeset
4649 bind(do_refill);
a61af66fc99e Initial load
duke
parents:
diff changeset
4650 movl(t1, Address(thread_reg, in_bytes(JavaThread::tlab_size_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4651 shll(t1, LogHeapWordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4652 // add object_size ??
a61af66fc99e Initial load
duke
parents:
diff changeset
4653 eden_allocate(top, t1, 0, t2, slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
4654
a61af66fc99e Initial load
duke
parents:
diff changeset
4655 // Check that t1 was preserved in eden_allocate.
a61af66fc99e Initial load
duke
parents:
diff changeset
4656 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
4657 if (UseTLAB) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4658 Label ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
4659 Register tsize = rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
4660 assert_different_registers(tsize, thread_reg, t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4661 pushl(tsize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4662 movl(tsize, Address(thread_reg, in_bytes(JavaThread::tlab_size_offset())));
a61af66fc99e Initial load
duke
parents:
diff changeset
4663 shll(tsize, LogHeapWordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4664 cmpl(t1, tsize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4665 jcc(Assembler::equal, ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
4666 stop("assert(t1 != tlab size)");
a61af66fc99e Initial load
duke
parents:
diff changeset
4667 should_not_reach_here();
a61af66fc99e Initial load
duke
parents:
diff changeset
4668
a61af66fc99e Initial load
duke
parents:
diff changeset
4669 bind(ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
4670 popl(tsize);
a61af66fc99e Initial load
duke
parents:
diff changeset
4671 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4672 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
4673 movl(Address(thread_reg, in_bytes(JavaThread::tlab_start_offset())), top);
a61af66fc99e Initial load
duke
parents:
diff changeset
4674 movl(Address(thread_reg, in_bytes(JavaThread::tlab_top_offset())), top);
a61af66fc99e Initial load
duke
parents:
diff changeset
4675 addl(top, t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
4676 subl(top, ThreadLocalAllocBuffer::alignment_reserve_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
4677 movl(Address(thread_reg, in_bytes(JavaThread::tlab_end_offset())), top);
a61af66fc99e Initial load
duke
parents:
diff changeset
4678 verify_tlab();
a61af66fc99e Initial load
duke
parents:
diff changeset
4679 jmp(retry);
a61af66fc99e Initial load
duke
parents:
diff changeset
4680 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4681
a61af66fc99e Initial load
duke
parents:
diff changeset
4682
a61af66fc99e Initial load
duke
parents:
diff changeset
4683 int MacroAssembler::biased_locking_enter(Register lock_reg, Register obj_reg, Register swap_reg, Register tmp_reg,
a61af66fc99e Initial load
duke
parents:
diff changeset
4684 bool swap_reg_contains_mark,
a61af66fc99e Initial load
duke
parents:
diff changeset
4685 Label& done, Label* slow_case,
a61af66fc99e Initial load
duke
parents:
diff changeset
4686 BiasedLockingCounters* counters) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4687 assert(UseBiasedLocking, "why call this otherwise?");
a61af66fc99e Initial load
duke
parents:
diff changeset
4688 assert(swap_reg == rax, "swap_reg must be rax, for cmpxchg");
a61af66fc99e Initial load
duke
parents:
diff changeset
4689 assert_different_registers(lock_reg, obj_reg, swap_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4690
a61af66fc99e Initial load
duke
parents:
diff changeset
4691 if (PrintBiasedLockingStatistics && counters == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
4692 counters = BiasedLocking::counters();
a61af66fc99e Initial load
duke
parents:
diff changeset
4693
a61af66fc99e Initial load
duke
parents:
diff changeset
4694 bool need_tmp_reg = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
4695 if (tmp_reg == noreg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4696 need_tmp_reg = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
4697 tmp_reg = lock_reg;
a61af66fc99e Initial load
duke
parents:
diff changeset
4698 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
4699 assert_different_registers(lock_reg, obj_reg, swap_reg, tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4700 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4701 assert(markOopDesc::age_shift == markOopDesc::lock_bits + markOopDesc::biased_lock_bits, "biased locking makes assumptions about bit layout");
a61af66fc99e Initial load
duke
parents:
diff changeset
4702 Address mark_addr (obj_reg, oopDesc::mark_offset_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
4703 Address klass_addr (obj_reg, oopDesc::klass_offset_in_bytes());
a61af66fc99e Initial load
duke
parents:
diff changeset
4704 Address saved_mark_addr(lock_reg, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
4705
a61af66fc99e Initial load
duke
parents:
diff changeset
4706 // Biased locking
a61af66fc99e Initial load
duke
parents:
diff changeset
4707 // See whether the lock is currently biased toward our thread and
a61af66fc99e Initial load
duke
parents:
diff changeset
4708 // whether the epoch is still valid
a61af66fc99e Initial load
duke
parents:
diff changeset
4709 // Note that the runtime guarantees sufficient alignment of JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
4710 // pointers to allow age to be placed into low bits
a61af66fc99e Initial load
duke
parents:
diff changeset
4711 // First check to see whether biasing is even enabled for this object
a61af66fc99e Initial load
duke
parents:
diff changeset
4712 Label cas_label;
a61af66fc99e Initial load
duke
parents:
diff changeset
4713 int null_check_offset = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
4714 if (!swap_reg_contains_mark) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4715 null_check_offset = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
4716 movl(swap_reg, mark_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4718 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4719 pushl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4720 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4721 movl(tmp_reg, swap_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4722 andl(tmp_reg, markOopDesc::biased_lock_mask_in_place);
a61af66fc99e Initial load
duke
parents:
diff changeset
4723 cmpl(tmp_reg, markOopDesc::biased_lock_pattern);
a61af66fc99e Initial load
duke
parents:
diff changeset
4724 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4725 popl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4726 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4727 jcc(Assembler::notEqual, cas_label);
a61af66fc99e Initial load
duke
parents:
diff changeset
4728 // The bias pattern is present in the object's header. Need to check
a61af66fc99e Initial load
duke
parents:
diff changeset
4729 // whether the bias owner and the epoch are both still current.
a61af66fc99e Initial load
duke
parents:
diff changeset
4730 // Note that because there is no current thread register on x86 we
a61af66fc99e Initial load
duke
parents:
diff changeset
4731 // need to store off the mark word we read out of the object to
a61af66fc99e Initial load
duke
parents:
diff changeset
4732 // avoid reloading it and needing to recheck invariants below. This
a61af66fc99e Initial load
duke
parents:
diff changeset
4733 // store is unfortunate but it makes the overall code shorter and
a61af66fc99e Initial load
duke
parents:
diff changeset
4734 // simpler.
a61af66fc99e Initial load
duke
parents:
diff changeset
4735 movl(saved_mark_addr, swap_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4736 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4737 pushl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4738 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4739 get_thread(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4740 xorl(swap_reg, tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4741 if (swap_reg_contains_mark) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4742 null_check_offset = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
4743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4744 movl(tmp_reg, klass_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4745 xorl(swap_reg, Address(tmp_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4746 andl(swap_reg, ~((int) markOopDesc::age_mask_in_place));
a61af66fc99e Initial load
duke
parents:
diff changeset
4747 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4748 popl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4749 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4750 if (counters != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4751 cond_inc32(Assembler::zero,
a61af66fc99e Initial load
duke
parents:
diff changeset
4752 ExternalAddress((address)counters->biased_lock_entry_count_addr()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4753 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4754 jcc(Assembler::equal, done);
a61af66fc99e Initial load
duke
parents:
diff changeset
4755
a61af66fc99e Initial load
duke
parents:
diff changeset
4756 Label try_revoke_bias;
a61af66fc99e Initial load
duke
parents:
diff changeset
4757 Label try_rebias;
a61af66fc99e Initial load
duke
parents:
diff changeset
4758
a61af66fc99e Initial load
duke
parents:
diff changeset
4759 // At this point we know that the header has the bias pattern and
a61af66fc99e Initial load
duke
parents:
diff changeset
4760 // that we are not the bias owner in the current epoch. We need to
a61af66fc99e Initial load
duke
parents:
diff changeset
4761 // figure out more details about the state of the header in order to
a61af66fc99e Initial load
duke
parents:
diff changeset
4762 // know what operations can be legally performed on the object's
a61af66fc99e Initial load
duke
parents:
diff changeset
4763 // header.
a61af66fc99e Initial load
duke
parents:
diff changeset
4764
a61af66fc99e Initial load
duke
parents:
diff changeset
4765 // If the low three bits in the xor result aren't clear, that means
a61af66fc99e Initial load
duke
parents:
diff changeset
4766 // the prototype header is no longer biased and we have to revoke
a61af66fc99e Initial load
duke
parents:
diff changeset
4767 // the bias on this object.
a61af66fc99e Initial load
duke
parents:
diff changeset
4768 testl(swap_reg, markOopDesc::biased_lock_mask_in_place);
a61af66fc99e Initial load
duke
parents:
diff changeset
4769 jcc(Assembler::notZero, try_revoke_bias);
a61af66fc99e Initial load
duke
parents:
diff changeset
4770
a61af66fc99e Initial load
duke
parents:
diff changeset
4771 // Biasing is still enabled for this data type. See whether the
a61af66fc99e Initial load
duke
parents:
diff changeset
4772 // epoch of the current bias is still valid, meaning that the epoch
a61af66fc99e Initial load
duke
parents:
diff changeset
4773 // bits of the mark word are equal to the epoch bits of the
a61af66fc99e Initial load
duke
parents:
diff changeset
4774 // prototype header. (Note that the prototype header's epoch bits
a61af66fc99e Initial load
duke
parents:
diff changeset
4775 // only change at a safepoint.) If not, attempt to rebias the object
a61af66fc99e Initial load
duke
parents:
diff changeset
4776 // toward the current thread. Note that we must be absolutely sure
a61af66fc99e Initial load
duke
parents:
diff changeset
4777 // that the current epoch is invalid in order to do this because
a61af66fc99e Initial load
duke
parents:
diff changeset
4778 // otherwise the manipulations it performs on the mark word are
a61af66fc99e Initial load
duke
parents:
diff changeset
4779 // illegal.
a61af66fc99e Initial load
duke
parents:
diff changeset
4780 testl(swap_reg, markOopDesc::epoch_mask_in_place);
a61af66fc99e Initial load
duke
parents:
diff changeset
4781 jcc(Assembler::notZero, try_rebias);
a61af66fc99e Initial load
duke
parents:
diff changeset
4782
a61af66fc99e Initial load
duke
parents:
diff changeset
4783 // The epoch of the current bias is still valid but we know nothing
a61af66fc99e Initial load
duke
parents:
diff changeset
4784 // about the owner; it might be set or it might be clear. Try to
a61af66fc99e Initial load
duke
parents:
diff changeset
4785 // acquire the bias of the object using an atomic operation. If this
a61af66fc99e Initial load
duke
parents:
diff changeset
4786 // fails we will go in to the runtime to revoke the object's bias.
a61af66fc99e Initial load
duke
parents:
diff changeset
4787 // Note that we first construct the presumed unbiased header so we
a61af66fc99e Initial load
duke
parents:
diff changeset
4788 // don't accidentally blow away another thread's valid bias.
a61af66fc99e Initial load
duke
parents:
diff changeset
4789 movl(swap_reg, saved_mark_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4790 andl(swap_reg,
a61af66fc99e Initial load
duke
parents:
diff changeset
4791 markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place);
a61af66fc99e Initial load
duke
parents:
diff changeset
4792 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4793 pushl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4794 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4795 get_thread(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4796 orl(tmp_reg, swap_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4797 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4798 lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
4799 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4800 cmpxchg(tmp_reg, Address(obj_reg, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
4801 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4802 popl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4803 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4804 // If the biasing toward our thread failed, this means that
a61af66fc99e Initial load
duke
parents:
diff changeset
4805 // another thread succeeded in biasing it toward itself and we
a61af66fc99e Initial load
duke
parents:
diff changeset
4806 // need to revoke that bias. The revocation will occur in the
a61af66fc99e Initial load
duke
parents:
diff changeset
4807 // interpreter runtime in the slow case.
a61af66fc99e Initial load
duke
parents:
diff changeset
4808 if (counters != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4809 cond_inc32(Assembler::zero,
a61af66fc99e Initial load
duke
parents:
diff changeset
4810 ExternalAddress((address)counters->anonymously_biased_lock_entry_count_addr()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4812 if (slow_case != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4813 jcc(Assembler::notZero, *slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
4814 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4815 jmp(done);
a61af66fc99e Initial load
duke
parents:
diff changeset
4816
a61af66fc99e Initial load
duke
parents:
diff changeset
4817 bind(try_rebias);
a61af66fc99e Initial load
duke
parents:
diff changeset
4818 // At this point we know the epoch has expired, meaning that the
a61af66fc99e Initial load
duke
parents:
diff changeset
4819 // current "bias owner", if any, is actually invalid. Under these
a61af66fc99e Initial load
duke
parents:
diff changeset
4820 // circumstances _only_, we are allowed to use the current header's
a61af66fc99e Initial load
duke
parents:
diff changeset
4821 // value as the comparison value when doing the cas to acquire the
a61af66fc99e Initial load
duke
parents:
diff changeset
4822 // bias in the current epoch. In other words, we allow transfer of
a61af66fc99e Initial load
duke
parents:
diff changeset
4823 // the bias from one thread to another directly in this situation.
a61af66fc99e Initial load
duke
parents:
diff changeset
4824 //
a61af66fc99e Initial load
duke
parents:
diff changeset
4825 // FIXME: due to a lack of registers we currently blow away the age
a61af66fc99e Initial load
duke
parents:
diff changeset
4826 // bits in this situation. Should attempt to preserve them.
a61af66fc99e Initial load
duke
parents:
diff changeset
4827 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4828 pushl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4829 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4830 get_thread(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4831 movl(swap_reg, klass_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4832 orl(tmp_reg, Address(swap_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4833 movl(swap_reg, saved_mark_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4834 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4835 lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
4836 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4837 cmpxchg(tmp_reg, Address(obj_reg, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
4838 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4839 popl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4840 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4841 // If the biasing toward our thread failed, then another thread
a61af66fc99e Initial load
duke
parents:
diff changeset
4842 // succeeded in biasing it toward itself and we need to revoke that
a61af66fc99e Initial load
duke
parents:
diff changeset
4843 // bias. The revocation will occur in the runtime in the slow case.
a61af66fc99e Initial load
duke
parents:
diff changeset
4844 if (counters != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4845 cond_inc32(Assembler::zero,
a61af66fc99e Initial load
duke
parents:
diff changeset
4846 ExternalAddress((address)counters->rebiased_lock_entry_count_addr()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4847 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4848 if (slow_case != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4849 jcc(Assembler::notZero, *slow_case);
a61af66fc99e Initial load
duke
parents:
diff changeset
4850 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4851 jmp(done);
a61af66fc99e Initial load
duke
parents:
diff changeset
4852
a61af66fc99e Initial load
duke
parents:
diff changeset
4853 bind(try_revoke_bias);
a61af66fc99e Initial load
duke
parents:
diff changeset
4854 // The prototype mark in the klass doesn't have the bias bit set any
a61af66fc99e Initial load
duke
parents:
diff changeset
4855 // more, indicating that objects of this data type are not supposed
a61af66fc99e Initial load
duke
parents:
diff changeset
4856 // to be biased any more. We are going to try to reset the mark of
a61af66fc99e Initial load
duke
parents:
diff changeset
4857 // this object to the prototype value and fall through to the
a61af66fc99e Initial load
duke
parents:
diff changeset
4858 // CAS-based locking scheme. Note that if our CAS fails, it means
a61af66fc99e Initial load
duke
parents:
diff changeset
4859 // that another thread raced us for the privilege of revoking the
a61af66fc99e Initial load
duke
parents:
diff changeset
4860 // bias of this particular object, so it's okay to continue in the
a61af66fc99e Initial load
duke
parents:
diff changeset
4861 // normal locking code.
a61af66fc99e Initial load
duke
parents:
diff changeset
4862 //
a61af66fc99e Initial load
duke
parents:
diff changeset
4863 // FIXME: due to a lack of registers we currently blow away the age
a61af66fc99e Initial load
duke
parents:
diff changeset
4864 // bits in this situation. Should attempt to preserve them.
a61af66fc99e Initial load
duke
parents:
diff changeset
4865 movl(swap_reg, saved_mark_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4866 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4867 pushl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4868 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4869 movl(tmp_reg, klass_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4870 movl(tmp_reg, Address(tmp_reg, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4871 if (os::is_MP()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4872 lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
4873 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4874 cmpxchg(tmp_reg, Address(obj_reg, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
4875 if (need_tmp_reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4876 popl(tmp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
4877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4878 // Fall through to the normal CAS-based lock, because no matter what
a61af66fc99e Initial load
duke
parents:
diff changeset
4879 // the result of the above CAS, some thread must have succeeded in
a61af66fc99e Initial load
duke
parents:
diff changeset
4880 // removing the bias bit from the object's header.
a61af66fc99e Initial load
duke
parents:
diff changeset
4881 if (counters != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4882 cond_inc32(Assembler::zero,
a61af66fc99e Initial load
duke
parents:
diff changeset
4883 ExternalAddress((address)counters->revoked_lock_entry_count_addr()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4884 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4885
a61af66fc99e Initial load
duke
parents:
diff changeset
4886 bind(cas_label);
a61af66fc99e Initial load
duke
parents:
diff changeset
4887
a61af66fc99e Initial load
duke
parents:
diff changeset
4888 return null_check_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
4889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4890
a61af66fc99e Initial load
duke
parents:
diff changeset
4891
a61af66fc99e Initial load
duke
parents:
diff changeset
4892 void MacroAssembler::biased_locking_exit(Register obj_reg, Register temp_reg, Label& done) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4893 assert(UseBiasedLocking, "why call this otherwise?");
a61af66fc99e Initial load
duke
parents:
diff changeset
4894
a61af66fc99e Initial load
duke
parents:
diff changeset
4895 // Check for biased locking unlock case, which is a no-op
a61af66fc99e Initial load
duke
parents:
diff changeset
4896 // Note: we do not have to check the thread ID for two reasons.
a61af66fc99e Initial load
duke
parents:
diff changeset
4897 // First, the interpreter checks for IllegalMonitorStateException at
a61af66fc99e Initial load
duke
parents:
diff changeset
4898 // a higher level. Second, if the bias was revoked while we held the
a61af66fc99e Initial load
duke
parents:
diff changeset
4899 // lock, the object could not be rebiased toward another thread, so
a61af66fc99e Initial load
duke
parents:
diff changeset
4900 // the bias bit would be clear.
a61af66fc99e Initial load
duke
parents:
diff changeset
4901 movl(temp_reg, Address(obj_reg, oopDesc::mark_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
4902 andl(temp_reg, markOopDesc::biased_lock_mask_in_place);
a61af66fc99e Initial load
duke
parents:
diff changeset
4903 cmpl(temp_reg, markOopDesc::biased_lock_pattern);
a61af66fc99e Initial load
duke
parents:
diff changeset
4904 jcc(Assembler::equal, done);
a61af66fc99e Initial load
duke
parents:
diff changeset
4905 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4906
a61af66fc99e Initial load
duke
parents:
diff changeset
4907
a61af66fc99e Initial load
duke
parents:
diff changeset
4908 Assembler::Condition MacroAssembler::negate_condition(Assembler::Condition cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4909 switch (cond) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4910 // Note some conditions are synonyms for others
a61af66fc99e Initial load
duke
parents:
diff changeset
4911 case Assembler::zero: return Assembler::notZero;
a61af66fc99e Initial load
duke
parents:
diff changeset
4912 case Assembler::notZero: return Assembler::zero;
a61af66fc99e Initial load
duke
parents:
diff changeset
4913 case Assembler::less: return Assembler::greaterEqual;
a61af66fc99e Initial load
duke
parents:
diff changeset
4914 case Assembler::lessEqual: return Assembler::greater;
a61af66fc99e Initial load
duke
parents:
diff changeset
4915 case Assembler::greater: return Assembler::lessEqual;
a61af66fc99e Initial load
duke
parents:
diff changeset
4916 case Assembler::greaterEqual: return Assembler::less;
a61af66fc99e Initial load
duke
parents:
diff changeset
4917 case Assembler::below: return Assembler::aboveEqual;
a61af66fc99e Initial load
duke
parents:
diff changeset
4918 case Assembler::belowEqual: return Assembler::above;
a61af66fc99e Initial load
duke
parents:
diff changeset
4919 case Assembler::above: return Assembler::belowEqual;
a61af66fc99e Initial load
duke
parents:
diff changeset
4920 case Assembler::aboveEqual: return Assembler::below;
a61af66fc99e Initial load
duke
parents:
diff changeset
4921 case Assembler::overflow: return Assembler::noOverflow;
a61af66fc99e Initial load
duke
parents:
diff changeset
4922 case Assembler::noOverflow: return Assembler::overflow;
a61af66fc99e Initial load
duke
parents:
diff changeset
4923 case Assembler::negative: return Assembler::positive;
a61af66fc99e Initial load
duke
parents:
diff changeset
4924 case Assembler::positive: return Assembler::negative;
a61af66fc99e Initial load
duke
parents:
diff changeset
4925 case Assembler::parity: return Assembler::noParity;
a61af66fc99e Initial load
duke
parents:
diff changeset
4926 case Assembler::noParity: return Assembler::parity;
a61af66fc99e Initial load
duke
parents:
diff changeset
4927 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4928 ShouldNotReachHere(); return Assembler::overflow;
a61af66fc99e Initial load
duke
parents:
diff changeset
4929 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4930
a61af66fc99e Initial load
duke
parents:
diff changeset
4931
a61af66fc99e Initial load
duke
parents:
diff changeset
4932 void MacroAssembler::cond_inc32(Condition cond, AddressLiteral counter_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4933 Condition negated_cond = negate_condition(cond);
a61af66fc99e Initial load
duke
parents:
diff changeset
4934 Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
4935 jcc(negated_cond, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
4936 atomic_incl(counter_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4937 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
4938 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4939
a61af66fc99e Initial load
duke
parents:
diff changeset
4940 void MacroAssembler::atomic_incl(AddressLiteral counter_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4941 pushfd();
a61af66fc99e Initial load
duke
parents:
diff changeset
4942 if (os::is_MP())
a61af66fc99e Initial load
duke
parents:
diff changeset
4943 lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
4944 increment(counter_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
4945 popfd();
a61af66fc99e Initial load
duke
parents:
diff changeset
4946 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4947
a61af66fc99e Initial load
duke
parents:
diff changeset
4948 SkipIfEqual::SkipIfEqual(
a61af66fc99e Initial load
duke
parents:
diff changeset
4949 MacroAssembler* masm, const bool* flag_addr, bool value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4950 _masm = masm;
a61af66fc99e Initial load
duke
parents:
diff changeset
4951 _masm->cmp8(ExternalAddress((address)flag_addr), value);
a61af66fc99e Initial load
duke
parents:
diff changeset
4952 _masm->jcc(Assembler::equal, _label);
a61af66fc99e Initial load
duke
parents:
diff changeset
4953 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4954
a61af66fc99e Initial load
duke
parents:
diff changeset
4955 SkipIfEqual::~SkipIfEqual() {
a61af66fc99e Initial load
duke
parents:
diff changeset
4956 _masm->bind(_label);
a61af66fc99e Initial load
duke
parents:
diff changeset
4957 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4958
a61af66fc99e Initial load
duke
parents:
diff changeset
4959
a61af66fc99e Initial load
duke
parents:
diff changeset
4960 // Writes to stack successive pages until offset reached to check for
a61af66fc99e Initial load
duke
parents:
diff changeset
4961 // stack overflow + shadow pages. This clobbers tmp.
a61af66fc99e Initial load
duke
parents:
diff changeset
4962 void MacroAssembler::bang_stack_size(Register size, Register tmp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4963 movl(tmp, rsp);
a61af66fc99e Initial load
duke
parents:
diff changeset
4964 // Bang stack for total size given plus shadow page size.
a61af66fc99e Initial load
duke
parents:
diff changeset
4965 // Bang one page at a time because large size can bang beyond yellow and
a61af66fc99e Initial load
duke
parents:
diff changeset
4966 // red zones.
a61af66fc99e Initial load
duke
parents:
diff changeset
4967 Label loop;
a61af66fc99e Initial load
duke
parents:
diff changeset
4968 bind(loop);
a61af66fc99e Initial load
duke
parents:
diff changeset
4969 movl(Address(tmp, (-os::vm_page_size())), size );
a61af66fc99e Initial load
duke
parents:
diff changeset
4970 subl(tmp, os::vm_page_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
4971 subl(size, os::vm_page_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
4972 jcc(Assembler::greater, loop);
a61af66fc99e Initial load
duke
parents:
diff changeset
4973
a61af66fc99e Initial load
duke
parents:
diff changeset
4974 // Bang down shadow pages too.
a61af66fc99e Initial load
duke
parents:
diff changeset
4975 // The -1 because we already subtracted 1 page.
a61af66fc99e Initial load
duke
parents:
diff changeset
4976 for (int i = 0; i< StackShadowPages-1; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
4977 movl(Address(tmp, (-i*os::vm_page_size())), size );
a61af66fc99e Initial load
duke
parents:
diff changeset
4978 }
a61af66fc99e Initial load
duke
parents:
diff changeset
4979 }