Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/x86/vm/c1_FpuStackSim_x86.cpp
32285 views
/*1* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_FpuStackSim.hpp"26#include "c1/c1_FrameMap.hpp"27#include "utilities/array.hpp"28#include "utilities/ostream.hpp"2930//--------------------------------------------------------31// FpuStackSim32//--------------------------------------------------------3334// This class maps the FPU registers to their stack locations; it computes35// the offsets between individual registers and simulates the FPU stack.3637const int EMPTY = -1;3839int FpuStackSim::regs_at(int i) const {40assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");41return _regs[i];42}4344void FpuStackSim::set_regs_at(int i, int val) {45assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");46_regs[i] = val;47}4849void FpuStackSim::dec_stack_size() {50_stack_size--;51assert(_stack_size >= 0, "FPU stack underflow");52}5354void FpuStackSim::inc_stack_size() {55_stack_size++;56assert(_stack_size <= FrameMap::nof_fpu_regs, "FPU stack overflow");57}5859FpuStackSim::FpuStackSim(Compilation* compilation)60: _compilation(compilation)61{62_stack_size = 0;63for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {64set_regs_at(i, EMPTY);65}66}676869void FpuStackSim::pop() {70if (TraceFPUStack) { tty->print("FPU-pop "); print(); tty->cr(); }71set_regs_at(tos_index(), EMPTY);72dec_stack_size();73}7475void FpuStackSim::pop(int rnr) {76if (TraceFPUStack) { tty->print("FPU-pop %d", rnr); print(); tty->cr(); }77assert(regs_at(tos_index()) == rnr, "rnr is not on TOS");78set_regs_at(tos_index(), EMPTY);79dec_stack_size();80}818283void FpuStackSim::push(int rnr) {84if (TraceFPUStack) { tty->print("FPU-push %d", rnr); print(); tty->cr(); }85assert(regs_at(stack_size()) == EMPTY, "should be empty");86set_regs_at(stack_size(), rnr);87inc_stack_size();88}899091void FpuStackSim::swap(int offset) {92if (TraceFPUStack) { tty->print("FPU-swap %d", offset); print(); tty->cr(); }93int t = regs_at(tos_index() - offset);94set_regs_at(tos_index() - offset, regs_at(tos_index()));95set_regs_at(tos_index(), t);96}979899int FpuStackSim::offset_from_tos(int rnr) const {100for (int i = tos_index(); i >= 0; i--) {101if (regs_at(i) == rnr) {102return tos_index() - i;103}104}105assert(false, "FpuStackSim: register not found");106BAILOUT_("FpuStackSim: register not found", 0);107}108109110int FpuStackSim::get_slot(int tos_offset) const {111return regs_at(tos_index() - tos_offset);112}113114void FpuStackSim::set_slot(int tos_offset, int rnr) {115set_regs_at(tos_index() - tos_offset, rnr);116}117118void FpuStackSim::rename(int old_rnr, int new_rnr) {119if (TraceFPUStack) { tty->print("FPU-rename %d %d", old_rnr, new_rnr); print(); tty->cr(); }120if (old_rnr == new_rnr)121return;122bool found = false;123for (int i = 0; i < stack_size(); i++) {124assert(regs_at(i) != new_rnr, "should not see old occurrences of new_rnr on the stack");125if (regs_at(i) == old_rnr) {126set_regs_at(i, new_rnr);127found = true;128}129}130assert(found, "should have found at least one instance of old_rnr");131}132133134bool FpuStackSim::contains(int rnr) {135for (int i = 0; i < stack_size(); i++) {136if (regs_at(i) == rnr) {137return true;138}139}140return false;141}142143bool FpuStackSim::is_empty() {144#ifdef ASSERT145if (stack_size() == 0) {146for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {147assert(regs_at(i) == EMPTY, "must be empty");148}149}150#endif151return stack_size() == 0;152}153154155bool FpuStackSim::slot_is_empty(int tos_offset) {156return (regs_at(tos_index() - tos_offset) == EMPTY);157}158159160void FpuStackSim::clear() {161if (TraceFPUStack) { tty->print("FPU-clear"); print(); tty->cr(); }162for (int i = tos_index(); i >= 0; i--) {163set_regs_at(i, EMPTY);164}165_stack_size = 0;166}167168169intArray* FpuStackSim::write_state() {170intArray* res = new intArray(1 + FrameMap::nof_fpu_regs);171(*res)[0] = stack_size();172for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {173(*res)[1 + i] = regs_at(i);174}175return res;176}177178179void FpuStackSim::read_state(intArray* fpu_stack_state) {180_stack_size = (*fpu_stack_state)[0];181for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {182set_regs_at(i, (*fpu_stack_state)[1 + i]);183}184}185186187#ifndef PRODUCT188void FpuStackSim::print() {189tty->print(" N=%d[", stack_size());\190for (int i = 0; i < stack_size(); i++) {191int reg = regs_at(i);192if (reg != EMPTY) {193tty->print("%d", reg);194} else {195tty->print("_");196}197};198tty->print(" ]");199}200#endif201202203