1 /*
   2  * Copyright (c) 2014, 2014, 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 package org.graalvm.compiler.core.common.calc;
  24 
  25 import org.graalvm.compiler.debug.GraalError;
  26 
  27 public enum FloatConvert {
  28     F2I(FloatConvertCategory.FloatingPointToInteger, 32),
  29     D2I(FloatConvertCategory.FloatingPointToInteger, 64),
  30     F2L(FloatConvertCategory.FloatingPointToInteger, 32),
  31     D2L(FloatConvertCategory.FloatingPointToInteger, 64),
  32     I2F(FloatConvertCategory.IntegerToFloatingPoint, 32),
  33     L2F(FloatConvertCategory.IntegerToFloatingPoint, 64),
  34     D2F(FloatConvertCategory.FloatingPointToFloatingPoint, 64),
  35     I2D(FloatConvertCategory.IntegerToFloatingPoint, 32),
  36     L2D(FloatConvertCategory.IntegerToFloatingPoint, 64),
  37     F2D(FloatConvertCategory.FloatingPointToFloatingPoint, 32);
  38 
  39     private final FloatConvertCategory category;
  40     private final int inputBits;
  41 
  42     FloatConvert(FloatConvertCategory category, int inputBits) {
  43         this.category = category;
  44         this.inputBits = inputBits;
  45     }
  46 
  47     public FloatConvertCategory getCategory() {
  48         return category;
  49     }
  50 
  51     public FloatConvert reverse() {
  52         switch (this) {
  53             case D2F:
  54                 return F2D;
  55             case D2I:
  56                 return I2D;
  57             case D2L:
  58                 return L2D;
  59             case F2D:
  60                 return D2F;
  61             case F2I:
  62                 return I2F;
  63             case F2L:
  64                 return L2F;
  65             case I2D:
  66                 return D2I;
  67             case I2F:
  68                 return F2I;
  69             case L2D:
  70                 return D2L;
  71             case L2F:
  72                 return F2L;
  73             default:
  74                 throw GraalError.shouldNotReachHere();
  75         }
  76     }
  77 
  78     public int getInputBits() {
  79         return inputBits;
  80     }
  81 }