1 /*
   2  * Copyright 2002 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  20  * CA 95054 USA or visit www.sun.com if you need additional information or
  21  * have any questions.
  22  *
  23  */
  24 
  25 package sun.jvm.hotspot.asm.sparc;
  26 
  27 import sun.jvm.hotspot.asm.*;
  28 
  29 abstract class FloatDecoder extends InstructionDecoder {
  30     final int    opf;
  31     final String name;
  32     final int    numSources; // 1 or 2;
  33     final int    src1Type;   // RTLDT_FL_SINGLE, _DOUBLE, _QUAD
  34     final int    src2Type;   // RTLDT_FL_SINGLE, _DOUBLE, _QUAD
  35     final int    resultType; // RTLDT_FL_SINGLE, _DOUBLE, _QUAD
  36 
  37     FloatDecoder(int opf, String name, int src1Type, int src2Type, int resultType) {
  38         this.opf = opf;
  39         this.name = name;
  40         numSources = 2;
  41         this.src1Type = src1Type;
  42         this.src2Type = src2Type;
  43         this.resultType = resultType;
  44     }
  45 
  46     FloatDecoder(int opf, String name, int src2Type, int resultType) {
  47         this.opf = opf;
  48         this.name = name;
  49         numSources = 1;
  50         this.src1Type = RTLOP_UNKNOWN;
  51         this.src2Type = src2Type;
  52         this.resultType = resultType;
  53     }
  54 
  55     abstract Instruction decodeFloatInstruction(int instruction,
  56                                SPARCRegister rs1, SPARCRegister rs2, SPARCRegister rd,
  57                                SPARCInstructionFactory factory);
  58 
  59     Instruction decode(int instruction, SPARCInstructionFactory factory) {
  60         int rs1Num = getSourceRegister1(instruction);
  61         int rs2Num = getSourceRegister2(instruction);
  62         int rdNum = getDestinationRegister(instruction);
  63 
  64         SPARCRegister rs1 = null;
  65         if (numSources == 2) {
  66            rs1 = RegisterDecoder.decode(src1Type, rs1Num);
  67            if (rs1 == null) {
  68               return factory.newIllegalInstruction(instruction);
  69            }
  70         }
  71 
  72         SPARCRegister rd = RegisterDecoder.decode(resultType, rdNum);
  73         SPARCRegister rs2 = RegisterDecoder.decode(src2Type, rs2Num);
  74         if (rd == null || rs2 == null) {
  75            return factory.newIllegalInstruction(instruction);
  76         }
  77 
  78         return decodeFloatInstruction(instruction, rs1, rs2, rd, factory);
  79     }
  80 }