src/cpu/x86/vm/c1_FpuStackSim_x86.cpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "c1/c1_FpuStackSim.hpp"
aoqi@0 27 #include "c1/c1_FrameMap.hpp"
aoqi@0 28 #include "utilities/array.hpp"
aoqi@0 29 #include "utilities/ostream.hpp"
aoqi@0 30
aoqi@0 31 //--------------------------------------------------------
aoqi@0 32 // FpuStackSim
aoqi@0 33 //--------------------------------------------------------
aoqi@0 34
aoqi@0 35 // This class maps the FPU registers to their stack locations; it computes
aoqi@0 36 // the offsets between individual registers and simulates the FPU stack.
aoqi@0 37
aoqi@0 38 const int EMPTY = -1;
aoqi@0 39
aoqi@0 40 int FpuStackSim::regs_at(int i) const {
aoqi@0 41 assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
aoqi@0 42 return _regs[i];
aoqi@0 43 }
aoqi@0 44
aoqi@0 45 void FpuStackSim::set_regs_at(int i, int val) {
aoqi@0 46 assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
aoqi@0 47 _regs[i] = val;
aoqi@0 48 }
aoqi@0 49
aoqi@0 50 void FpuStackSim::dec_stack_size() {
aoqi@0 51 _stack_size--;
aoqi@0 52 assert(_stack_size >= 0, "FPU stack underflow");
aoqi@0 53 }
aoqi@0 54
aoqi@0 55 void FpuStackSim::inc_stack_size() {
aoqi@0 56 _stack_size++;
aoqi@0 57 assert(_stack_size <= FrameMap::nof_fpu_regs, "FPU stack overflow");
aoqi@0 58 }
aoqi@0 59
aoqi@0 60 FpuStackSim::FpuStackSim(Compilation* compilation)
aoqi@0 61 : _compilation(compilation)
aoqi@0 62 {
aoqi@0 63 _stack_size = 0;
aoqi@0 64 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
aoqi@0 65 set_regs_at(i, EMPTY);
aoqi@0 66 }
aoqi@0 67 }
aoqi@0 68
aoqi@0 69
aoqi@0 70 void FpuStackSim::pop() {
aoqi@0 71 if (TraceFPUStack) { tty->print("FPU-pop "); print(); tty->cr(); }
aoqi@0 72 set_regs_at(tos_index(), EMPTY);
aoqi@0 73 dec_stack_size();
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 void FpuStackSim::pop(int rnr) {
aoqi@0 77 if (TraceFPUStack) { tty->print("FPU-pop %d", rnr); print(); tty->cr(); }
aoqi@0 78 assert(regs_at(tos_index()) == rnr, "rnr is not on TOS");
aoqi@0 79 set_regs_at(tos_index(), EMPTY);
aoqi@0 80 dec_stack_size();
aoqi@0 81 }
aoqi@0 82
aoqi@0 83
aoqi@0 84 void FpuStackSim::push(int rnr) {
aoqi@0 85 if (TraceFPUStack) { tty->print("FPU-push %d", rnr); print(); tty->cr(); }
aoqi@0 86 assert(regs_at(stack_size()) == EMPTY, "should be empty");
aoqi@0 87 set_regs_at(stack_size(), rnr);
aoqi@0 88 inc_stack_size();
aoqi@0 89 }
aoqi@0 90
aoqi@0 91
aoqi@0 92 void FpuStackSim::swap(int offset) {
aoqi@0 93 if (TraceFPUStack) { tty->print("FPU-swap %d", offset); print(); tty->cr(); }
aoqi@0 94 int t = regs_at(tos_index() - offset);
aoqi@0 95 set_regs_at(tos_index() - offset, regs_at(tos_index()));
aoqi@0 96 set_regs_at(tos_index(), t);
aoqi@0 97 }
aoqi@0 98
aoqi@0 99
aoqi@0 100 int FpuStackSim::offset_from_tos(int rnr) const {
aoqi@0 101 for (int i = tos_index(); i >= 0; i--) {
aoqi@0 102 if (regs_at(i) == rnr) {
aoqi@0 103 return tos_index() - i;
aoqi@0 104 }
aoqi@0 105 }
aoqi@0 106 assert(false, "FpuStackSim: register not found");
aoqi@0 107 BAILOUT_("FpuStackSim: register not found", 0);
aoqi@0 108 }
aoqi@0 109
aoqi@0 110
aoqi@0 111 int FpuStackSim::get_slot(int tos_offset) const {
aoqi@0 112 return regs_at(tos_index() - tos_offset);
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 void FpuStackSim::set_slot(int tos_offset, int rnr) {
aoqi@0 116 set_regs_at(tos_index() - tos_offset, rnr);
aoqi@0 117 }
aoqi@0 118
aoqi@0 119 void FpuStackSim::rename(int old_rnr, int new_rnr) {
aoqi@0 120 if (TraceFPUStack) { tty->print("FPU-rename %d %d", old_rnr, new_rnr); print(); tty->cr(); }
aoqi@0 121 if (old_rnr == new_rnr)
aoqi@0 122 return;
aoqi@0 123 bool found = false;
aoqi@0 124 for (int i = 0; i < stack_size(); i++) {
aoqi@0 125 assert(regs_at(i) != new_rnr, "should not see old occurrences of new_rnr on the stack");
aoqi@0 126 if (regs_at(i) == old_rnr) {
aoqi@0 127 set_regs_at(i, new_rnr);
aoqi@0 128 found = true;
aoqi@0 129 }
aoqi@0 130 }
aoqi@0 131 assert(found, "should have found at least one instance of old_rnr");
aoqi@0 132 }
aoqi@0 133
aoqi@0 134
aoqi@0 135 bool FpuStackSim::contains(int rnr) {
aoqi@0 136 for (int i = 0; i < stack_size(); i++) {
aoqi@0 137 if (regs_at(i) == rnr) {
aoqi@0 138 return true;
aoqi@0 139 }
aoqi@0 140 }
aoqi@0 141 return false;
aoqi@0 142 }
aoqi@0 143
aoqi@0 144 bool FpuStackSim::is_empty() {
aoqi@0 145 #ifdef ASSERT
aoqi@0 146 if (stack_size() == 0) {
aoqi@0 147 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
aoqi@0 148 assert(regs_at(i) == EMPTY, "must be empty");
aoqi@0 149 }
aoqi@0 150 }
aoqi@0 151 #endif
aoqi@0 152 return stack_size() == 0;
aoqi@0 153 }
aoqi@0 154
aoqi@0 155
aoqi@0 156 bool FpuStackSim::slot_is_empty(int tos_offset) {
aoqi@0 157 return (regs_at(tos_index() - tos_offset) == EMPTY);
aoqi@0 158 }
aoqi@0 159
aoqi@0 160
aoqi@0 161 void FpuStackSim::clear() {
aoqi@0 162 if (TraceFPUStack) { tty->print("FPU-clear"); print(); tty->cr(); }
aoqi@0 163 for (int i = tos_index(); i >= 0; i--) {
aoqi@0 164 set_regs_at(i, EMPTY);
aoqi@0 165 }
aoqi@0 166 _stack_size = 0;
aoqi@0 167 }
aoqi@0 168
aoqi@0 169
aoqi@0 170 intArray* FpuStackSim::write_state() {
aoqi@0 171 intArray* res = new intArray(1 + FrameMap::nof_fpu_regs);
aoqi@0 172 (*res)[0] = stack_size();
aoqi@0 173 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
aoqi@0 174 (*res)[1 + i] = regs_at(i);
aoqi@0 175 }
aoqi@0 176 return res;
aoqi@0 177 }
aoqi@0 178
aoqi@0 179
aoqi@0 180 void FpuStackSim::read_state(intArray* fpu_stack_state) {
aoqi@0 181 _stack_size = (*fpu_stack_state)[0];
aoqi@0 182 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
aoqi@0 183 set_regs_at(i, (*fpu_stack_state)[1 + i]);
aoqi@0 184 }
aoqi@0 185 }
aoqi@0 186
aoqi@0 187
aoqi@0 188 #ifndef PRODUCT
aoqi@0 189 void FpuStackSim::print() {
aoqi@0 190 tty->print(" N=%d[", stack_size());\
aoqi@0 191 for (int i = 0; i < stack_size(); i++) {
aoqi@0 192 int reg = regs_at(i);
aoqi@0 193 if (reg != EMPTY) {
aoqi@0 194 tty->print("%d", reg);
aoqi@0 195 } else {
aoqi@0 196 tty->print("_");
aoqi@0 197 }
aoqi@0 198 };
aoqi@0 199 tty->print(" ]");
aoqi@0 200 }
aoqi@0 201 #endif

mercurial