Created
August 6, 2019 18:53
-
-
Save schmee/d1a705acc49a2f5f08e34fcddfe736e7 to your computer and use it in GitHub Desktop.
Vector API in Clojure!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector_clj/core$i256_add.invoke(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; [0x000000011f8acdc0, 0x000000011f8ad058] 664 bytes | |
[Entry Point] | |
[Constants] | |
# {method} {0x000000013253d3b8} 'invoke' '(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;' in 'vector_clj/core$i256_add' | |
# this: rsi:rsi = 'vector_clj/core$i256_add' | |
# parm0: rdx:rdx = 'java/lang/Object' | |
# parm1: rcx:rcx = 'java/lang/Object' | |
# [sp+0x30] (sp of caller) | |
..... | |
0x000000011f8acec3: prefetchw BYTE PTR [r10+0x180] | |
0x000000011f8acecb: mov r10d,DWORD PTR [rcx+0xc] | |
0x000000011f8acecf: mov r8d,DWORD PTR [rdx+0xc] | |
0x000000011f8aced3: vmovdqu ymm0,YMMWORD PTR [r12+r10*8+0x10] | |
0x000000011f8aceda: vmovdqu ymm1,YMMWORD PTR [r12+r8*8+0x10] | |
0x000000011f8acee1: vpaddd ymm0,ymm1,ymm0 | |
0x000000011f8acee5: vmovdqu YMMWORD PTR [rax+0x10],ymm0 | |
0x000000011f8aceea: mov r10,rbx | |
0x000000011f8aceed: mov r11,rax | |
.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns vector-clj.core | |
(:require [clojure.reflect :as r] | |
[criterium.core :as c]) | |
(:import [jdk.incubator.vector | |
Int256Vector | |
IntVector | |
IntVector$IntSpecies | |
VectorSpecies])) | |
(set! *warn-on-reflection* true) | |
(def ^IntVector$IntSpecies I256 (IntVector/SPECIES_PREFERRED)) | |
(def i1 (int-array (range 1 9))) | |
(def i2 (int-array (range 9 17))) | |
(defn ->Vector ^Int256Vector [ia] | |
(.fromArray I256 ia 0)) | |
(defn i256-add [^Int256Vector v1 ^Int256Vector v2] | |
(.add v1 v2)) | |
(def v1 (->Vector i1)) | |
(def v2 (->Vector i2)) | |
(def v3 (i256-add v1 v2)) | |
(defn -main [& args] | |
(c/quick-bench (i256-add v1 v2))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject vector-clj "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" | |
:url "https://www.eclipse.org/legal/epl-2.0/"} | |
:dependencies [[org.clojure/clojure "1.10.1"] | |
[org.clojure/tools.namespace "0.2.11"] | |
[criterium "0.4.5"]] | |
:repl-options {:init-ns vector-clj.core} | |
:source-paths ["src" "env/dev/clj" "test"] | |
:main "vector-clj.core" | |
:jvm-opts ["--add-modules" | |
"jdk.incubator.vector" | |
"-XX:+UnlockDiagnosticVMOptions" | |
; "-XX:+PrintCompilation" | |
; "-XX:+PrintInlining" | |
"-XX:+PrintAssembly"] | |
:profiles {:dev {:dependencies [[pjstadig/humane-test-output "0.9.0"]] | |
:plugins [[com.jakemccrary/lein-test-refresh "0.22.0"]] | |
:injections [(require 'pjstadig.humane-test-output) | |
(pjstadig.humane-test-output/activate!)]}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment