diff --git a/justfile b/justfile index 7ff0bd6..482fc1f 100644 --- a/justfile +++ b/justfile @@ -7,4 +7,7 @@ benchmark: mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json benchmarkOnly: - mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json vecxt.benchmark.AddScalarBenchmark \ No newline at end of file + mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json vecxt.benchmark.AddScalarBenchmark + +setJvm: + eval "$(cs java --jvm 21 --env)" \ No newline at end of file diff --git a/vecxt/jvm/src/package.scala b/vecxt/jvm/src/package.scala index ded42c3..83cd77b 100644 --- a/vecxt/jvm/src/package.scala +++ b/vecxt/jvm/src/package.scala @@ -18,6 +18,7 @@ package vecxt import dev.ludovic.netlib.blas.JavaBLAS.getInstance as blas import scala.util.chaining.* import vecxt.Matrix.* +import jdk.incubator.vector.ByteVector import jdk.incubator.vector.DoubleVector import jdk.incubator.vector.VectorSpecies import jdk.incubator.vector.VectorOperators @@ -56,15 +57,15 @@ object extensions: end extension extension (vec: Array[Boolean]) - inline def countTrue: Int = - val species = VectorSpecies.ofBoolean(VectorSpecies.PREFERRED) - val length = species.length() + inline def countTrue: Int = + val species = ByteVector.SPECIES_PREFERRED + val l = species.length() var sum = 0 var i = 0 while i < species.loopBound(vec.length) do - sum += DoubleVector.fromArray(species, vec, i).compare(VectorOperators.EQ, true).trueCount - i += length + sum = sum + ByteVector.fromBooleanArray(species, vec, i).reduceLanes(VectorOperators.ADD) + i += l end while while i < vec.length do