1 /*
   2  * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef CPU_X86_VM_VMREG_X86_INLINE_HPP
  26 #define CPU_X86_VM_VMREG_X86_INLINE_HPP
  27 
  28 inline VMReg Register::as_VMReg() const {
  29   if (encoding() == noreg.encoding()) {
  30     return VMRegImpl::Bad();
  31   }
  32 #ifdef AMD64
  33   return VMRegImpl::as_VMReg(encoding() << 1 );
  34 #else
  35   return VMRegImpl::as_VMReg(encoding() );
  36 #endif // AMD64
  37 }
  38 
  39 inline VMReg FloatRegister::as_VMReg() const {
  40   return VMRegImpl::as_VMReg((encoding() << 1) + ConcreteRegisterImpl::max_gpr);
  41 }
  42 
  43 inline VMReg XMMRegister::as_VMReg() const {
  44   return VMRegImpl::as_VMReg((encoding() << 3) + ConcreteRegisterImpl::max_fpr);
  45 }
  46 
  47 
  48 inline bool VMRegImpl::is_Register() {
  49   return (unsigned int) value() < (unsigned int) ConcreteRegisterImpl::max_gpr;
  50 }
  51 
  52 inline bool VMRegImpl::is_FloatRegister() {
  53   return value() >= ConcreteRegisterImpl::max_gpr && value() < ConcreteRegisterImpl::max_fpr;
  54 }
  55 
  56 inline bool VMRegImpl::is_XMMRegister() {
  57   return value() >= ConcreteRegisterImpl::max_fpr && value() < ConcreteRegisterImpl::max_xmm;
  58 }
  59 
  60 inline Register VMRegImpl::as_Register() {
  61 
  62   assert( is_Register(), "must be");
  63   // Yuk
  64 #ifdef AMD64
  65   return ::as_Register(value() >> 1);
  66 #else
  67   return ::as_Register(value());
  68 #endif // AMD64
  69 }
  70 
  71 inline FloatRegister VMRegImpl::as_FloatRegister() {
  72   assert( is_FloatRegister() && is_even(value()), "must be" );
  73   // Yuk
  74   return ::as_FloatRegister((value() - ConcreteRegisterImpl::max_gpr) >> 1);
  75 }
  76 
  77 inline XMMRegister VMRegImpl::as_XMMRegister() {
  78   assert( is_XMMRegister() && is_even(value()), "must be" );
  79   // Yuk
  80   return ::as_XMMRegister((value() - ConcreteRegisterImpl::max_fpr) >> 3);
  81 }
  82 
  83 inline   bool VMRegImpl::is_concrete() {
  84   assert(is_reg(), "must be");
  85 #ifndef AMD64
  86   if (is_Register()) return true;
  87 #endif // AMD64
  88   return is_even(value());
  89 }
  90 
  91 #endif // CPU_X86_VM_VMREG_X86_INLINE_HPP