hotspot/src/cpu/x86/vm/c1_FpuStackSim_x86.cpp
author xlu
Wed, 24 Dec 2008 13:06:09 -0800
changeset 1888 bbf498fb4354
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6787106: Hotspot 32 bit build fails on platforms having different definitions for intptr_t & int32_t Summary: Avoid casting between int32_t and intptr_t specifically for MasmAssembler::movptr in 32 bit platforms. Reviewed-by: jrose, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_c1_FpuStackSim_x86.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
//--------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//               FpuStackSim
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//--------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// This class maps the FPU registers to their stack locations; it computes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// the offsets between individual registers and simulates the FPU stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
const int EMPTY = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
int FpuStackSim::regs_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  return _regs[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
void FpuStackSim::set_regs_at(int i, int val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  assert(i >= 0 && i < FrameMap::nof_fpu_regs, "out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _regs[i] = val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
void FpuStackSim::dec_stack_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _stack_size--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  assert(_stack_size >= 0, "FPU stack underflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
void FpuStackSim::inc_stack_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  _stack_size++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  assert(_stack_size <= FrameMap::nof_fpu_regs, "FPU stack overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
FpuStackSim::FpuStackSim(Compilation* compilation)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
 : _compilation(compilation)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _stack_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    set_regs_at(i, EMPTY);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
void FpuStackSim::pop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  if (TraceFPUStack) { tty->print("FPU-pop "); print(); tty->cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  set_regs_at(tos_index(), EMPTY);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  dec_stack_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
void FpuStackSim::pop(int rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (TraceFPUStack) { tty->print("FPU-pop %d", rnr); print(); tty->cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  assert(regs_at(tos_index()) == rnr, "rnr is not on TOS");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  set_regs_at(tos_index(), EMPTY);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  dec_stack_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
void FpuStackSim::push(int rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  if (TraceFPUStack) { tty->print("FPU-push %d", rnr); print(); tty->cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  assert(regs_at(stack_size()) == EMPTY, "should be empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  set_regs_at(stack_size(), rnr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  inc_stack_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void FpuStackSim::swap(int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  if (TraceFPUStack) { tty->print("FPU-swap %d", offset); print(); tty->cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int t = regs_at(tos_index() - offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  set_regs_at(tos_index() - offset, regs_at(tos_index()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  set_regs_at(tos_index(), t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
int FpuStackSim::offset_from_tos(int rnr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  for (int i = tos_index(); i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    if (regs_at(i) == rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      return tos_index() - i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  assert(false, "FpuStackSim: register not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  BAILOUT_("FpuStackSim: register not found", 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
int FpuStackSim::get_slot(int tos_offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  return regs_at(tos_index() - tos_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
void FpuStackSim::set_slot(int tos_offset, int rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  set_regs_at(tos_index() - tos_offset, rnr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
void FpuStackSim::rename(int old_rnr, int new_rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  if (TraceFPUStack) { tty->print("FPU-rename %d %d", old_rnr, new_rnr); print(); tty->cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  if (old_rnr == new_rnr)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  for (int i = 0; i < stack_size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    assert(regs_at(i) != new_rnr, "should not see old occurrences of new_rnr on the stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    if (regs_at(i) == old_rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      set_regs_at(i, new_rnr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      found = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  assert(found, "should have found at least one instance of old_rnr");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
bool FpuStackSim::contains(int rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  for (int i = 0; i < stack_size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    if (regs_at(i) == rnr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
bool FpuStackSim::is_empty() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (stack_size() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      assert(regs_at(i) == EMPTY, "must be empty");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  return stack_size() == 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
bool FpuStackSim::slot_is_empty(int tos_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  return (regs_at(tos_index() - tos_offset) == EMPTY);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
void FpuStackSim::clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if (TraceFPUStack) { tty->print("FPU-clear"); print(); tty->cr(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  for (int i = tos_index(); i >= 0; i--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    set_regs_at(i, EMPTY);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  _stack_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
intArray* FpuStackSim::write_state() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  intArray* res = new intArray(1 + FrameMap::nof_fpu_regs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  (*res)[0] = stack_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    (*res)[1 + i] = regs_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
void FpuStackSim::read_state(intArray* fpu_stack_state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  _stack_size = (*fpu_stack_state)[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  for (int i = 0; i < FrameMap::nof_fpu_regs; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    set_regs_at(i, (*fpu_stack_state)[1 + i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
void FpuStackSim::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  tty->print(" N=%d[", stack_size());\
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  for (int i = 0; i < stack_size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    int reg = regs_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    if (reg != EMPTY) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      tty->print("%d", reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      tty->print("_");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  };
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
#endif