1 #!/bin/bash
  2 #
  3 # Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5 #
  6 # This code is free software; you can redistribute it and/or modify it
  7 # under the terms of the GNU General Public License version 2 only, as
  8 # published by the Free Software Foundation.  Oracle designates this
  9 # particular file as subject to the "Classpath" exception as provided
 10 # by Oracle in the LICENSE file that accompanied this code.
 11 #
 12 # This code is distributed in the hope that it will be useful, but WITHOUT
 13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 15 # version 2 for more details (a copy is included in the LICENSE file that
 16 # accompanied this code).
 17 #
 18 # You should have received a copy of the GNU General Public License version
 19 # 2 along with this work; if not, write to the Free Software Foundation,
 20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 21 #
 22 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 23 # or visit www.oracle.com if you need additional information or have any
 24 # questions.
 25 #
 26 
 27 # For manual invocation.
 28 # You can regenerate the source files,
 29 # and you can clean them up.
 30 # FIXME: Move this script under $REPO/make/gensrc/
 31 list_mech_gen() {
 32     ( # List MG files physically present
 33       grep -il 'mechanically generated.*do not edit' $(find * -name \*.java -print)
 34       # List MG files currently deleted (via --clean)
 35       hg status -nd .
 36     ) | egrep '(^|/)(Byte|Short|Int|Long|Float|Double)(Scalar|([0-9Max]+Vector)).*\.java$'
 37 }
 38 case $* in
 39 '')             CLASS_FILTER='*';;
 40 --generate*)    CLASS_FILTER=${2-'*'};;
 41 --clean)        MG=$(list_mech_gen); set -x; rm -f $MG; exit;;
 42 --revert)       MG=$(list_mech_gen); set -x; hg revert $MG; exit;;
 43 --list)         list_mech_gen; exit;;
 44 --help|*)       echo "Usage: $0 [--generate [file] | --clean | --revert | --list]"; exit 1;;
 45 esac
 46 
 47 . config.sh
 48 
 49 # Detect whether to generate the performance tests
 50 generate_perf_tests=false
 51 if [ -d "$PERF_DEST" ]; then
 52   generate_perf_tests=true
 53 fi
 54 
 55 # First, generate the template file.
 56 bash ./gen-template.sh $generate_perf_tests
 57 
 58 Log false "Generating Vector API tests, $(date)\n"
 59 
 60 # Compile SPP
 61 Log true "Compiling SPP... "
 62 compilation=$(${JAVAC} -d . "${JDK_SRC_HOME}/make/jdk/src/classes/build/tools/spp/Spp.java")
 63 Log false "$compilation\n"
 64 Log true "done\n"
 65 
 66 # For each type
 67 for type in byte short int long float double
 68 do
 69   Type="$(tr '[:lower:]' '[:upper:]' <<< ${type:0:1})${type:1}"
 70   TYPE="$(tr '[:lower:]' '[:upper:]' <<< ${type})"
 71   args="-K$type -Dtype=$type -DType=$Type -DTYPE=$TYPE"
 72 
 73   Boxtype=$Type
 74   Wideboxtype=$Boxtype
 75   MaxValue=MAX_VALUE
 76   MinValue=MIN_VALUE
 77 
 78   kind=BITWISE
 79 
 80   bitstype=$type
 81   Bitstype=$Type
 82   Boxbitstype=$Boxtype
 83 
 84   fptype=$type
 85   Fptype=$Type
 86   Boxfptype=$Boxtype
 87 
 88   case $type in
 89     byte)
 90       Wideboxtype=Byte
 91       args="$args -KbyteOrShort"
 92       ;;
 93     short)
 94       Wideboxtype=Short
 95       args="$args -KbyteOrShort"
 96       ;;
 97     int)
 98       Boxtype=Integer
 99       Wideboxtype=Integer
100       fptype=float
101       Fptype=Float
102       Boxfptype=Float
103       args="$args -KintOrLong"
104       ;;
105     long)
106       Wideboxtype=Long
107       fptype=double
108       Fptype=Double
109       Boxfptype=Double
110       args="$args -KintOrLong"
111       ;;
112     float)
113       kind=FP
114       bitstype=int
115       Bitstype=Int
116       Boxbitstype=Integer
117       Wideboxtype=Float
118       MaxValue=POSITIVE_INFINITY
119       MinValue=NEGATIVE_INFINITY
120       ;;
121     double)
122       kind=FP
123       bitstype=long
124       Bitstype=Long
125       Boxbitstype=Long
126       Wideboxtype=Double
127       MaxValue=POSITIVE_INFINITY
128       MinValue=NEGATIVE_INFINITY
129       ;;
130   esac
131 
132   args="$args -K$kind -K$Type -DBoxtype=$Boxtype -DWideboxtype=$Wideboxtype -DMaxValue=$MaxValue -DMinValue=$MinValue"
133   args="$args -Dbitstype=$bitstype -DBitstype=$Bitstype -DBoxbitstype=$Boxbitstype"
134   args="$args -Dfptype=$fptype -DFptype=$Fptype -DBoxfptype=$Boxfptype"
135 
136   abstractvectortype=${typeprefix}${Type}Vector
137   abstractvectorteststype=${typeprefix}${Type}VectorTests
138   abstractbitsvectortype=${typeprefix}${Bitstype}Vector
139   abstractfpvectortype=${typeprefix}${Fptype}Vector
140   args="$args -Dabstractvectortype=$abstractvectortype -Dabstractvectorteststype=$abstractvectorteststype -Dabstractbitsvectortype=$abstractbitsvectortype -Dabstractfpvectortype=$abstractfpvectortype"
141 
142   # Generate tests for operations
143   # For each size
144   Log true "${Type}:"
145 
146   for bits in 64 128 256 512 Max
147   do
148     vectortype=${typeprefix}${Type}${bits}Vector
149     vectorteststype=${typeprefix}${Type}${bits}VectorTests
150     vectorbenchtype=${typeprefix}${Type}${bits}Vector
151     masktype=${typeprefix}${Type}${bits}Mask
152     bitsvectortype=${typeprefix}${Bitstype}${bits}Vector
153     fpvectortype=${typeprefix}${Fptype}${bits}Vector
154     shape=S${bits}Bit
155     Shape=S_${bits}_BIT
156     if [[ "${vectortype}" == "ByteMaxVector" ]]; then
157       args="$args -KByteMax"
158     fi
159     bitargs="$args -Dbits=$bits -Dvectortype=$vectortype -Dvectorteststype=$vectorteststype -Dvectorbenchtype=$vectorbenchtype -Dmasktype=$masktype -Dbitsvectortype=$bitsvectortype -Dfpvectortype=$fpvectortype -Dshape=$shape -DShape=$Shape"
160     if [ $bits == 'Max' ]; then
161       bitargs="$bitargs -KMaxBit"
162     fi
163 
164     # Generate jtreg tests
165     case $vectorteststype in
166     $CLASS_FILTER)
167       Log true " ${bits}_jtreg $vectorteststype.java"
168       Log false "${JAVA} -cp . ${SPP_CLASSNAME} -nel $bitargs -i${TEMPLATE_FILE} -o$vectorteststype.java "
169       TEST_DEST_FILE="${vectorteststype}.java"
170       rm -f ${TEST_DEST_FILE}
171       ${JAVA} -cp . ${SPP_CLASSNAME} -nel $bitargs \
172         -i${TEMPLATE_FILE} \
173         -o${TEST_DEST_FILE}
174       if [ VAR_OS_ENV==windows.cygwin ]; then
175         tr -d  '\r' < ${TEST_DEST_FILE} > temp
176         mv temp ${TEST_DEST_FILE}
177       fi
178       ;;
179     esac
180 
181     if [ $generate_perf_tests == true ]; then
182       # Generate jmh performance tests
183       case $vectorbenchtype in
184       $CLASS_FILTER)
185         Log true " ${bits}_jmh $vectorbenchtype.java"
186         Log false "${JAVA} -cp . ${SPP_CLASSNAME} -nel $bitargs -i${PERF_TEMPLATE_FILE} -o${vectorteststype}Perf.java "
187         PERF_DEST_FILE="${PERF_DEST}/${vectorbenchtype}.java"
188         rm -f ${PERF_DEST_FILE}
189         ${JAVA} -cp . ${SPP_CLASSNAME} -nel $bitargs \
190           -i${PERF_TEMPLATE_FILE} \
191           -o${PERF_DEST_FILE}
192         if [ VAR_OS_ENV==windows.cygwin ]; then
193           tr -d  '\r' < ${PERF_DEST_FILE} > temp
194           mv temp ${PERF_DEST_FILE}
195         fi
196         ;;
197       esac
198     fi
199   done
200 
201   if [ $generate_perf_tests == true ]; then
202     # Generate jmh performance tests
203     case ${Type}Scalar in
204     $CLASS_FILTER)
205     Log true " scalar ${Type}Scalar.java"
206     PERF_DEST_FILE="${PERF_DEST}/${Type}Scalar.java"
207     rm -f ${PERF_DEST_FILE}
208     ${JAVA} -cp . ${SPP_CLASSNAME} -nel $args \
209       -i${PERF_SCALAR_TEMPLATE_FILE} \
210       -o${PERF_DEST_FILE}
211     if [ VAR_OS_ENV==windows.cygwin ]; then
212       tr -d  '\r' < ${PERF_DEST_FILE} > temp
213       mv temp ${PERF_DEST_FILE}
214     fi
215       ;;
216     esac
217   fi
218 
219   # Generate tests for loads and stores
220   # For each size
221   for bits in 64 128 256 512 Max
222   do
223     vectortype=${typeprefix}${Type}${bits}Vector
224     vectorteststype=${typeprefix}${Type}${bits}VectorLoadStoreTests
225     vectorbenchtype=${typeprefix}${Type}${bits}VectorLoadStore
226     masktype=${typeprefix}${Type}${bits}Mask
227     bitsvectortype=${typeprefix}${Bitstype}${bits}Vector
228     fpvectortype=${typeprefix}${Fptype}${bits}Vector
229     shape=S${bits}Bit
230     Shape=S_${bits}_BIT
231     if [[ "${vectortype}" == "ByteMaxVector" ]]; then
232       args="$args -KByteMax"
233     fi
234     bitargs="$args -Dbits=$bits -Dvectortype=$vectortype -Dvectorteststype=$vectorteststype -Dvectorbenchtype=$vectorbenchtype -Dmasktype=$masktype -Dbitsvectortype=$bitsvectortype -Dfpvectortype=$fpvectortype -Dshape=$shape -DShape=$Shape"
235     if [ $bits == 'Max' ]; then
236       bitargs="$bitargs -KMaxBit"
237     fi
238 
239     # Generate
240     case $vectorteststype in
241     $CLASS_FILTER)
242       Log true " ${bits}_ls $vectorteststype.java"
243       Log false "${JAVA} -cp . ${SPP_CLASSNAME} -nel $bitargs -itemplates/X-LoadStoreTest.java.template -o$vectorteststype.java "
244       TEST_DEST_FILE="${vectorteststype}.java"
245       rm -f ${TEST_DEST_FILE}
246       ${JAVA} -cp . ${SPP_CLASSNAME} -nel $bitargs \
247         -itemplates/X-LoadStoreTest.java.template \
248         -o${TEST_DEST_FILE}
249       if [ VAR_OS_ENV==windows.cygwin ]; then
250         tr -d  '\r' < ${TEST_DEST_FILE} > temp
251         mv temp ${TEST_DEST_FILE}
252       fi
253       ;;
254     esac
255 
256     # TODO: Generate jmh performance tests for LoadStore variants
257   done
258 
259   Log true " done\n"
260 
261 done
262 
263 rm -fr build
264