1 /*
   2  * Copyright (c) 2020, 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.inline.hpp"
  32 #include "runtime/frame.inline.hpp"
  33 #include "runtime/registerMap.hpp"
  34 #include "utilities/exceptions.hpp"
  35 
  36 extern "C" {
  37   void JNICALL JVM_RegisterVectorSupportMethods(JNIEnv* env, jclass vsclass);
  38 }
  39 
  40 class VectorSupport : AllStatic {
  41  private:
  42   static void init_mask_array(typeArrayOop arr, BasicType elem_bt, int num_elem, address value_addr);
  43   static void init_vector_array(typeArrayOop arr, BasicType elem_bt, int num_elem, address value_addr);
  44   static oop  allocate_vector_payload_helper(InstanceKlass* ik, BasicType elem_bt, int num_elem, address value_addr, TRAPS);
  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 
  82   static int vop2ideal(jint vop, BasicType bt);
  83 
  84   static oop  allocate_vector(InstanceKlass* holder, frame* fr, RegisterMap* reg_map, ObjectValue* sv, TRAPS);
  85 
  86   static bool is_vector(Klass* klass);
  87   static bool is_vector_mask(Klass* klass);
  88   static bool is_vector_shuffle(Klass* klass);
  89 };
  90 #endif // SHARE_PRIMS_VECTORSUPPORT_HPP