[vector] Prototype of apply() method on Vector

Kharbas, Kishor kishor.kharbas at intel.com
Mon Feb 18 16:40:27 UTC 2019


Hi,
Modified the webrev in place since I mistakenly uploaded a wrong version.

Also, I wanted to share how a sequence of operations look like with apply() method.

Using specialized operation specific methods:

    public float[] add() {
        for (int i = 0; i < a.length; i += SPECIES.length()) {
            FloatVector av = SPECIES.fromArray(a, i);
            FloatVector bv = SPECIES.fromArray(b, i);
            // ((av * av) + (bv * bv)) * -1.0
            av.mul(av)
                    .add(bv.mul(bv))
                    .neg()
                    .intoArray(c, i);
        }
        return c;
    }

Using the apply() method:

    public float[] addWithApply() {
        for (int i = 0; i < a.length; i += SPECIES.length()) {
            FloatVector av = SPECIES.fromArray(a, i);
            FloatVector bv = SPECIES.fromArray(b, i);
            // ((av * av) + (bv * bv)) * -1.0
            av.apply(BOp.MUL, av)
                    .apply(BOp.ADD, bv.apply(BOp.MUL, bv))
                    .apply(UOp.NEG)
                    .intoArray(c, i);
        }
        return c;
    }

Thanks
Kishor
From: Kharbas, Kishor
Sent: Saturday, February 16, 2019 4:03 PM
To: panama-dev at openjdk.java.net
Cc: Viswanathan, Sandhya <sandhya.viswanathan at intel.com>; Kharbas, Kishor <kishor.kharbas at intel.com>
Subject: [vector] Prototype of apply() method on Vector

Hi Brian, John, Vladimir and others,
There has been discussion on this mail thread before (did not find the mail thread to reply to it) about having an apply() on vectors.

The idea is to reduce the api surface by defining a apply() method which takes the kind of operation to be performed. Here is an attempt to prototype this method,
http://cr.openjdk.java.net/~kkharbas/vector-api/webrev-apply.00

This prototype does generate optimal vector code just like operation specific methods.

Please let me know your thoughts.

Thanks,
Kishor


More information about the panama-dev mailing list