Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@
* additional functionality for code generation. These types with their extended
* functionality can be used with many other code generation facilities in the
* library, such as generating random {@code Expression}s.
*
* <p>This module distinguishes <strong>scalar</strong> Java types and
* <strong>Vector API lane-element</strong> types:
* <ul>
* <li>Scalar {@code PRIMITIVE_TYPES}/{@code FLOATING_TYPES}/etc. enumerate
* only Java primitive types ({@code byte}, {@code short}, ...).
* These lists are typed as {@code List<PrimitiveType>} and are consumed
* by scalar fuzzers / scalar code generation. {@link Float16Type} (the
* scalar {@code Float16} logical type) is included in
* {@link #SCALAR_NUMERIC_TYPES} only.</li>
Comment on lines +40 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove the "only" on the last line. Because we may add it to other places later.

* <li>Vector-lane lists ({@code VECTOR_ELEMENT_TYPES},
* {@code FLOATING_VECTOR_ELEMENT_TYPES}, ...) enumerate the lane types
* valid for {@code VectorType.Vector}. These are typed as
* {@code List<VectorElementType>} and additionally include
* {@link Float16VectorType#FLOAT16} since {@code Float16Vector} is a real
* Vector API type whose lanes happen to have no Java primitive
* keyword.</li>
* </ul>
* Vector generators (e.g. {@code Operations.VECTOR_OPERATIONS}) consume the
* vector-lane lists; scalar generators (e.g.
* {@code Operations.PRIMITIVE_OPERATIONS}) consume the scalar lists.
*/
public interface CodeGenerationDataNameType extends DataName.Type {

Expand Down Expand Up @@ -101,9 +122,19 @@ public interface CodeGenerationDataNameType extends DataName.Type {
static PrimitiveType booleans() { return PrimitiveType.BOOLEANS; }

/**
* The Float16 type.
* The {@code Float16Vector} lane-element type. This is a
* {@link VectorElementType}, <strong>not</strong> a Java
* {@link PrimitiveType}; it appears in vector-lane lists but never in the
* scalar {@code PRIMITIVE_TYPES}/{@code FLOATING_TYPES} lists.
*
* @return The Float16 type.
* @return The {@code Float16Vector} {@link VectorElementType}.
*/
static Float16VectorType float16s() { return Float16VectorType.FLOAT16; }

/**
* The {@code Float16} scalar (logical) type.
*
* @return The scalar {@code Float16} type.
*/
static CodeGenerationDataNameType float16() { return Float16Type.FLOAT16; }
Comment on lines 124 to 139

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be very confusing, having the float16s and float16 methods here, the only difference is the s. Accidental confusion is pre-programmed.

That's why I would really suggest we rename the Float16VectorType to ShortCarriesFloat16, and then its method can be shortCarriesFloat16. That makes the semantics much more explicit.


Expand Down Expand Up @@ -185,6 +216,75 @@ public interface CodeGenerationDataNameType extends DataName.Type {
float16()
);

// --------------------------------------------------------------------
// Vector API lane-element type lists.
//
// These are typed as List<VectorElementType> and may include
// Float16VectorType.FLOAT16 in addition to the Java primitive lane
// carriers. They are the source of truth for vector lane iteration in
// vector generators (e.g. Operations.VECTOR_OPS).
// --------------------------------------------------------------------

/**
* All Vector API lane-element types: every Java numeric primitive lane
* carrier plus {@link Float16VectorType#FLOAT16}.
*/
List<VectorElementType> VECTOR_ELEMENT_TYPES = List.of(
bytes(),
shorts(),
float16s(),
ints(),
longs(),
floats(),
doubles()
);

/**
* Integral Vector API lane-element types (byte, short, int, long).
*/
List<VectorElementType> INTEGRAL_VECTOR_ELEMENT_TYPES = List.of(
bytes(),
shorts(),
ints(),
longs()
);

/**
* Floating Vector API lane-element types (float16, float, double).
*/
List<VectorElementType> FLOATING_VECTOR_ELEMENT_TYPES = List.of(
float16s(),
floats(),
doubles()
);

/**
* Integral-and-floating Vector API lane-element types: every lane type
* except booleans/chars (which have no Vector API counterparts).
*/
List<VectorElementType> INTEGRAL_AND_FLOATING_VECTOR_ELEMENT_TYPES = List.of(
bytes(),
shorts(),
float16s(),
ints(),
longs(),
floats(),
doubles()
);

/**
* Vector API lane-element types whose lanes are 32/64 bits and integral
* (int, long).
*/
List<VectorElementType> INT_LONG_VECTOR_ELEMENT_TYPES = List.of(
ints(),
longs()
);

// --------------------------------------------------------------------
// Concrete VectorType lists (typed as the concrete Vector subclasses).
// --------------------------------------------------------------------

List<VectorType.Vector> VECTOR_BYTE_VECTOR_TYPES = List.of(
VectorType.BYTE_64,
VectorType.BYTE_128,
Expand All @@ -199,6 +299,13 @@ public interface CodeGenerationDataNameType extends DataName.Type {
VectorType.SHORT_512
);

List<VectorType.Vector> VECTOR_FLOAT16_VECTOR_TYPES = List.of(
VectorType.FLOAT16_64,
VectorType.FLOAT16_128,
VectorType.FLOAT16_256,
VectorType.FLOAT16_512
);

List<VectorType.Vector> VECTOR_INT_VECTOR_TYPES = List.of(
VectorType.INT_64,
VectorType.INT_128,
Expand Down Expand Up @@ -230,6 +337,7 @@ public interface CodeGenerationDataNameType extends DataName.Type {
List<VectorType.Vector> VECTOR_VECTOR_TYPES = Utils.concat(
VECTOR_BYTE_VECTOR_TYPES,
VECTOR_SHORT_VECTOR_TYPES,
VECTOR_FLOAT16_VECTOR_TYPES,
VECTOR_INT_VECTOR_TYPES,
VECTOR_LONG_VECTOR_TYPES,
VECTOR_FLOAT_VECTOR_TYPES,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package compiler.lib.template_framework.library;

import compiler.lib.generators.Generators;
import compiler.lib.generators.Generator;

import compiler.lib.template_framework.DataName;

/**
* The {@link Float16VectorType} is the {@link VectorElementType} that describes
* the lane type of a {@code Float16Vector}.
*
* <p>Float16 is <strong>not</strong> a Java primitive type and therefore does
* not appear in any of the scalar {@link PrimitiveType} lists. As a
* {@link VectorElementType} it appears in vector-lane-typed lists such as
* {@link CodeGenerationDataNameType#VECTOR_ELEMENT_TYPES} and
* {@link CodeGenerationDataNameType#FLOATING_VECTOR_ELEMENT_TYPES}, which are
* consumed by vector-only generators (e.g. {@code Operations.VECTOR_OPERATIONS}).
*
* <p>The carrier type for a {@code Float16Vector} lane is {@code short}; the
* element type token used in {@code VectorOperators.Conversion.of*} expressions
* and {@code Float16Vector.SPECIES_*} is {@code Float16}.
*
* <p>NaN handling note: there are multiple bit representations for NaN within
* {@code short}/{@code Float16}. Consumers comparing {@code short[]} carrier
* arrays should canonicalize via {@code Float.float16ToFloat} (which returns a
* canonical NaN) before structural comparison.
*/
public final class Float16VectorType implements VectorElementType {
private static final Generator<Short> GEN_FLOAT16 = Generators.G.float16s();

/** The singleton instance. */
public static final Float16VectorType FLOAT16 = new Float16VectorType();

private Float16VectorType() {}

@Override
public boolean isSubtypeOf(DataName.Type other) {
return other instanceof Float16VectorType;
}

@Override
public String name() {
return "Float16";
}

@Override
public String carrierTypeName() {
return "short";
}

@Override
public String boxedTypeName() {
return "Float16";
}
Comment on lines +64 to +77

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I had an expression with this type, could I auto-box it, using Float16? Not really, right?


@Override
public int byteSize() {
return 2;
}

@Override
public boolean isFloating() {
return true;
}

@Override
public String toString() {
// Used by Template `let(...)` hashtag substitution as a Java scalar
// type for a single lane. Float16 has no Java keyword, so we return
// the carrier ("short"), which is what Float16Vector.lane(int) returns
// and what Float16Vector.broadcast(SPECIES, ...) accepts.
return carrierTypeName();
}

@Override
public Object con() {
return "(short)" + GEN_FLOAT16.next();
}

@Override
public Object callLibraryRNG() {
return "LibraryRNG.nextFloat16()";
}
}
Loading