1 /*
  2  *  Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
  3  *  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  *  This code is free software; you can redistribute it and/or modify it
  6  *  under the terms of the GNU General Public License version 2 only, as
  7  *  published by the Free Software Foundation.
  8  *
  9  *  This code is distributed in the hope that it will be useful, but WITHOUT
 10  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  *  version 2 for more details (a copy is included in the LICENSE file that
 13  *  accompanied this code).
 14  *
 15  *  You should have received a copy of the GNU General Public License version
 16  *  2 along with this work; if not, write to the Free Software Foundation,
 17  *  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  *  Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  *  or visit www.oracle.com if you need additional information or have any
 21  *  questions.
 22  *
 23  */
 24 
 25 package org.openjdk.bench.jdk.incubator.vector;
 26 
 27 import jdk.incubator.vector.*;
 28 import java.util.concurrent.TimeUnit;
 29 import org.openjdk.jmh.annotations.*;
 30 
 31 @OutputTimeUnit(TimeUnit.MILLISECONDS)
 32 @State(Scope.Thread)
 33 @Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
 34 public class MaskCastOperationsBenchmark {
 35     VectorMask<Byte> bmask64;
 36     VectorMask<Byte> bmask128;
 37     VectorMask<Byte> bmask256;
 38 
 39     VectorMask<Short> smask64;
 40     VectorMask<Short> smask128;
 41     VectorMask<Short> smask256;
 42     VectorMask<Short> smask512;
 43 
 44     VectorMask<Integer> imask64;
 45     VectorMask<Integer> imask128;
 46     VectorMask<Integer> imask256;
 47     VectorMask<Integer> imask512;
 48 
 49     VectorMask<Long> lmask128;
 50     VectorMask<Long> lmask256;
 51     VectorMask<Long> lmask512;
 52 
 53     static final boolean [] mask_arr = {
 54        false, false, false, true, false, false, false, false,
 55        false, false, false, true, false, false, false, false,
 56        false, false, false, true, false, false, false, false,
 57        true, true, true, true, true, true, true, true,
 58        true, true, true, true, true, true, true, true,
 59        false, false, false, true, false, false, false, false,
 60        false, false, false, true, false, false, false, false,
 61        false, false, false, true, false, false, false, false
 62     };
 63 
 64     @Setup(Level.Trial)
 65     public void BmSetup() {
 66         bmask64 = VectorMask.fromArray(ByteVector.SPECIES_64, mask_arr, 0);
 67         bmask128 = VectorMask.fromArray(ByteVector.SPECIES_128, mask_arr, 0);
 68         bmask256 = VectorMask.fromArray(ByteVector.SPECIES_256, mask_arr, 0);
 69 
 70         smask64 = VectorMask.fromArray(ShortVector.SPECIES_64, mask_arr, 0);
 71         smask128 = VectorMask.fromArray(ShortVector.SPECIES_128, mask_arr, 0);
 72         smask256 = VectorMask.fromArray(ShortVector.SPECIES_256, mask_arr, 0);
 73         smask512 = VectorMask.fromArray(ShortVector.SPECIES_512, mask_arr, 0);
 74 
 75         imask64 = VectorMask.fromArray(IntVector.SPECIES_64, mask_arr, 0);
 76         imask128 = VectorMask.fromArray(IntVector.SPECIES_128, mask_arr, 0);
 77         imask256 = VectorMask.fromArray(IntVector.SPECIES_256, mask_arr, 0);
 78         imask512 = VectorMask.fromArray(IntVector.SPECIES_512, mask_arr, 0);
 79 
 80         lmask128 = VectorMask.fromArray(LongVector.SPECIES_128, mask_arr, 0);
 81         lmask256 = VectorMask.fromArray(LongVector.SPECIES_256, mask_arr, 0);
 82         lmask512 = VectorMask.fromArray(LongVector.SPECIES_512, mask_arr, 0);
 83     }
 84 
 85     @Benchmark
 86     public VectorMask<Short> microMaskCastByte64ToShort128() {
 87         return bmask64.cast(ShortVector.SPECIES_128);
 88     }
 89 
 90     @Benchmark
 91     public VectorMask<Integer> microMaskCastByte64ToInteger256() {
 92         return bmask64.cast(IntVector.SPECIES_256);
 93     }
 94 
 95     @Benchmark
 96     public VectorMask<Long> microMaskCastByte64ToLong512() {
 97         return bmask64.cast(LongVector.SPECIES_512);
 98     }
 99 
100     @Benchmark
101     public VectorMask<Short> microMaskCastByte128ToShort256() {
102         return bmask128.cast(ShortVector.SPECIES_256);
103     }
104 
105     @Benchmark
106     public VectorMask<Integer> microMaskCastByte128ToInteger512() {
107         return bmask128.cast(IntVector.SPECIES_512);
108     }
109 
110     @Benchmark
111     public VectorMask<Short> microMaskCastByte256ToShort512() {
112         return bmask256.cast(ShortVector.SPECIES_512);
113     }
114 
115     @Benchmark
116     public VectorMask<Integer> microMaskCastShort64ToInteger128() {
117         return smask64.cast(IntVector.SPECIES_128);
118     }
119 
120     @Benchmark
121     public VectorMask<Long> microMaskCastShort64ToLong256() {
122         return smask64.cast(LongVector.SPECIES_256);
123     }
124 
125     @Benchmark
126     public VectorMask<Byte> microMaskCastShort128ToByte64() {
127         return smask128.cast(ByteVector.SPECIES_64);
128     }
129 
130     @Benchmark
131     public VectorMask<Integer> microMaskCastShort128ToInteger256() {
132         return smask128.cast(IntVector.SPECIES_256);
133     }
134 
135     @Benchmark
136     public VectorMask<Long> microMaskCastShort128ToLong512() {
137         return smask128.cast(LongVector.SPECIES_512);
138     }
139 
140     @Benchmark
141     public VectorMask<Byte> microMaskCastShort256ToByte128() {
142         return smask256.cast(ByteVector.SPECIES_128);
143     }
144 
145     @Benchmark
146     public VectorMask<Integer> microMaskCastShort256ToInteger512() {
147         return smask256.cast(IntVector.SPECIES_512);
148     }
149 
150     @Benchmark
151     public VectorMask<Byte> microMaskCastShort512ToByte256() {
152         return smask512.cast(ByteVector.SPECIES_256);
153     }
154 
155     @Benchmark
156     public VectorMask<Long> microMaskCastInteger64ToLong128() {
157         return imask64.cast(LongVector.SPECIES_128);
158     }
159 
160     @Benchmark
161     public VectorMask<Short> microMaskCastInteger128ToShort64() {
162         return imask128.cast(ShortVector.SPECIES_64);
163     }
164 
165     @Benchmark
166     public VectorMask<Long> microMaskCastInteger128ToLong256() {
167         return imask128.cast(LongVector.SPECIES_256);
168     }
169 
170     @Benchmark
171     public VectorMask<Byte> microMaskCastInteger256ToByte64() {
172         return imask256.cast(ByteVector.SPECIES_64);
173     }
174 
175     @Benchmark
176     public VectorMask<Short> microMaskCastInteger256ToShort128() {
177         return imask256.cast(ShortVector.SPECIES_128);
178     }
179 
180     @Benchmark
181     public VectorMask<Long> microMaskCastInteger256ToLong512() {
182         return imask256.cast(LongVector.SPECIES_512);
183     }
184 
185     @Benchmark
186     public VectorMask<Byte> microMaskCastInteger512ToByte128() {
187         return imask512.cast(ByteVector.SPECIES_128);
188     }
189 
190     @Benchmark
191     public VectorMask<Short> microMaskCastInteger512ToShort256() {
192         return imask512.cast(ShortVector.SPECIES_256);
193     }
194 
195     @Benchmark
196     public VectorMask<Integer> microMaskCastLong128ToInteger64() {
197         return lmask128.cast(IntVector.SPECIES_64);
198     }
199 
200     @Benchmark
201     public VectorMask<Short> microMaskCastLong256ToShort64() {
202         return lmask256.cast(ShortVector.SPECIES_64);
203     }
204 
205     @Benchmark
206     public VectorMask<Integer> microMaskCastLong256ToInteger128() {
207         return lmask256.cast(IntVector.SPECIES_128);
208     }
209 
210     @Benchmark
211     public VectorMask<Byte> microMaskCastLong512ToByte64() {
212         return lmask512.cast(ByteVector.SPECIES_64);
213     }
214 
215     @Benchmark
216     public VectorMask<Short> microMaskCastLong512ToShort128() {
217         return lmask512.cast(ShortVector.SPECIES_128);
218     }
219 
220     @Benchmark
221     public VectorMask<Integer> microMaskCastLong512ToInteger256() {
222         return lmask512.cast(IntVector.SPECIES_256);
223     }
224 }