Coder Social home page Coder Social logo

vector-handle's Introduction

vector-handle

A high level API to express vectorized operations on primitive arrays in Java allowing to specify the vectorized operations as a simple lambda.

example

private static final VH = VectorHandle.of(lookup(), int.class, int.class, int.class);
...
var dest = new int[4];
var a = new int[] { 1, 2, 3, 4 };
var b = new int[] { 4, 4, 4, 4 };
VH.apply(dest, a, b, (x, y) -> x + y * 2);
System.out.println(Arrays.toString(dest)); // [9, 10, 11, 12]

available operations

The lambda used by the variations of the method apply() only accept the following operator

  • constants (any static final fields): Foo.A_CONSTANT
  • literals: 1, 1L, 1.0f, 1.0
  • parameters (any lambda parameters): x, y, etc
  • Unary operator: -
  • Binary operators: +, -, *, /, Math.min(), Math.max()

how to build it

This project requires the JDK 16, it uses internally the Vector API (jdk.incubator.vector)

  mvn packages

how it works ?

Lambdas in Java are desugared as static method where there are declared. To find the corresponding class and method name to the lambda, the lambda is first serialized by explicitly calling writeReplace() (all serialized lambda proxies have that method) to get the resulting java.lang.invoke.SerializedLambda. Then using ASM, the bytecode lambda method is read and transformed to a tree of expressions (AST) using a simple abstract interpretation. From the AST, a new bytecode using the vector API (jdk.incubator.vector) is generated with ASM and loaded using Lookup.defineHiddenClass. When calling apply, a mutable call site is used to do all the operations above and see the generated bytecode as a method handle.

vector-handle's People

Contributors

forax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

apete

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.