From 65646ff98c2d39b0dc25afdb92b4917832c2c014 Mon Sep 17 00:00:00 2001 From: Simon Parten Date: Wed, 25 Sep 2024 16:46:47 +0200 Subject: [PATCH] . --- justfile | 5 ++++- vecxt/jvm/src/package.scala | 11 ++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) 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