< prev index next >

src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/aarch64/TypeClass.java

Print this page

  9  * particular file as subject to the "Classpath" exception as provided
 10  * by Oracle in the LICENSE file that accompanied this code.
 11  *
 12  * This code is distributed in the hope that it will be useful, but WITHOUT
 13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 15  * version 2 for more details (a copy is included in the LICENSE file that
 16  * accompanied this code).
 17  *
 18  * You should have received a copy of the GNU General Public License version
 19  * 2 along with this work; if not, write to the Free Software Foundation,
 20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 21  *
 22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 23  * or visit www.oracle.com if you need additional information or have any
 24  * questions.
 25  */
 26 package jdk.internal.foreign.abi.aarch64;
 27 
 28 import jdk.incubator.foreign.GroupLayout;

 29 import jdk.incubator.foreign.MemoryLayout;
 30 import jdk.incubator.foreign.SequenceLayout;
 31 import jdk.incubator.foreign.ValueLayout;
 32 import jdk.internal.foreign.PlatformLayouts;
 33 
 34 public enum TypeClass {
 35     STRUCT_REGISTER,
 36     STRUCT_REFERENCE,
 37     STRUCT_HFA,
 38     POINTER,
 39     INTEGER,
 40     FLOAT;
 41 
 42     private static final int MAX_AGGREGATE_REGS_SIZE = 2;
 43 
 44     private static TypeClass classifyValueType(ValueLayout type) {
 45         return switch (PlatformLayouts.getKind(type)) {
 46             case CHAR, SHORT, INT, LONG, LONG_LONG -> INTEGER;
 47             case POINTER -> POINTER;
 48             case FLOAT, DOUBLE -> FLOAT;
 49         };






 50     }
 51 
 52     static boolean isRegisterAggregate(MemoryLayout type) {
 53         return type.bitSize() <= MAX_AGGREGATE_REGS_SIZE * 64;
 54     }
 55 
 56     static boolean isHomogeneousFloatAggregate(MemoryLayout type) {
 57         if (!(type instanceof GroupLayout))
 58             return false;
 59 
 60         GroupLayout groupLayout = (GroupLayout)type;
 61 
 62         final int numElements = groupLayout.memberLayouts().size();
 63         if (numElements > 4 || numElements == 0)
 64             return false;
 65 
 66         MemoryLayout baseType = groupLayout.memberLayouts().get(0);
 67 
 68         if (!(baseType instanceof ValueLayout))
 69             return false;

  9  * particular file as subject to the "Classpath" exception as provided
 10  * by Oracle in the LICENSE file that accompanied this code.
 11  *
 12  * This code is distributed in the hope that it will be useful, but WITHOUT
 13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 15  * version 2 for more details (a copy is included in the LICENSE file that
 16  * accompanied this code).
 17  *
 18  * You should have received a copy of the GNU General Public License version
 19  * 2 along with this work; if not, write to the Free Software Foundation,
 20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 21  *
 22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 23  * or visit www.oracle.com if you need additional information or have any
 24  * questions.
 25  */
 26 package jdk.internal.foreign.abi.aarch64;
 27 
 28 import jdk.incubator.foreign.GroupLayout;
 29 import jdk.incubator.foreign.MemoryAddress;
 30 import jdk.incubator.foreign.MemoryLayout;
 31 import jdk.incubator.foreign.SequenceLayout;
 32 import jdk.incubator.foreign.ValueLayout;

 33 
 34 public enum TypeClass {
 35     STRUCT_REGISTER,
 36     STRUCT_REFERENCE,
 37     STRUCT_HFA,
 38     POINTER,
 39     INTEGER,
 40     FLOAT;
 41 
 42     private static final int MAX_AGGREGATE_REGS_SIZE = 2;
 43 
 44     private static TypeClass classifyValueType(ValueLayout type) {
 45         Class<?> carrier = type.carrier();
 46         if (carrier == boolean.class || carrier == byte.class || carrier == char.class ||
 47                 carrier == short.class || carrier == int.class || carrier == long.class) {
 48             return INTEGER;
 49         } else if (carrier == float.class || carrier == double.class) {
 50             return FLOAT;
 51         } else if (carrier == MemoryAddress.class) {
 52             return POINTER;
 53         } else {
 54             throw new IllegalStateException("Cannot get here: " + carrier.getName());
 55         }
 56     }
 57 
 58     static boolean isRegisterAggregate(MemoryLayout type) {
 59         return type.bitSize() <= MAX_AGGREGATE_REGS_SIZE * 64;
 60     }
 61 
 62     static boolean isHomogeneousFloatAggregate(MemoryLayout type) {
 63         if (!(type instanceof GroupLayout))
 64             return false;
 65 
 66         GroupLayout groupLayout = (GroupLayout)type;
 67 
 68         final int numElements = groupLayout.memberLayouts().size();
 69         if (numElements > 4 || numElements == 0)
 70             return false;
 71 
 72         MemoryLayout baseType = groupLayout.memberLayouts().get(0);
 73 
 74         if (!(baseType instanceof ValueLayout))
 75             return false;
< prev index next >