1 #!/bin/bash
  2 #
  3 # Copyright (c) 2018, 2024, 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.
  9 #
 10 # This code is distributed in the hope that it will be useful, but WITHOUT
 11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13 # version 2 for more details (a copy is included in the LICENSE file that
 14 # accompanied this code).
 15 #
 16 # You should have received a copy of the GNU General Public License version
 17 # 2 along with this work; if not, write to the Free Software Foundation,
 18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19 #
 20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21 # or visit www.oracle.com if you need additional information or have any
 22 # questions.
 23 #
 24 
 25 generate_perf_tests=$1
 26 
 27 TEMPLATE_FOLDER="templates/"
 28 
 29 unit_output="unit_tests.template"
 30 perf_output="perf_tests.template"
 31 perf_scalar_output="perf_scalar_tests.template"
 32 
 33 unary="Unary-op"
 34 unary_masked="Unary-Masked-op"
 35 unary_scalar="Unary-Scalar-op"
 36 ternary="Ternary-op"
 37 ternary_masked="Ternary-Masked-op"
 38 ternary_broadcast="Ternary-Broadcast-op"
 39 ternary_broadcast_masked="Ternary-Broadcast-Masked-op"
 40 ternary_double_broadcast="Ternary-Double-Broadcast-op"
 41 ternary_double_broadcast_masked="Ternary-Double-Broadcast-Masked-op"
 42 ternary_scalar="Ternary-Scalar-op"
 43 binary="Binary-op"
 44 binary_masked="Binary-Masked-op"
 45 binary_memop="Binary-mem-op"
 46 binary_masked_memop="Binary-Masked-mem-op"
 47 saturating_binary="SaturatingBinary-op"
 48 saturating_binary_masked="SaturatingBinary-Masked-op"
 49 saturating_binary_assocative="SaturatingBinary-op-associative"
 50 saturating_binary_assocative_masked="SaturatingBinary-Masked-op-associative"
 51 binary_broadcast="Binary-Broadcast-op"
 52 binary_broadcast_masked="Binary-Broadcast-Masked-op"
 53 binary_broadcast_long="Binary-Broadcast-Long-op"
 54 binary_broadcast_masked_long="Binary-Broadcast-Masked-Long-op"
 55 binary_scalar="Binary-Scalar-op"
 56 blend="Blend-op"
 57 test_template="Test"
 58 compare_template="Compare"
 59 compare_masked_template="Compare-Masked"
 60 compare_broadcast_template="Compare-Broadcast"
 61 reduction_scalar="Reduction-Scalar-op"
 62 reduction_scalar_func="Reduction-Scalar-op-func"
 63 reduction_scalar_masked="Reduction-Scalar-Masked-op"
 64 reduction_scalar_masked_func="Reduction-Scalar-Masked-op-func"
 65 reduction_op="Reduction-op"
 66 reduction_op_func="Reduction-op-func"
 67 reduction_op_masked="Reduction-Masked-op"
 68 reduction_op_masked_func="Reduction-Masked-op-func"
 69 reduction_saturating_op="SaturatingReduction-op"
 70 reduction_saturating_op_masked="SaturatingReduction-Masked-op"
 71 unary_math_template="Unary-op-math"
 72 binary_math_template="Binary-op-math"
 73 binary_math_broadcast_template="Binary-Broadcast-op-math"
 74 bool_reduction_scalar="BoolReduction-Scalar-op"
 75 bool_reduction_template="BoolReduction-op"
 76 with_op_template="With-Op"
 77 shift_template="Shift-op"
 78 shift_masked_template="Shift-Masked-op"
 79 shift_const_template="Shift-Const-op"
 80 shift_masked_const_template="Shift-Masked-Const-op"
 81 get_template="Get-op"
 82 rearrange_template="Rearrange"
 83 compressexpand_template="CompressExpand"
 84 broadcast_template="Broadcast"
 85 zero_template="Zero"
 86 slice_template="Slice-op"
 87 slice1_template="Slice-bop"
 88 slice1_masked_template="Slice-Masked-bop"
 89 unslice_template="Unslice-op"
 90 unslice1_template="Unslice-bop"
 91 unslice1_masked_template="Unslice-Masked-bop"
 92 miscellaneous_template="Miscellaneous"
 93 
 94 function replace_variables {
 95   local filename=$1
 96   local output=$2
 97   local kernel=$3
 98   local test=$4
 99   local op=$5
100   local init=$6
101   local guard=$7
102   local masked=$8
103   local op_name=$9
104   local kernel_smoke=${10}
105 
106   if [ "x${kernel}" != "x" ]; then
107     local kernel_escaped=$(echo -e "$kernel" | tr '\n' '`')
108     sed "s/\[\[KERNEL\]\]/${kernel_escaped}/g" $filename > ${filename}.current1
109     cat ${filename}.current1 | tr '`' "\n" > ${filename}.current
110     rm -f "${filename}.current1"
111   else
112     cp $filename ${filename}.current
113   fi
114 
115   # Check if we need to do multiple replacements
116   # If you want to emit for an operation using lanewise(VectorOperator.**, ..) and also using dedicated instruction (e.g. add(..)), then
117   # pass the 'test' argument as "OPERATOR_NAME+func_Name" (e.g. "ADD+add")
118   # if there is a masked version available for the operation add "withMask" to 'test' argument (e.g. "ADD+add+withMask")
119   local test_func=""
120   local withMask=""
121   local tests=($(awk -F+ '{$1=$1} 1' <<< $test))
122   if [ "${tests[2]}" == "withMask" ]; then
123     test=${tests[0]}
124     test_func=${tests[1]}
125     withMask=${tests[2]}
126   elif [ "${tests[1]}" == "withMask" ]; then
127     test=""
128     test_func=${tests[0]}
129     withMask=${tests[1]}
130   elif [ "${tests[1]}" != "" ]; then
131     test=${tests[0]}
132     test_func=${tests[1]}
133   fi
134 
135   sed_prog="
136     s/\<OPTIONAL\>\(.*\)\<\\OPTIONAL\>/\1/g
137     s/\[\[TEST_TYPE\]\]/${masked}/g
138     s/\[\[TEST_OP\]\]/${op}/g
139     s/\[\[TEST_INIT\]\]/${init}/g
140     s/\[\[OP_NAME\]\]/${op_name}/g
141   "
142   sed_prog_2="$sed_prog
143     s/\[\[TEST\]\]/${test_func}/g
144     s/[.][^(]*(VectorOperators.$test_func, /.$test_func(/g
145     s/[.][^(]*(VectorOperators.$test_func,/.$test_func(/g
146     s/[.][^(]*(VectorOperators.$test_func/.$test_func(/g
147   "
148   sed_prog="
149     $sed_prog
150     s/\[\[TEST\]\]/${test}/g
151   "
152 
153   # Guard the test if necessary
154   if [ "$guard" != "" ]; then
155     echo -e "#if[${guard}]" >> $output
156   fi
157   if [ "$test" != "" ]; then
158     sed -e "$sed_prog" < ${filename}.current >> $output
159   fi
160   # If we also have a dedicated function for the operation then use 2nd sed expression
161   if [[ "$filename" == *"Unit"* ]] && [ "$test_func" != "" ]; then
162     if [ "$masked" == "" ] || [ "$withMask" != "" ]; then
163       if [ ! -z "$kernel_smoke" ]; then
164         local kernel_smoke_escaped=$(echo -e "$kernel_smoke" | tr '\n' '`')
165         sed "s/\[\[KERNEL\]\]/${kernel_smoke_escaped}/g" $filename > ${filename}.scurrent1
166         cat ${filename}.scurrent1 | tr '`' "\n" > ${filename}.scurrent
167         rm -f "${filename}.scurrent1"
168       else
169         cp $filename.current ${filename}.scurrent
170       fi
171       sed -e "$sed_prog_2" < ${filename}.scurrent >> $output
172       rm -f ${filename}.scurrent
173     fi
174   fi
175   if [ "$guard" != "" ]; then
176     echo -e "#end[${guard}]" >> $output
177   fi
178 
179   rm -f ${filename}.current
180 }
181 
182 function gen_op_tmpl {
183   local template=$1
184   local test=$2
185   local op=$3
186   local guard=""
187   local init=""
188   if [ $# -gt 3 ]; then
189     guard=$4
190   fi
191   if [ $# == 5 ]; then
192     init=$5
193   fi
194 
195   local masked=""
196   if [[ $template == *"Masked"* ]]; then
197     masked="Masked"
198   fi
199 
200   local op_name=""
201   if [[ $template == *"Shift"* ]]; then
202     op_name="Shift"
203   elif [[ $template == *"Get"* ]]; then
204     op_name="extract"
205   fi
206 
207   local kernel_filename="${TEMPLATE_FOLDER}/Kernel-${template}.template"
208   local kernel_smoke_filename="${TEMPLATE_FOLDER}/Kernel-${template}-smoke.template"
209   local unit_filename="${TEMPLATE_FOLDER}/Unit-${template}.template"
210   if [ ! -f $unit_filename ]; then
211     # Leverage general unit code snippet if no specialization exists
212     unit_filename="${TEMPLATE_FOLDER}/Unit-${template%_*}.template"
213     echo $unit_filename
214   fi
215 
216   local kernel=""
217   if [ -f $kernel_filename ]; then
218     kernel="$(cat $kernel_filename)"
219   fi
220 
221   local kernel_smoke=""
222   if [ -f $kernel_smoke_filename ]; then
223     kernel_smoke="$(cat $kernel_smoke_filename)"
224   else
225     kernel_smoke="$kernel"
226   fi
227 
228   # Replace template variables in unit test files (if any)
229   replace_variables $unit_filename $unit_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" "$kernel_smoke"
230 
231   local gen_perf_tests=$generate_perf_tests
232   if [[ $template == *"-Broadcast-"* ]] || [[ $template == "Miscellaneous" ]] ||
233      [[ $template == *"Compare-Masked"* ]] || [[ $template == *"Compare-Broadcast"* ]]; then
234     gen_perf_tests=false
235   fi
236   if [ $gen_perf_tests == true ]; then
237     # Replace template variables in performance test files (if any)
238     local perf_wrapper_filename="${TEMPLATE_FOLDER}/Perf-wrapper.template"
239     local perf_vector_filename="${TEMPLATE_FOLDER}/Perf-${template}.template"
240     local perf_scalar_filename="${TEMPLATE_FOLDER}/Perf-Scalar-${template}.template"
241 
242     if [ -f $perf_vector_filename ]; then
243       replace_variables $perf_vector_filename  $perf_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" ""
244     elif [ -f $kernel_filename ]; then
245       replace_variables $perf_wrapper_filename $perf_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" ""
246     elif [[ $template != *"-Scalar-"* ]] && [[ $template != "Get-op" ]] && [[ $template != "With-Op" ]]; then
247       echo "Warning: missing perf: $@"
248     fi
249 
250     if [ -f $perf_scalar_filename ]; then
251       replace_variables $perf_scalar_filename $perf_scalar_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" ""
252     elif [[ $template != *"-Scalar-"* ]] && [[ $template != "Get-op" ]] && [[ $template != "With-Op" ]]; then
253       echo "Warning: Missing PERF SCALAR: $perf_scalar_filename"
254     fi
255   fi
256 }
257 
258 function gen_binary_alu_op {
259   echo "Generating binary op $1 ($2)..."
260   gen_op_tmpl $binary "$@"
261   gen_op_tmpl $binary_masked "$@"
262 }
263 
264 function gen_binary_alu_mem_op {
265   echo "Generating binary op $1 ($2)..."
266   gen_op_tmpl $binary_memop "$@"
267   gen_op_tmpl $binary_masked_memop "$@"
268 }
269 
270 function gen_binary_alu_bcst_op {
271   echo "Generating binary broadcast op $1 ($2)..."
272   gen_op_tmpl $binary_broadcast "$@"
273   gen_op_tmpl $binary_broadcast_masked "$@"
274 }
275 
276 function gen_binary_alu_bcst_long_op {
277   echo "Generating binary broadcast long op $1 ($2)..."
278   gen_op_tmpl $binary_broadcast_long "$@"
279   gen_op_tmpl $binary_broadcast_masked_long "$@"
280 }
281 
282 function gen_shift_op {
283   echo "Generating Shift constant op $1 ($2)..."
284   gen_op_tmpl $shift_template "$@"
285   gen_op_tmpl $shift_masked_template "$@"
286 }
287 
288 function gen_shift_cst_op {
289   echo "Generating Shift constant op $1 ($2)..."
290   gen_op_tmpl $shift_const_template "$@"
291   gen_op_tmpl $shift_masked_const_template "$@"
292 }
293 
294 function gen_unary_alu_op {
295   echo "Generating unary op $1 ($2)..."
296   gen_op_tmpl $unary_scalar "$@"
297   gen_op_tmpl $unary "$@"
298   gen_op_tmpl $unary_masked "$@"
299 }
300 
301 function gen_ternary_alu_op {
302   echo "Generating ternary op $1 ($2)..."
303   gen_op_tmpl $ternary_scalar "$@"
304   gen_op_tmpl $ternary "$@"
305   gen_op_tmpl $ternary_masked "$@"
306 }
307 
308 function gen_ternary_alu_bcst_op {
309   echo "Generating ternary broadcast op $1 ($2)..."
310   gen_op_tmpl $ternary_broadcast "$@"
311   gen_op_tmpl $ternary_broadcast_masked "$@"
312 }
313 
314 function gen_ternary_alu_double_bcst_op {
315   echo "Generating ternary double broadcast op $1 ($2)..."
316   gen_op_tmpl $ternary_double_broadcast "$@"
317   gen_op_tmpl $ternary_double_broadcast_masked "$@"
318 }
319 
320 function gen_binary_op {
321   echo "Generating binary op $1 ($2)..."
322 #  gen_op_tmpl $binary_scalar "$@"
323   gen_op_tmpl $binary "$@"
324   gen_op_tmpl $binary_masked "$@"
325 }
326 
327 function gen_saturating_binary_op {
328   echo "Generating binary op $1 ($2)..."
329   gen_op_tmpl $saturating_binary "$@"
330   gen_op_tmpl $saturating_binary_masked "$@"
331 }
332 
333 function gen_saturating_binary_op_associative {
334   echo "Generating saturating binary associative op $1 ($2)..."
335   gen_op_tmpl $saturating_binary_assocative "$@"
336   gen_op_tmpl $saturating_binary_assocative_masked "$@"
337 }
338 
339 function gen_binary_op_no_masked {
340   echo "Generating binary op $1 ($2)..."
341 #  gen_op_tmpl $binary_scalar "$@"
342   gen_op_tmpl $binary "$@"
343 }
344 
345 function gen_binary_bcst_op_no_masked {
346   echo "Generating binary broadcast op $1 ($2)..."
347   gen_op_tmpl $binary_broadcast "$@"
348 }
349 
350 function gen_compare_op {
351   echo "Generating compare op $1 ($2)..."
352   gen_op_tmpl $compare_template "$@"
353   gen_op_tmpl $compare_masked_template "$@"
354 }
355 
356 function gen_compare_bcst_op {
357   echo "Generating compare broadcast op $1 ($2)..."
358   gen_op_tmpl $compare_broadcast_template "$@"
359 }
360 
361 function gen_reduction_op {
362   echo "Generating reduction op $1 ($2)..."
363   gen_op_tmpl $reduction_scalar "$@"
364   gen_op_tmpl $reduction_op "$@"
365   gen_op_tmpl $reduction_scalar_masked "$@"
366   gen_op_tmpl $reduction_op_masked "$@"
367 }
368 
369 function gen_reduction_op_func {
370   echo "Generating reduction op $1 ($2)..."
371   gen_op_tmpl $reduction_scalar_func "$@"
372   gen_op_tmpl $reduction_op_func "$@"
373   gen_op_tmpl $reduction_scalar_masked_func "$@"
374   gen_op_tmpl $reduction_op_masked_func "$@"
375 }
376 
377 function gen_bool_reduction_op {
378   echo "Generating boolean reduction op $1 ($2)..."
379   gen_op_tmpl $bool_reduction_scalar "$@"
380   gen_op_tmpl $bool_reduction_template "$@"
381 }
382 function gen_saturating_reduction_op {
383   echo "Generating saturating reduction op $1 ($2)..."
384   gen_op_tmpl $reduction_scalar_func "$@"
385   gen_op_tmpl $reduction_saturating_op "$@"
386   gen_op_tmpl $reduction_scalar_masked_func "$@"
387   gen_op_tmpl $reduction_saturating_op_masked "$@"
388 }
389 
390 function gen_with_op {
391   echo "Generating with op $1 ($2)..."
392   gen_op_tmpl $with_op_template "$@"
393 }
394 
395 function gen_get_op {
396   echo "Generating get op $1 ($2)..."
397   gen_op_tmpl $get_template "$@"
398 }
399 
400 function gen_unit_header {
401   cat $TEMPLATE_FOLDER/Unit-header.template > $1
402 }
403 
404 function gen_unit_footer {
405   cat $TEMPLATE_FOLDER/Unit-footer.template >> $1
406 }
407 
408 function gen_perf_header {
409   cat $TEMPLATE_FOLDER/Perf-header.template > $1
410 }
411 
412 function gen_perf_footer {
413   cat $TEMPLATE_FOLDER/Perf-footer.template >> $1
414 }
415 
416 function gen_perf_scalar_header {
417   cat $TEMPLATE_FOLDER/Perf-Scalar-header.template > $1
418 }
419 
420 function gen_perf_scalar_footer {
421   cat $TEMPLATE_FOLDER/Perf-Scalar-footer.template >> $1
422 }
423 
424 gen_unit_header $unit_output
425 
426 if [ $generate_perf_tests == true ]; then
427   gen_perf_header $perf_output
428   gen_perf_scalar_header $perf_scalar_output
429 fi
430 
431 # ALU binary ops.
432 # Here "ADD+add+withMask" says VectorOperator name is "ADD", and we have a dedicate method too named 'add', and add() is also available with mask variant.
433 gen_binary_alu_op "ADD+add+withMask" "a + b"
434 gen_binary_alu_op "SUB+sub+withMask" "a - b"
435 gen_binary_alu_op "MUL+mul+withMask" "a \* b"
436 gen_binary_alu_op "DIV+div+withMask" "a \/ b" "FP"
437 gen_op_tmpl "Binary-op_bitwise-div" "DIV+div+withMask" "a \/ b" "BITWISE"
438 gen_op_tmpl "Binary-Masked-op_bitwise-div" "DIV+div+withMask" "a \/ b" "BITWISE"
439 gen_binary_alu_op "FIRST_NONZERO" "{#if[FP]?Double.doubleToLongBits}(a)!=0?a:b"
440 gen_binary_alu_op "AND+and"   "a \& b"  "BITWISE"
441 gen_binary_alu_op "AND_NOT" "a \& ~b" "BITWISE"
442 gen_binary_alu_op "OR+or"    "a | b"   "BITWISE"
443 # Missing:        "OR_UNCHECKED"
444 gen_binary_alu_op "XOR"   "a ^ b"   "BITWISE"
445 gen_binary_alu_op "COMPRESS_BITS" "\$Boxtype\$.compress(a, b)" "intOrLong"
446 gen_binary_alu_op "EXPAND_BITS" "\$Boxtype\$.expand(a, b)" "intOrLong"
447 # Generate the broadcast versions
448 gen_binary_alu_bcst_op "add+withMask" "a + b"
449 gen_binary_alu_bcst_op "sub+withMask" "a - b"
450 gen_binary_alu_bcst_op "mul+withMask" "a \* b"
451 gen_binary_alu_bcst_op "div+withMask" "a \/ b" "FP"
452 gen_op_tmpl "Binary-Broadcast-op_bitwise-div" "div+withMask" "a \/ b" "BITWISE"
453 gen_op_tmpl "Binary-Broadcast-Masked-op_bitwise-div" "div+withMask" "a \/ b" "BITWISE"
454 gen_binary_alu_bcst_op "OR+or"    "a | b"   "BITWISE"
455 gen_binary_alu_bcst_op "AND+and"    "a \& b"   "BITWISE"
456 gen_binary_alu_bcst_long_op "OR"     "a | b"   "BITWISE"
457 gen_binary_alu_bcst_long_op "ADD"    "a + b"
458 
459 # Shifts
460 gen_binary_alu_op "LSHL" "(a << b)" "intOrLong"
461 gen_binary_alu_op "LSHL" "(a << (b \& 0x7))" "byte"
462 gen_binary_alu_op "LSHL" "(a << (b \& 0xF))" "short"
463 gen_binary_alu_op "ASHR" "(a >> b)" "intOrLong"
464 gen_binary_alu_op "ASHR" "(a >> (b \& 0x7))" "byte"
465 gen_binary_alu_op "ASHR" "(a >> (b \& 0xF))" "short"
466 gen_binary_alu_op "LSHR" "(a >>> b)" "intOrLong"
467 gen_binary_alu_op "LSHR" "((a \& 0xFF) >>> (b \& 0x7))" "byte"
468 gen_binary_alu_op "LSHR" "((a \& 0xFFFF) >>> (b \& 0xF))" "short"
469 gen_shift_op  "LSHL" "(a << b)" "intOrLong"
470 gen_shift_op  "LSHL" "(a << (b \& 7))" "byte"
471 gen_shift_op  "LSHL" "(a << (b \& 15))" "short"
472 gen_shift_op  "LSHR" "(a >>> b)" "intOrLong"
473 gen_shift_op  "LSHR" "((a \& 0xFF) >>> (b \& 7))" "byte"
474 gen_shift_op  "LSHR" "((a \& 0xFFFF) >>> (b \& 15))" "short"
475 gen_shift_op  "ASHR" "(a >> b)" "intOrLong"
476 gen_shift_op  "ASHR" "(a >> (b \& 7))" "byte"
477 gen_shift_op  "ASHR" "(a >> (b \& 15))" "short"
478 gen_binary_alu_op "ROR" "ROR_scalar(a,b)" "BITWISE"
479 gen_binary_alu_op "ROL" "ROL_scalar(a,b)" "BITWISE"
480 gen_shift_op  "ROR" "ROR_scalar(a, b)" "BITWISE"
481 gen_shift_op  "ROL" "ROL_scalar(a, b)" "BITWISE"
482 
483 # Constant Shifts
484 gen_shift_cst_op  "LSHR" "(a >>> CONST_SHIFT)" "intOrLong"
485 gen_shift_cst_op  "LSHR" "((a \& 0xFF) >>> CONST_SHIFT)" "byte"
486 gen_shift_cst_op  "LSHR" "((a \& 0xFFFF) >>> CONST_SHIFT)" "short"
487 gen_shift_cst_op  "LSHL" "(a << CONST_SHIFT)" "BITWISE"
488 gen_shift_cst_op  "ASHR" "(a >> CONST_SHIFT)" "BITWISE"
489 gen_shift_cst_op  "ROR" "ROR_scalar(a, CONST_SHIFT)" "BITWISE"
490 gen_shift_cst_op  "ROL" "ROL_scalar(a, CONST_SHIFT)" "BITWISE"
491 
492 # Binary operation with one memory operand
493 gen_binary_alu_mem_op "MIN+min+withMask", "Math.min(a, b)"
494 gen_binary_alu_mem_op "MAX+max+withMask", "Math.max(a, b)"
495 
496 # Masked reductions.
497 gen_binary_op_no_masked "MIN+min" "Math.min(a, b)"
498 gen_binary_op_no_masked "MAX+max" "Math.max(a, b)"
499 gen_binary_op "UMIN" "VectorMath.minUnsigned(a, b)" "BITWISE"
500 gen_binary_op "UMAX" "VectorMath.maxUnsigned(a, b)" "BITWISE"
501 gen_saturating_binary_op "SADD" "VectorMath.addSaturating(a, b)" "BITWISE"
502 gen_saturating_binary_op "SSUB" "VectorMath.subSaturating(a, b)" "BITWISE"
503 gen_saturating_binary_op "SUADD" "VectorMath.addSaturatingUnsigned(a, b)" "BITWISE"
504 gen_saturating_binary_op "SUSUB" "VectorMath.subSaturatingUnsigned(a, b)" "BITWISE"
505 gen_binary_bcst_op_no_masked "MIN+min" "Math.min(a, b)"
506 gen_binary_bcst_op_no_masked "MAX+max" "Math.max(a, b)"
507 gen_saturating_binary_op_associative "SUADD" "VectorMath.addSaturatingUnsigned(a, b)" "BITWISE"
508 
509 # Reductions.
510 gen_reduction_op "AND" "\&" "BITWISE" "-1"
511 gen_reduction_op "OR" "|" "BITWISE" "0"
512 gen_reduction_op "XOR" "^" "BITWISE" "0"
513 gen_reduction_op "ADD" "+" "" "0"
514 gen_reduction_op "MUL" "*" "" "1"
515 gen_reduction_op_func "MIN" "(\$type\$) Math.min" "" "\$Wideboxtype\$.\$MaxValue\$"
516 gen_reduction_op_func "MAX" "(\$type\$) Math.max" "" "\$Wideboxtype\$.\$MinValue\$"
517 gen_reduction_op_func "UMIN" "(\$type\$) VectorMath.minUnsigned" "BITWISE" "\$Wideboxtype\$.\$MaxValue\$"
518 gen_reduction_op_func "UMAX" "(\$type\$) VectorMath.maxUnsigned" "BITWISE" "\$Wideboxtype\$.\$MinValue\$"
519 gen_reduction_op_func "FIRST_NONZERO" "firstNonZero" "" "(\$type\$) 0"
520 
521 # Boolean reductions.
522 gen_bool_reduction_op "anyTrue" "|" "BITWISE" "false"
523 gen_bool_reduction_op "allTrue" "\&" "BITWISE" "true"
524 
525 # Saturating reductions.
526 gen_saturating_reduction_op "SUADD" "(\$type\$) VectorMath.addSaturatingUnsigned" "BITWISE" "0"
527 
528 #Insert
529 gen_with_op "withLane" "" "" ""
530 
531 # Tests
532 gen_op_tmpl $test_template "IS_DEFAULT" "bits(a)==0"
533 gen_op_tmpl $test_template "IS_NEGATIVE" "bits(a)<0"
534 gen_op_tmpl $test_template "IS_FINITE" "\$Boxtype\$.isFinite(a)" "FP"
535 gen_op_tmpl $test_template "IS_NAN" "\$Boxtype\$.isNaN(a)" "FP"
536 gen_op_tmpl $test_template "IS_INFINITE" "\$Boxtype\$.isInfinite(a)" "FP"
537 
538 # Compares
539 gen_compare_op "LT+lt" "lt"
540 gen_compare_op "GT" "gt"
541 gen_compare_op "EQ+eq" "eq"
542 gen_compare_op "NE" "neq"
543 gen_compare_op "LE" "le"
544 gen_compare_op "GE" "ge"
545 
546 gen_compare_op "ULT" "ult" "BITWISE"
547 gen_compare_op "UGT" "ugt" "BITWISE"
548 gen_compare_op "ULE" "ule" "BITWISE"
549 gen_compare_op "UGE" "uge" "BITWISE"
550 
551 
552 gen_compare_bcst_op "LT" "<"
553 gen_compare_bcst_op "EQ" "=="
554 
555 # Blend.
556 gen_op_tmpl $blend "blend" ""
557 
558 # Rearrange
559 gen_op_tmpl $rearrange_template "rearrange" ""
560 
561 # Compress/Expand
562 gen_op_tmpl $compressexpand_template "compress_expand" ""
563 
564 # Get
565 gen_get_op "lane" ""
566 
567 # Broadcast
568 gen_op_tmpl $broadcast_template "broadcast" ""
569 
570 # Zero
571 gen_op_tmpl $zero_template "zero" ""
572 
573 # Slice
574 gen_op_tmpl $slice_template "sliceUnary" ""
575 gen_op_tmpl $slice1_template "sliceBinary" ""
576 gen_op_tmpl $slice1_masked_template "slice" ""
577 
578 # Unslice
579 gen_op_tmpl $unslice_template "unsliceUnary" ""
580 gen_op_tmpl $unslice1_template "unsliceBinary" ""
581 gen_op_tmpl $unslice1_masked_template "unslice" ""
582 
583 # Math
584 gen_op_tmpl $unary_math_template "SIN" "Math.sin((double)a)" "FP"
585 gen_op_tmpl $unary_math_template "EXP" "Math.exp((double)a)" "FP"
586 gen_op_tmpl $unary_math_template "LOG1P" "Math.log1p((double)a)" "FP"
587 gen_op_tmpl $unary_math_template "LOG" "Math.log((double)a)" "FP"
588 gen_op_tmpl $unary_math_template "LOG10" "Math.log10((double)a)" "FP"
589 gen_op_tmpl $unary_math_template "EXPM1" "Math.expm1((double)a)" "FP"
590 gen_op_tmpl $unary_math_template "COS" "Math.cos((double)a)" "FP"
591 gen_op_tmpl $unary_math_template "TAN" "Math.tan((double)a)" "FP"
592 gen_op_tmpl $unary_math_template "SINH" "Math.sinh((double)a)" "FP"
593 gen_op_tmpl $unary_math_template "COSH" "Math.cosh((double)a)" "FP"
594 gen_op_tmpl $unary_math_template "TANH" "Math.tanh((double)a)" "FP"
595 gen_op_tmpl $unary_math_template "ASIN" "Math.asin((double)a)" "FP"
596 gen_op_tmpl $unary_math_template "ACOS" "Math.acos((double)a)" "FP"
597 gen_op_tmpl $unary_math_template "ATAN" "Math.atan((double)a)" "FP"
598 gen_op_tmpl $unary_math_template "CBRT" "Math.cbrt((double)a)" "FP"
599 gen_op_tmpl $binary_math_template "HYPOT" "Math.hypot((double)a, (double)b)" "FP"
600 gen_op_tmpl $binary_math_template "POW+pow" "Math.pow((double)a, (double)b)" "FP"
601 gen_op_tmpl $binary_math_template "ATAN2" "Math.atan2((double)a, (double)b)" "FP"
602 gen_op_tmpl $binary_math_broadcast_template "POW+pow" "Math.pow((double)a, (double)b)" "FP"
603 
604 # Ternary operations.
605 gen_ternary_alu_op "FMA+fma" "Math.fma(a, b, c)" "FP"
606 gen_ternary_alu_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE"
607 gen_ternary_alu_bcst_op "FMA" "Math.fma(a, b, c)" "FP"
608 gen_ternary_alu_bcst_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE"
609 gen_ternary_alu_double_bcst_op "FMA+fma" "Math.fma(a, b, c)" "FP"
610 gen_ternary_alu_double_bcst_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE"
611 
612 # Unary operations.
613 gen_unary_alu_op "NEG+neg" "-((\$type\$)a)"
614 gen_unary_alu_op "ABS+abs" "Math.abs((\$type\$)a)"
615 gen_unary_alu_op "NOT+not" "~((\$type\$)a)" "BITWISE"
616 gen_unary_alu_op "ZOMO" "(a==0?0:-1)" "BITWISE"
617 gen_unary_alu_op "SQRT+sqrt" "Math.sqrt((double)a)" "FP"
618 gen_unary_alu_op "BIT_COUNT" "\$Boxtype\$.bitCount(a)" "intOrLong"
619 gen_unary_alu_op "BIT_COUNT" "Integer.bitCount((int)a \& 0xFF)" "byte"
620 gen_unary_alu_op "BIT_COUNT" "Integer.bitCount((int)a \& 0xFFFF)" "short"
621 gen_unary_alu_op "TRAILING_ZEROS_COUNT" "TRAILING_ZEROS_COUNT_scalar(a)" "BITWISE"
622 gen_unary_alu_op "LEADING_ZEROS_COUNT" "LEADING_ZEROS_COUNT_scalar(a)" "BITWISE"
623 gen_unary_alu_op "REVERSE" "REVERSE_scalar(a)" "BITWISE"
624 gen_unary_alu_op "REVERSE_BYTES" "\$Boxtype\$.reverseBytes(a)" "intOrLong"
625 gen_unary_alu_op "REVERSE_BYTES" "\$Boxtype\$.reverseBytes(a)" "short"
626 gen_unary_alu_op "REVERSE_BYTES" "a" "byte"
627 
628 # Miscellaneous Smoke Tests
629 gen_op_tmpl $miscellaneous_template "MISC" "" ""
630 
631 gen_unit_footer $unit_output
632 
633 if [ $generate_perf_tests == true ]; then
634   gen_perf_footer $perf_output
635   gen_perf_scalar_footer $perf_scalar_output
636 fi
637 
638 rm -f templates/*.current*