< prev index next >

test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/crypto/ChaChaBench.java

Print this page
rev 55594 : tests and benchmark changes


  64     @Benchmark
  65     public void encrypt128() {
  66         cc20_S128.chacha20(key, nonce, counter, in, out);
  67     }
  68 
  69     @Benchmark
  70     public void encrypt256() {
  71         cc20_S256.chacha20(key, nonce, counter, in, out);
  72     }
  73 
  74     @Benchmark
  75     public void encrypt512() {
  76         cc20_S512.chacha20(key, nonce, counter, in, out);
  77     }
  78 
  79     private static class ChaChaVector {
  80 
  81         private static final int[] STATE_CONSTANTS =
  82             new int[]{0x61707865, 0x3320646e, 0x79622d32, 0x6b206574};
  83 
  84         private final IntVector.IntSpecies intSpecies;
  85         private final int numBlocks;
  86 
  87         private final Vector.Shuffle<Integer> rot1;
  88         private final Vector.Shuffle<Integer> rot2;
  89         private final Vector.Shuffle<Integer> rot3;
  90 
  91         private final IntVector counterAdd;
  92 
  93         private final Vector.Shuffle<Integer> shuf0;
  94         private final Vector.Shuffle<Integer> shuf1;
  95         private final Vector.Shuffle<Integer> shuf2;
  96         private final Vector.Shuffle<Integer> shuf3;
  97 
  98         private final Vector.Mask<Integer> mask0;
  99         private final Vector.Mask<Integer> mask1;
 100         private final Vector.Mask<Integer> mask2;
 101         private final Vector.Mask<Integer> mask3;
 102 
 103         private final int[] state;
 104 
 105         public ChaChaVector(Vector.Shape shape) {
 106             this.intSpecies = IntVector.species(shape);
 107             this.numBlocks = intSpecies.length() / 4;
 108 
 109             this.rot1 = makeRotate(1);
 110             this.rot2 = makeRotate(2);
 111             this.rot3 = makeRotate(3);
 112 
 113             this.counterAdd = makeCounterAdd();
 114 
 115             this.shuf0 = makeRearrangeShuffle(0);
 116             this.shuf1 = makeRearrangeShuffle(1);
 117             this.shuf2 = makeRearrangeShuffle(2);
 118             this.shuf3 = makeRearrangeShuffle(3);
 119 
 120             this.mask0 = makeRearrangeMask(0);
 121             this.mask1 = makeRearrangeMask(1);
 122             this.mask2 = makeRearrangeMask(2);
 123             this.mask3 = makeRearrangeMask(3);
 124 
 125             this.state = new int[numBlocks * 16];
 126         }




  64     @Benchmark
  65     public void encrypt128() {
  66         cc20_S128.chacha20(key, nonce, counter, in, out);
  67     }
  68 
  69     @Benchmark
  70     public void encrypt256() {
  71         cc20_S256.chacha20(key, nonce, counter, in, out);
  72     }
  73 
  74     @Benchmark
  75     public void encrypt512() {
  76         cc20_S512.chacha20(key, nonce, counter, in, out);
  77     }
  78 
  79     private static class ChaChaVector {
  80 
  81         private static final int[] STATE_CONSTANTS =
  82             new int[]{0x61707865, 0x3320646e, 0x79622d32, 0x6b206574};
  83 
  84         private final Vector.Species<Integer> intSpecies;
  85         private final int numBlocks;
  86 
  87         private final Vector.Shuffle<Integer> rot1;
  88         private final Vector.Shuffle<Integer> rot2;
  89         private final Vector.Shuffle<Integer> rot3;
  90 
  91         private final IntVector counterAdd;
  92 
  93         private final Vector.Shuffle<Integer> shuf0;
  94         private final Vector.Shuffle<Integer> shuf1;
  95         private final Vector.Shuffle<Integer> shuf2;
  96         private final Vector.Shuffle<Integer> shuf3;
  97 
  98         private final Vector.Mask<Integer> mask0;
  99         private final Vector.Mask<Integer> mask1;
 100         private final Vector.Mask<Integer> mask2;
 101         private final Vector.Mask<Integer> mask3;
 102 
 103         private final int[] state;
 104 
 105         public ChaChaVector(Vector.Shape shape) {
 106             this.intSpecies = Vector.Species.of(Integer.class, shape);
 107             this.numBlocks = intSpecies.length() / 4;
 108 
 109             this.rot1 = makeRotate(1);
 110             this.rot2 = makeRotate(2);
 111             this.rot3 = makeRotate(3);
 112 
 113             this.counterAdd = makeCounterAdd();
 114 
 115             this.shuf0 = makeRearrangeShuffle(0);
 116             this.shuf1 = makeRearrangeShuffle(1);
 117             this.shuf2 = makeRearrangeShuffle(2);
 118             this.shuf3 = makeRearrangeShuffle(3);
 119 
 120             this.mask0 = makeRearrangeMask(0);
 121             this.mask1 = makeRearrangeMask(1);
 122             this.mask2 = makeRearrangeMask(2);
 123             this.mask3 = makeRearrangeMask(3);
 124 
 125             this.state = new int[numBlocks * 16];
 126         }


< prev index next >