Skip to content

Commit

Permalink
Use fma in VectorSimdOps.cosineSimilarity
Browse files Browse the repository at this point in the history
  • Loading branch information
jkni committed Nov 6, 2024
1 parent b383af2 commit f28634a
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static float cosineSimilarity(MemorySegmentVectorFloat v1, MemorySegmentVectorFl
for (int i = 0; i < vectorizedLength; i += FloatVector.SPECIES_PREFERRED.length()) {
var a = FloatVector.fromMemorySegment(FloatVector.SPECIES_PREFERRED, v1.get(), v1.offset(i), ByteOrder.LITTLE_ENDIAN);
var b = FloatVector.fromMemorySegment(FloatVector.SPECIES_PREFERRED, v2.get(), v2.offset(i), ByteOrder.LITTLE_ENDIAN);
vsum = vsum.add(a.mul(b));
vsum = a.fma(b, vsum);
vaMagnitude = a.fma(a, vaMagnitude);
vbMagnitude = b.fma(b, vbMagnitude);
}
Expand All @@ -269,7 +269,7 @@ static float cosineSimilarity(MemorySegmentVectorFloat v1, int v1offset, MemoryS
for (int i = 0; i < vectorizedLength; i += FloatVector.SPECIES_PREFERRED.length()) {
var a = FloatVector.fromMemorySegment(FloatVector.SPECIES_PREFERRED, v1.get(), v1.offset(v1offset + i), ByteOrder.LITTLE_ENDIAN);
var b = FloatVector.fromMemorySegment(FloatVector.SPECIES_PREFERRED, v2.get(), v2.offset(v2offset + i), ByteOrder.LITTLE_ENDIAN);
vsum = vsum.add(a.mul(b));
vsum = a.fma(b, vsum);
vaMagnitude = a.fma(a, vaMagnitude);
vbMagnitude = b.fma(b, vbMagnitude);
}
Expand Down

0 comments on commit f28634a

Please sign in to comment.