Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/aarch64/vm/c1_FpuStackSim_aarch64.cpp
32285 views
/*1* Copyright (c) 2013, Red Hat Inc.2* Copyright (c) 2005, 2010, Oracle and/or its affiliates.3* All rights reserved.4* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.5*6* This code is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License version 2 only, as8* published by the Free Software Foundation.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*24*/2526#include "precompiled.hpp"27#include "c1/c1_FpuStackSim.hpp"28#include "c1/c1_FrameMap.hpp"29#include "utilities/array.hpp"30#include "utilities/ostream.hpp"3132//--------------------------------------------------------33// FpuStackSim34//--------------------------------------------------------3536// This class maps the FPU registers to their stack locations; it computes37// the offsets between individual registers and simulates the FPU stack.3839const int EMPTY = -1;4041int FpuStackSim::regs_at(int i) const {42assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");43return _regs[i];44}4546void FpuStackSim::set_regs_at(int i, int val) {47assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");48_regs[i] = val;49}5051void FpuStackSim::dec_stack_size() {52_stack_size--;53assert(_stack_size >= 0, "FPU stack underflow");54}5556void FpuStackSim::inc_stack_size() {57_stack_size++;58assert(_stack_size <= FrameMap::nof_fpu_regs, "FPU stack overflow");59}6061FpuStackSim::FpuStackSim(Compilation* compilation)62: _compilation(compilation)63{64_stack_size = 0;65for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {66set_regs_at(i, EMPTY);67}68}697071void FpuStackSim::pop() {72if (TraceFPUStack) { tty->print("FPU-pop "); print(); tty->cr(); }73set_regs_at(tos_index(), EMPTY);74dec_stack_size();75}7677void FpuStackSim::pop(int rnr) {78if (TraceFPUStack) { tty->print("FPU-pop %d", rnr); print(); tty->cr(); }79assert(regs_at(tos_index()) == rnr, "rnr is not on TOS");80set_regs_at(tos_index(), EMPTY);81dec_stack_size();82}838485void FpuStackSim::push(int rnr) {86if (TraceFPUStack) { tty->print("FPU-push %d", rnr); print(); tty->cr(); }87assert(regs_at(stack_size()) == EMPTY, "should be empty");88set_regs_at(stack_size(), rnr);89inc_stack_size();90}919293void FpuStackSim::swap(int offset) {94if (TraceFPUStack) { tty->print("FPU-swap %d", offset); print(); tty->cr(); }95int t = regs_at(tos_index() - offset);96set_regs_at(tos_index() - offset, regs_at(tos_index()));97set_regs_at(tos_index(), t);98}99100101int FpuStackSim::offset_from_tos(int rnr) const {102for (int i = tos_index(); i >= 0; i--) {103if (regs_at(i) == rnr) {104return tos_index() - i;105}106}107assert(false, "FpuStackSim: register not found");108BAILOUT_("FpuStackSim: register not found", 0);109}110111112int FpuStackSim::get_slot(int tos_offset) const {113return regs_at(tos_index() - tos_offset);114}115116void FpuStackSim::set_slot(int tos_offset, int rnr) {117set_regs_at(tos_index() - tos_offset, rnr);118}119120void FpuStackSim::rename(int old_rnr, int new_rnr) {121if (TraceFPUStack) { tty->print("FPU-rename %d %d", old_rnr, new_rnr); print(); tty->cr(); }122if (old_rnr == new_rnr)123return;124bool found = false;125for (int i = 0; i < stack_size(); i++) {126assert(regs_at(i) != new_rnr, "should not see old occurrences of new_rnr on the stack");127if (regs_at(i) == old_rnr) {128set_regs_at(i, new_rnr);129found = true;130}131}132assert(found, "should have found at least one instance of old_rnr");133}134135136bool FpuStackSim::contains(int rnr) {137for (int i = 0; i < stack_size(); i++) {138if (regs_at(i) == rnr) {139return true;140}141}142return false;143}144145bool FpuStackSim::is_empty() {146#ifdef ASSERT147if (stack_size() == 0) {148for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {149assert(regs_at(i) == EMPTY, "must be empty");150}151}152#endif153return stack_size() == 0;154}155156157bool FpuStackSim::slot_is_empty(int tos_offset) {158return (regs_at(tos_index() - tos_offset) == EMPTY);159}160161162void FpuStackSim::clear() {163if (TraceFPUStack) { tty->print("FPU-clear"); print(); tty->cr(); }164for (int i = tos_index(); i >= 0; i--) {165set_regs_at(i, EMPTY);166}167_stack_size = 0;168}169170171intArray* FpuStackSim::write_state() {172intArray* res = new intArray(1 + FrameMap::nof_fpu_regs);173(*res)[0] = stack_size();174for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {175(*res)[1 + i] = regs_at(i);176}177return res;178}179180181void FpuStackSim::read_state(intArray* fpu_stack_state) {182_stack_size = (*fpu_stack_state)[0];183for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {184set_regs_at(i, (*fpu_stack_state)[1 + i]);185}186}187188189#ifndef PRODUCT190void FpuStackSim::print() {191tty->print(" N=%d[", stack_size());\192for (int i = 0; i < stack_size(); i++) {193int reg = regs_at(i);194if (reg != EMPTY) {195tty->print("%d", reg);196} else {197tty->print("_");198}199};200tty->print(" ]");201}202#endif203204205