1 /*
   2  * Copyright (c) 2015, 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 jdk.vm.ci.aarch64;
  24 
  25 import jdk.vm.ci.meta.PlatformKind;
  26 
  27 public enum AArch64Kind implements PlatformKind {
  28 
  29     // scalar
  30     BYTE(1),
  31     WORD(2),
  32     DWORD(4),
  33     QWORD(8),
  34     SINGLE(4),
  35     DOUBLE(8),
  36 
  37     // SIMD
  38     V32_BYTE(4, BYTE),
  39     V32_WORD(4, WORD),
  40     V64_BYTE(8, BYTE),
  41     V64_WORD(8, WORD),
  42     V64_DWORD(8, DWORD),
  43     V128_BYTE(16, BYTE),
  44     V128_WORD(16, WORD),
  45     V128_DWORD(16, DWORD),
  46     V128_QWORD(16, QWORD),
  47     V128_SINGLE(16, SINGLE),
  48     V128_DOUBLE(16, DOUBLE);
  49 
  50     private final int size;
  51     private final int vectorLength;
  52 
  53     private final AArch64Kind scalar;
  54     private final EnumKey<AArch64Kind> key = new EnumKey<>(this);
  55 
  56     AArch64Kind(int size) {
  57         this.size = size;
  58         this.scalar = this;
  59         this.vectorLength = 1;
  60     }
  61 
  62     AArch64Kind(int size, AArch64Kind scalar) {
  63         this.size = size;
  64         this.scalar = scalar;
  65 
  66         assert size % scalar.size == 0;
  67         this.vectorLength = size / scalar.size;
  68     }
  69 
  70     public AArch64Kind getScalar() {
  71         return scalar;
  72     }
  73 
  74     public int getSizeInBytes() {
  75         return size;
  76     }
  77 
  78     public int getVectorLength() {
  79         return vectorLength;
  80     }
  81 
  82     public Key getKey() {
  83         return key;
  84     }
  85 
  86     public boolean isInteger() {
  87         switch (this) {
  88             case BYTE:
  89             case WORD:
  90             case DWORD:
  91             case QWORD:
  92                 return true;
  93             default:
  94                 return false;
  95         }
  96     }
  97 
  98     public boolean isSIMD() {
  99         switch (this) {
 100             case SINGLE:
 101             case DOUBLE:
 102             case V32_BYTE:
 103             case V32_WORD:
 104             case V64_BYTE:
 105             case V64_WORD:
 106             case V64_DWORD:
 107             case V128_BYTE:
 108             case V128_WORD:
 109             case V128_DWORD:
 110             case V128_QWORD:
 111             case V128_SINGLE:
 112             case V128_DOUBLE:
 113                 return true;
 114             default:
 115                 return false;
 116         }
 117     }
 118 
 119     public char getTypeChar() {
 120         switch (this) {
 121             case BYTE:
 122                 return 'b';
 123             case WORD:
 124                 return 'w';
 125             case DWORD:
 126                 return 'd';
 127             case QWORD:
 128                 return 'q';
 129             case SINGLE:
 130                 return 'S';
 131             case DOUBLE:
 132                 return 'D';
 133             case V32_BYTE:
 134             case V32_WORD:
 135             case V64_BYTE:
 136             case V64_WORD:
 137             case V64_DWORD:
 138             case V128_BYTE:
 139             case V128_WORD:
 140             case V128_DWORD:
 141             case V128_QWORD:
 142             case V128_SINGLE:
 143             case V128_DOUBLE:
 144                 return 'v';
 145             default:
 146                 return '-';
 147         }
 148     }
 149 }