annotate src/cpu/x86/vm/relocInfo_x86.cpp @ 71:3d62cb85208d

6662967: Optimize I2D conversion on new x86 Summary: Use CVTDQ2PS and CVTDQ2PD for integer values conversions to float and double values on new AMD cpu. Reviewed-by: sgoldman, never
author kvn
date Wed, 19 Mar 2008 15:33:25 -0700
parents a61af66fc99e
children c436414a719e
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 1998-2005 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/_relocInfo_x86.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 void Relocation::pd_set_data_value(address x, intptr_t o) {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
31 x += o;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 typedef Assembler::WhichOperand WhichOperand;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64, call32
a61af66fc99e Initial load
duke
parents:
diff changeset
34 assert(which == Assembler::disp32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
35 which == Assembler::imm64_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
36 if (which == Assembler::imm64_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 *pd_address_in_code() = x;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // Note: Use runtime_call_type relocations for call32_operand.
a61af66fc99e Initial load
duke
parents:
diff changeset
40 address ip = addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
41 address disp = Assembler::locate_operand(ip, which);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 address next_ip = Assembler::locate_next_instruction(ip);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 *(int32_t*) disp = x - next_ip;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
46 *pd_address_in_code() = x + o;
a61af66fc99e Initial load
duke
parents:
diff changeset
47 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 address Relocation::pd_call_destination(address orig_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 intptr_t adj = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 if (orig_addr != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // We just moved this call instruction from orig_addr to addr().
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // This means its target will appear to have grown by addr() - orig_addr.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 adj = -( addr() - orig_addr );
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 NativeInstruction* ni = nativeInstruction_at(addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (ni->is_call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return nativeCall_at(addr())->destination() + adj;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 } else if (ni->is_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
62 return nativeJump_at(addr())->jump_destination() + adj;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 } else if (ni->is_cond_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 return nativeGeneralJump_at(addr())->jump_destination() + adj;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 } else if (ni->is_mov_literal64()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 return (address) ((NativeMovConstReg*)ni)->data();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void Relocation::pd_set_call_destination(address x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 NativeInstruction* ni = nativeInstruction_at(addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
76 if (ni->is_call()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 nativeCall_at(addr())->set_destination(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 } else if (ni->is_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 NativeJump* nj = nativeJump_at(addr());
a61af66fc99e Initial load
duke
parents:
diff changeset
80 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (nj->jump_destination() == (address) -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 x = (address) -1; // retain jump to self
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
85 nj->set_jump_destination(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 } else if (ni->is_cond_jump()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // %%%% kludge this, for now, until we get a jump_destination method
a61af66fc99e Initial load
duke
parents:
diff changeset
88 address old_dest = nativeGeneralJump_at(addr())->jump_destination();
a61af66fc99e Initial load
duke
parents:
diff changeset
89 address disp = Assembler::locate_operand(addr(), Assembler::call32_operand);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 *(jint*)disp += (x - old_dest);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 } else if (ni->is_mov_literal64()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 ((NativeMovConstReg*)ni)->set_data((intptr_t)x);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 address* Relocation::pd_address_in_code() {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // All embedded Intel addresses are stored in 32-bit words.
a61af66fc99e Initial load
duke
parents:
diff changeset
101 // Since the addr points at the start of the instruction,
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // we must parse the instruction a bit to find the embedded word.
a61af66fc99e Initial load
duke
parents:
diff changeset
103 assert(is_data(), "must be a DataRelocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
104 typedef Assembler::WhichOperand WhichOperand;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64/imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
106 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
107 assert(which == Assembler::disp32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
108 which == Assembler::call32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
109 which == Assembler::imm64_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (which != Assembler::imm64_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // The "address" in the code is a displacement can't return it as
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // and address* since it is really a jint*
a61af66fc99e Initial load
duke
parents:
diff changeset
113 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
117 assert(which == Assembler::disp32_operand || which == Assembler::imm32_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return (address*) Assembler::locate_operand(addr(), which);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 address Relocation::pd_get_address_from_code() {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // All embedded Intel addresses are stored in 32-bit words.
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Since the addr points at the start of the instruction,
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // we must parse the instruction a bit to find the embedded word.
a61af66fc99e Initial load
duke
parents:
diff changeset
128 assert(is_data(), "must be a DataRelocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 typedef Assembler::WhichOperand WhichOperand;
a61af66fc99e Initial load
duke
parents:
diff changeset
130 WhichOperand which = (WhichOperand) format(); // that is, disp32 or imm64/imm32
a61af66fc99e Initial load
duke
parents:
diff changeset
131 assert(which == Assembler::disp32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
132 which == Assembler::call32_operand ||
a61af66fc99e Initial load
duke
parents:
diff changeset
133 which == Assembler::imm64_operand, "format unpacks ok");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 if (which != Assembler::imm64_operand) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 address ip = addr();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 address disp = Assembler::locate_operand(ip, which);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 address next_ip = Assembler::locate_next_instruction(ip);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 address a = next_ip + *(int32_t*) disp;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return a;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
142 return *pd_address_in_code();
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 int Relocation::pd_breakpoint_size() {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // minimum breakpoint size, in short words
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return NativeIllegalInstruction::instruction_size / sizeof(short);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 Untested("pd_swap_in_breakpoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
152 if (instrs != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 for (int i = 0; i < instrlen; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 instrs[i] = ((short*)x)[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158 NativeIllegalInstruction::insert(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 Untested("pd_swap_out_breakpoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 assert(NativeIllegalInstruction::instruction_size == sizeof(short), "right address unit for update");
a61af66fc99e Initial load
duke
parents:
diff changeset
165 NativeInstruction* ni = nativeInstruction_at(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 *(short*)ni->addr_at(0) = instrs[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }