1 /*
  2  * Copyright (c) 2021, 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 SHARE_PRIMS_VECTORSUPPORT_HPP
 26 #define SHARE_PRIMS_VECTORSUPPORT_HPP
 27 
 28 #include "jni.h"
 29 #include "code/debugInfo.hpp"
 30 #include "memory/allocation.hpp"
 31 #include "oops/typeArrayOop.hpp"
 32 #include "runtime/registerMap.hpp"
 33 #include "utilities/exceptions.hpp"
 34 
 35 extern "C" {
 36   void JNICALL JVM_RegisterVectorSupportMethods(JNIEnv* env, jclass vsclass);
 37 }
 38 
 39 class VectorSupport : AllStatic {
 40  private:
 41   static Handle allocate_vector_payload(InstanceKlass* ik, frame* fr, RegisterMap* reg_map, ScopeValue* payload, TRAPS);
 42   static Handle allocate_vector_payload_helper(InstanceKlass* ik, frame* fr, RegisterMap* reg_map, Location location, TRAPS);
 43 
 44   static void init_payload_element(typeArrayOop arr, BasicType elem_bt, int index, address addr);
 45 
 46   static BasicType klass2bt(InstanceKlass* ik);
 47   static jint klass2length(InstanceKlass* ik);
 48 
 49  public:
 50 
 51    // Should be aligned with constants in jdk.internal.vm.vector.VectorSupport
 52   enum VectorOperation {
 53     // Unary
 54     VECTOR_OP_ABS     = 0,
 55     VECTOR_OP_NEG     = 1,
 56     VECTOR_OP_SQRT    = 2,
 57 
 58     // Binary
 59     VECTOR_OP_ADD     = 4,
 60     VECTOR_OP_SUB     = 5,
 61     VECTOR_OP_MUL     = 6,
 62     VECTOR_OP_DIV     = 7,
 63     VECTOR_OP_MIN     = 8,
 64     VECTOR_OP_MAX     = 9,
 65     VECTOR_OP_AND     = 10,
 66     VECTOR_OP_OR      = 11,
 67     VECTOR_OP_XOR     = 12,
 68 
 69     // Ternary
 70     VECTOR_OP_FMA     = 13,
 71 
 72     // Broadcast int
 73     VECTOR_OP_LSHIFT  = 14,
 74     VECTOR_OP_RSHIFT  = 15,
 75     VECTOR_OP_URSHIFT = 16,
 76 
 77     // Convert
 78     VECTOR_OP_CAST        = 17,
 79     VECTOR_OP_REINTERPRET = 18,
 80 
 81     // Mask manipulation operations
 82     VECTOR_OP_MASK_TRUECOUNT = 19,
 83     VECTOR_OP_MASK_FIRSTTRUE = 20,
 84     VECTOR_OP_MASK_LASTTRUE  = 21,
 85 
 86     // Rotate operations
 87     VECTOR_OP_LROTATE = 22,
 88     VECTOR_OP_RROTATE = 23,
 89 
 90     // Vector Math Library
 91     VECTOR_OP_TAN   = 101,
 92     VECTOR_OP_TANH  = 102,
 93     VECTOR_OP_SIN   = 103,
 94     VECTOR_OP_SINH  = 104,
 95     VECTOR_OP_COS   = 105,
 96     VECTOR_OP_COSH  = 106,
 97     VECTOR_OP_ASIN  = 107,
 98     VECTOR_OP_ACOS  = 108,
 99     VECTOR_OP_ATAN  = 109,
100     VECTOR_OP_ATAN2 = 110,
101     VECTOR_OP_CBRT  = 111,
102     VECTOR_OP_LOG   = 112,
103     VECTOR_OP_LOG10 = 113,
104     VECTOR_OP_LOG1P = 114,
105     VECTOR_OP_POW   = 115,
106     VECTOR_OP_EXP   = 116,
107     VECTOR_OP_EXPM1 = 117,
108     VECTOR_OP_HYPOT = 118,
109 
110     VECTOR_OP_SVML_START = VECTOR_OP_TAN,
111     VECTOR_OP_SVML_END   = VECTOR_OP_HYPOT,
112     NUM_SVML_OP = VECTOR_OP_SVML_END - VECTOR_OP_SVML_START + 1
113   };
114 
115   enum {
116     VEC_SIZE_64 = 0,
117     VEC_SIZE_128 = 1,
118     VEC_SIZE_256 = 2,
119     VEC_SIZE_512 = 3,
120     NUM_VEC_SIZES = 4
121   };
122 
123   static const char* svmlname[VectorSupport::NUM_SVML_OP];
124 
125   static int vop2ideal(jint vop, BasicType bt);
126 
127   static instanceOop allocate_vector(InstanceKlass* holder, frame* fr, RegisterMap* reg_map, ObjectValue* sv, TRAPS);
128 
129   static bool is_vector(Klass* klass);
130   static bool is_vector_mask(Klass* klass);
131   static bool is_vector_shuffle(Klass* klass);
132 };
133 #endif // SHARE_PRIMS_VECTORSUPPORT_HPP