1 /*
   2  * Copyright (c) 2013, Red Hat Inc.
   3  * Copyright (c) 2005, 2010, Oracle and/or its affiliates.
   4  * All rights reserved.
   5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   6  *
   7  * This code is free software; you can redistribute it and/or modify it
   8  * under the terms of the GNU General Public License version 2 only, as
   9  * published by the Free Software Foundation.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  *
  25  */
  26 
  27 #ifndef CPU_X86_VM_C1_FPUSTACKSIM_X86_HPP
  28 #define CPU_X86_VM_C1_FPUSTACKSIM_X86_HPP
  29 
  30 //  Simulates the FPU stack and maintains mapping [fpu-register -> stack offset]
  31 //  FPU registers are described as numbers from 0..nof_fpu_regs-1
  32 
  33 class Compilation;
  34 
  35 class FpuStackSim VALUE_OBJ_CLASS_SPEC {
  36  private:
  37   Compilation* _compilation;
  38   int          _stack_size;
  39   int          _regs[FrameMap::nof_fpu_regs];
  40 
  41   int tos_index() const                        { return _stack_size - 1; }
  42 
  43   int regs_at(int i) const;
  44   void set_regs_at(int i, int val);
  45   void dec_stack_size();
  46   void inc_stack_size();
  47 
  48   // unified bailout support
  49   Compilation*  compilation() const              { return _compilation; }
  50   void          bailout(const char* msg) const   { compilation()->bailout(msg); }
  51   bool          bailed_out() const               { return compilation()->bailed_out(); }
  52 
  53  public:
  54   FpuStackSim(Compilation* compilation);
  55   void pop ();
  56   void pop (int rnr);                          // rnr must be on tos
  57   void push(int rnr);
  58   void swap(int offset);                       // exchange tos with tos + offset
  59   int offset_from_tos(int rnr) const;          // return the offset of the topmost instance of rnr from TOS
  60   int  get_slot(int tos_offset) const;         // return the entry at the given offset from TOS
  61   void set_slot(int tos_offset, int rnr);      // set the entry at the given offset from TOS
  62   void rename(int old_rnr, int new_rnr);       // rename all instances of old_rnr to new_rnr
  63   bool contains(int rnr);                      // debugging support only
  64   bool is_empty();
  65   bool slot_is_empty(int tos_offset);
  66   int stack_size() const                       { return _stack_size; }
  67   void clear();
  68   intArray* write_state();
  69   void read_state(intArray* fpu_stack_state);
  70 
  71   void print() PRODUCT_RETURN;
  72 };
  73 
  74 #endif // CPU_X86_VM_C1_FPUSTACKSIM_X86_HPP