@@ -37,7 +37,6 @@ public final class JdkVectorLibrary implements VectorLibrary {
3737 static final MethodHandle sqr7u$mh ;
3838 static final MethodHandle sqr7uBulk$mh ;
3939 static final MethodHandle sqr7uBulkWithOffsets$mh ;
40- static final MethodHandle cosf32$mh ;
4140 static final MethodHandle dotf32$mh ;
4241 static final MethodHandle sqrf32$mh ;
4342
@@ -51,99 +50,28 @@ public final class JdkVectorLibrary implements VectorLibrary {
5150 int caps = (int ) vecCaps$mh .invokeExact ();
5251 logger .info ("vec_caps=" + caps );
5352 if (caps > 0 ) {
54- if (caps == 2 ) {
55- dot7u$mh = downcallHandle (
56- "vec_dot7u_2" ,
57- FunctionDescriptor .of (JAVA_INT , ADDRESS , ADDRESS , JAVA_INT ),
58- LinkerHelperUtil .critical ()
59- );
60- dot7uBulk$mh = downcallHandle (
61- "vec_dot7u_bulk_2" ,
62- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS ),
63- LinkerHelperUtil .critical ()
64- );
65- dot7uBulkWithOffsets$mh = downcallHandle (
66- "vec_dot7u_bulk_offsets_2" ,
67- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS , JAVA_INT , ADDRESS ),
68- LinkerHelperUtil .critical ()
69- );
70- sqr7u$mh = downcallHandle (
71- "vec_sqr7u_2" ,
72- FunctionDescriptor .of (JAVA_INT , ADDRESS , ADDRESS , JAVA_INT ),
73- LinkerHelperUtil .critical ()
74- );
75- sqr7uBulk$mh = downcallHandle (
76- "vec_sqr7u_bulk_2" ,
77- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS ),
78- LinkerHelperUtil .critical ()
79- );
80- sqr7uBulkWithOffsets$mh = downcallHandle (
81- "vec_sqr7u_bulk_offsets_2" ,
82- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS , JAVA_INT , ADDRESS ),
83- LinkerHelperUtil .critical ()
84- );
85- cosf32$mh = downcallHandle (
86- "vec_cosf32_2" ,
87- FunctionDescriptor .of (JAVA_FLOAT , ADDRESS , ADDRESS , JAVA_INT ),
88- LinkerHelperUtil .critical ()
89- );
90- dotf32$mh = downcallHandle (
91- "vec_dotf32_2" ,
92- FunctionDescriptor .of (JAVA_FLOAT , ADDRESS , ADDRESS , JAVA_INT ),
93- LinkerHelperUtil .critical ()
94- );
95- sqrf32$mh = downcallHandle (
96- "vec_sqrf32_2" ,
97- FunctionDescriptor .of (JAVA_FLOAT , ADDRESS , ADDRESS , JAVA_INT ),
98- LinkerHelperUtil .critical ()
99- );
100- } else {
101- dot7u$mh = downcallHandle (
102- "vec_dot7u" ,
103- FunctionDescriptor .of (JAVA_INT , ADDRESS , ADDRESS , JAVA_INT ),
104- LinkerHelperUtil .critical ()
105- );
106- dot7uBulk$mh = downcallHandle (
107- "vec_dot7u_bulk" ,
108- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS ),
109- LinkerHelperUtil .critical ()
110- );
111- dot7uBulkWithOffsets$mh = downcallHandle (
112- "vec_dot7u_bulk_offsets" ,
113- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS , JAVA_INT , ADDRESS ),
114- LinkerHelperUtil .critical ()
115- );
116- sqr7u$mh = downcallHandle (
117- "vec_sqr7u" ,
118- FunctionDescriptor .of (JAVA_INT , ADDRESS , ADDRESS , JAVA_INT ),
119- LinkerHelperUtil .critical ()
120- );
121- sqr7uBulk$mh = downcallHandle (
122- "vec_sqr7u_bulk" ,
123- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS ),
124- LinkerHelperUtil .critical ()
125- );
126- sqr7uBulkWithOffsets$mh = downcallHandle (
127- "vec_sqr7u_bulk_offsets" ,
128- FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS , JAVA_INT , ADDRESS ),
129- LinkerHelperUtil .critical ()
130- );
131- cosf32$mh = downcallHandle (
132- "vec_cosf32" ,
133- FunctionDescriptor .of (JAVA_FLOAT , ADDRESS , ADDRESS , JAVA_INT ),
134- LinkerHelperUtil .critical ()
135- );
136- dotf32$mh = downcallHandle (
137- "vec_dotf32" ,
138- FunctionDescriptor .of (JAVA_FLOAT , ADDRESS , ADDRESS , JAVA_INT ),
139- LinkerHelperUtil .critical ()
140- );
141- sqrf32$mh = downcallHandle (
142- "vec_sqrf32" ,
143- FunctionDescriptor .of (JAVA_FLOAT , ADDRESS , ADDRESS , JAVA_INT ),
144- LinkerHelperUtil .critical ()
145- );
146- }
53+ String suffix = caps == 2 ? "_2" : "" ;
54+ FunctionDescriptor intSingle = FunctionDescriptor .of (JAVA_INT , ADDRESS , ADDRESS , JAVA_INT );
55+ FunctionDescriptor floatSingle = FunctionDescriptor .of (JAVA_FLOAT , ADDRESS , ADDRESS , JAVA_INT );
56+ FunctionDescriptor bulk = FunctionDescriptor .ofVoid (ADDRESS , ADDRESS , JAVA_INT , JAVA_INT , ADDRESS );
57+ FunctionDescriptor bulkOffsets = FunctionDescriptor .ofVoid (
58+ ADDRESS ,
59+ ADDRESS ,
60+ JAVA_INT ,
61+ JAVA_INT ,
62+ ADDRESS ,
63+ JAVA_INT ,
64+ ADDRESS
65+ );
66+
67+ dot7u$mh = downcallHandle ("vec_dot7u" + suffix , intSingle , LinkerHelperUtil .critical ());
68+ dot7uBulk$mh = downcallHandle ("vec_dot7u_bulk" + suffix , bulk , LinkerHelperUtil .critical ());
69+ dot7uBulkWithOffsets$mh = downcallHandle ("vec_dot7u_bulk_offsets" + suffix , bulkOffsets , LinkerHelperUtil .critical ());
70+ sqr7u$mh = downcallHandle ("vec_sqr7u" + suffix , intSingle , LinkerHelperUtil .critical ());
71+ sqr7uBulk$mh = downcallHandle ("vec_sqr7u_bulk" + suffix , bulk , LinkerHelperUtil .critical ());
72+ sqr7uBulkWithOffsets$mh = downcallHandle ("vec_sqr7u_bulk_offsets" + suffix , bulkOffsets , LinkerHelperUtil .critical ());
73+ dotf32$mh = downcallHandle ("vec_dotf32" + suffix , floatSingle , LinkerHelperUtil .critical ());
74+ sqrf32$mh = downcallHandle ("vec_sqrf32" + suffix , floatSingle , LinkerHelperUtil .critical ());
14775 INSTANCE = new JdkVectorSimilarityFunctions ();
14876 } else {
14977 if (caps < 0 ) {
@@ -157,7 +85,6 @@ public final class JdkVectorLibrary implements VectorLibrary {
15785 sqr7u$mh = null ;
15886 sqr7uBulk$mh = null ;
15987 sqr7uBulkWithOffsets$mh = null ;
160- cosf32$mh = null ;
16188 dotf32$mh = null ;
16289 sqrf32$mh = null ;
16390 INSTANCE = null ;
@@ -243,19 +170,6 @@ static void squareDistance7uBulkWithOffsets(
243170 sqr7uBulkWithOffsets (a , b , length , pitch , offsets , count , result );
244171 }
245172
246- /**
247- * Computes the cosine of given float32 vectors.
248- *
249- * @param a address of the first vector
250- * @param b address of the second vector
251- * @param elementCount the vector dimensions, number of float32 elements in the segment
252- */
253- static float cosineF32 (MemorySegment a , MemorySegment b , int elementCount ) {
254- checkByteSize (a , b );
255- Objects .checkFromIndexSize (0 , elementCount , (int ) a .byteSize () / Float .BYTES );
256- return cosf32 (a , b , elementCount );
257- }
258-
259173 /**
260174 * Computes the dot product of given float32 vectors.
261175 *
@@ -352,14 +266,6 @@ private static void sqr7uBulkWithOffsets(
352266 }
353267 }
354268
355- private static float cosf32 (MemorySegment a , MemorySegment b , int length ) {
356- try {
357- return (float ) JdkVectorLibrary .cosf32$mh .invokeExact (a , b , length );
358- } catch (Throwable t ) {
359- throw new AssertionError (t );
360- }
361- }
362-
363269 private static float dotf32 (MemorySegment a , MemorySegment b , int length ) {
364270 try {
365271 return (float ) JdkVectorLibrary .dotf32$mh .invokeExact (a , b , length );
@@ -382,7 +288,6 @@ private static float sqrf32(MemorySegment a, MemorySegment b, int length) {
382288 static final MethodHandle SQR_HANDLE_7U ;
383289 static final MethodHandle SQR_HANDLE_7U_BULK ;
384290 static final MethodHandle SQR_HANDLE_7U_BULK_WITH_OFFSETS ;
385- static final MethodHandle COS_HANDLE_FLOAT32 ;
386291 static final MethodHandle DOT_HANDLE_FLOAT32 ;
387292 static final MethodHandle SQR_HANDLE_FLOAT32 ;
388293
@@ -427,7 +332,6 @@ private static float sqrf32(MemorySegment a, MemorySegment b, int length) {
427332 );
428333
429334 MethodType singleFloatScorer = MethodType .methodType (float .class , MemorySegment .class , MemorySegment .class , int .class );
430- COS_HANDLE_FLOAT32 = lookup .findStatic (JdkVectorSimilarityFunctions .class , "cosineF32" , singleFloatScorer );
431335 DOT_HANDLE_FLOAT32 = lookup .findStatic (JdkVectorSimilarityFunctions .class , "dotProductF32" , singleFloatScorer );
432336 SQR_HANDLE_FLOAT32 = lookup .findStatic (JdkVectorSimilarityFunctions .class , "squareDistanceF32" , singleFloatScorer );
433337 } catch (NoSuchMethodException | IllegalAccessException e ) {
@@ -465,11 +369,6 @@ public MethodHandle squareDistanceHandle7uBulkWithOffsets() {
465369 return SQR_HANDLE_7U_BULK_WITH_OFFSETS ;
466370 }
467371
468- @ Override
469- public MethodHandle cosineHandleFloat32 () {
470- return COS_HANDLE_FLOAT32 ;
471- }
472-
473372 @ Override
474373 public MethodHandle dotProductHandleFloat32 () {
475374 return DOT_HANDLE_FLOAT32 ;
0 commit comments