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