1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/c1_FpuStackSim_x86.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,198 @@ 1.4 +/* 1.5 + * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +# include "incls/_precompiled.incl" 1.29 +# include "incls/_c1_FpuStackSim_x86.cpp.incl" 1.30 + 1.31 +//-------------------------------------------------------- 1.32 +// FpuStackSim 1.33 +//-------------------------------------------------------- 1.34 + 1.35 +// This class maps the FPU registers to their stack locations; it computes 1.36 +// the offsets between individual registers and simulates the FPU stack. 1.37 + 1.38 +const int EMPTY = -1; 1.39 + 1.40 +int FpuStackSim::regs_at(int i) const { 1.41 + assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds"); 1.42 + return _regs[i]; 1.43 +} 1.44 + 1.45 +void FpuStackSim::set_regs_at(int i, int val) { 1.46 + assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds"); 1.47 + _regs[i] = val; 1.48 +} 1.49 + 1.50 +void FpuStackSim::dec_stack_size() { 1.51 + _stack_size--; 1.52 + assert(_stack_size >= 0, "FPU stack underflow"); 1.53 +} 1.54 + 1.55 +void FpuStackSim::inc_stack_size() { 1.56 + _stack_size++; 1.57 + assert(_stack_size <= FrameMap::nof_fpu_regs, "FPU stack overflow"); 1.58 +} 1.59 + 1.60 +FpuStackSim::FpuStackSim(Compilation* compilation) 1.61 + : _compilation(compilation) 1.62 +{ 1.63 + _stack_size = 0; 1.64 + for (int i = 0; i < FrameMap::nof_fpu_regs; i++) { 1.65 + set_regs_at(i, EMPTY); 1.66 + } 1.67 +} 1.68 + 1.69 + 1.70 +void FpuStackSim::pop() { 1.71 + if (TraceFPUStack) { tty->print("FPU-pop "); print(); tty->cr(); } 1.72 + set_regs_at(tos_index(), EMPTY); 1.73 + dec_stack_size(); 1.74 +} 1.75 + 1.76 +void FpuStackSim::pop(int rnr) { 1.77 + if (TraceFPUStack) { tty->print("FPU-pop %d", rnr); print(); tty->cr(); } 1.78 + assert(regs_at(tos_index()) == rnr, "rnr is not on TOS"); 1.79 + set_regs_at(tos_index(), EMPTY); 1.80 + dec_stack_size(); 1.81 +} 1.82 + 1.83 + 1.84 +void FpuStackSim::push(int rnr) { 1.85 + if (TraceFPUStack) { tty->print("FPU-push %d", rnr); print(); tty->cr(); } 1.86 + assert(regs_at(stack_size()) == EMPTY, "should be empty"); 1.87 + set_regs_at(stack_size(), rnr); 1.88 + inc_stack_size(); 1.89 +} 1.90 + 1.91 + 1.92 +void FpuStackSim::swap(int offset) { 1.93 + if (TraceFPUStack) { tty->print("FPU-swap %d", offset); print(); tty->cr(); } 1.94 + int t = regs_at(tos_index() - offset); 1.95 + set_regs_at(tos_index() - offset, regs_at(tos_index())); 1.96 + set_regs_at(tos_index(), t); 1.97 +} 1.98 + 1.99 + 1.100 +int FpuStackSim::offset_from_tos(int rnr) const { 1.101 + for (int i = tos_index(); i >= 0; i--) { 1.102 + if (regs_at(i) == rnr) { 1.103 + return tos_index() - i; 1.104 + } 1.105 + } 1.106 + assert(false, "FpuStackSim: register not found"); 1.107 + BAILOUT_("FpuStackSim: register not found", 0); 1.108 +} 1.109 + 1.110 + 1.111 +int FpuStackSim::get_slot(int tos_offset) const { 1.112 + return regs_at(tos_index() - tos_offset); 1.113 +} 1.114 + 1.115 +void FpuStackSim::set_slot(int tos_offset, int rnr) { 1.116 + set_regs_at(tos_index() - tos_offset, rnr); 1.117 +} 1.118 + 1.119 +void FpuStackSim::rename(int old_rnr, int new_rnr) { 1.120 + if (TraceFPUStack) { tty->print("FPU-rename %d %d", old_rnr, new_rnr); print(); tty->cr(); } 1.121 + if (old_rnr == new_rnr) 1.122 + return; 1.123 + bool found = false; 1.124 + for (int i = 0; i < stack_size(); i++) { 1.125 + assert(regs_at(i) != new_rnr, "should not see old occurrences of new_rnr on the stack"); 1.126 + if (regs_at(i) == old_rnr) { 1.127 + set_regs_at(i, new_rnr); 1.128 + found = true; 1.129 + } 1.130 + } 1.131 + assert(found, "should have found at least one instance of old_rnr"); 1.132 +} 1.133 + 1.134 + 1.135 +bool FpuStackSim::contains(int rnr) { 1.136 + for (int i = 0; i < stack_size(); i++) { 1.137 + if (regs_at(i) == rnr) { 1.138 + return true; 1.139 + } 1.140 + } 1.141 + return false; 1.142 +} 1.143 + 1.144 +bool FpuStackSim::is_empty() { 1.145 +#ifdef ASSERT 1.146 + if (stack_size() == 0) { 1.147 + for (int i = 0; i < FrameMap::nof_fpu_regs; i++) { 1.148 + assert(regs_at(i) == EMPTY, "must be empty"); 1.149 + } 1.150 + } 1.151 +#endif 1.152 + return stack_size() == 0; 1.153 +} 1.154 + 1.155 + 1.156 +bool FpuStackSim::slot_is_empty(int tos_offset) { 1.157 + return (regs_at(tos_index() - tos_offset) == EMPTY); 1.158 +} 1.159 + 1.160 + 1.161 +void FpuStackSim::clear() { 1.162 + if (TraceFPUStack) { tty->print("FPU-clear"); print(); tty->cr(); } 1.163 + for (int i = tos_index(); i >= 0; i--) { 1.164 + set_regs_at(i, EMPTY); 1.165 + } 1.166 + _stack_size = 0; 1.167 +} 1.168 + 1.169 + 1.170 +intArray* FpuStackSim::write_state() { 1.171 + intArray* res = new intArray(1 + FrameMap::nof_fpu_regs); 1.172 + (*res)[0] = stack_size(); 1.173 + for (int i = 0; i < FrameMap::nof_fpu_regs; i++) { 1.174 + (*res)[1 + i] = regs_at(i); 1.175 + } 1.176 + return res; 1.177 +} 1.178 + 1.179 + 1.180 +void FpuStackSim::read_state(intArray* fpu_stack_state) { 1.181 + _stack_size = (*fpu_stack_state)[0]; 1.182 + for (int i = 0; i < FrameMap::nof_fpu_regs; i++) { 1.183 + set_regs_at(i, (*fpu_stack_state)[1 + i]); 1.184 + } 1.185 +} 1.186 + 1.187 + 1.188 +#ifndef PRODUCT 1.189 +void FpuStackSim::print() { 1.190 + tty->print(" N=%d[", stack_size());\ 1.191 + for (int i = 0; i < stack_size(); i++) { 1.192 + int reg = regs_at(i); 1.193 + if (reg != EMPTY) { 1.194 + tty->print("%d", reg); 1.195 + } else { 1.196 + tty->print("_"); 1.197 + } 1.198 + }; 1.199 + tty->print(" ]"); 1.200 +} 1.201 +#endif