Path: blob/master/test/hotspot/jtreg/compiler/codegen/TestByteFloatVect.java
41149 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 711964426* @summary Increase superword's vector size up to 256 bits27*28* @run main/othervm/timeout=300 -Xbatch -XX:+IgnoreUnrecognizedVMOptions29* -XX:-TieredCompilation -XX:-OptimizeFill30* compiler.codegen.TestByteFloatVect31*/3233package compiler.codegen;3435public class TestByteFloatVect {36private static final int ARRLEN = 997;37private static final int ITERS = 11000;38private static final int OFFSET = 3;39private static final int SCALE = 2;40private static final int ALIGN_OFF = 8;41private static final int UNALIGN_OFF = 5;4243public static void main(String args[]) {44System.out.println("Testing Byte + Float vectors");45int errn = test();46if (errn > 0) {47System.err.println("FAILED: " + errn + " errors");48System.exit(97);49}50System.out.println("PASSED");51}5253static int test() {54byte[] a1 = new byte[ARRLEN];55byte[] a2 = new byte[ARRLEN];56float[] b1 = new float[ARRLEN];57float[] b2 = new float[ARRLEN];58System.out.println("Warmup");59for (int i=0; i<ITERS; i++) {60test_ci(a1, b1);61test_vi(a2, b2, (byte)123, 103.f);62test_cp(a1, a2, b1, b2);63test_ci_neg(a1, b1);64test_vi_neg(a1, b1, (byte)123, 103.f);65test_cp_neg(a1, a2, b1, b2);66test_ci_oppos(a1, b1);67test_vi_oppos(a1, b1, (byte)123, 103.f);68test_cp_oppos(a1, a2, b1, b2);69test_ci_aln(a1, b1);70test_vi_aln(a1, b1, (byte)123, 103.f);71test_cp_alndst(a1, a2, b1, b2);72test_cp_alnsrc(a1, a2, b1, b2);73test_ci_unaln(a1, b1);74test_vi_unaln(a1, b1, (byte)123, 103.f);75test_cp_unalndst(a1, a2, b1, b2);76test_cp_unalnsrc(a1, a2, b1, b2);77}78// Initialize79for (int i=0; i<ARRLEN; i++) {80a1[i] = -1;81a2[i] = -1;82b1[i] = -1.f;83b2[i] = -1.f;84}85// Test and verify results86System.out.println("Verification");87int errn = 0;88{89test_ci(a1, b1);90for (int i=0; i<ARRLEN; i++) {91errn += verify("test_ci: a1", i, a1[i], (byte)-123);92errn += verify("test_ci: b1", i, b1[i], -103.f);93}94test_vi(a2, b2, (byte)123, 103.f);95for (int i=0; i<ARRLEN; i++) {96errn += verify("test_vi: a2", i, a2[i], (byte)123);97errn += verify("test_vi: b2", i, b2[i], 103.f);98}99test_cp(a1, a2, b1, b2);100for (int i=0; i<ARRLEN; i++) {101errn += verify("test_cp: a1", i, a1[i], (byte)123);102errn += verify("test_cp: b1", i, b1[i], 103.f);103}104105// Reset for negative stride106for (int i=0; i<ARRLEN; i++) {107a1[i] = -1;108a2[i] = -1;109b1[i] = -1.f;110b2[i] = -1.f;111}112test_ci_neg(a1, b1);113for (int i=0; i<ARRLEN; i++) {114errn += verify("test_ci_neg: a1", i, a1[i], (byte)-123);115errn += verify("test_ci_neg: b1", i, b1[i], -103.f);116}117test_vi_neg(a2, b2, (byte)123, 103.f);118for (int i=0; i<ARRLEN; i++) {119errn += verify("test_vi_neg: a2", i, a2[i], (byte)123);120errn += verify("test_vi_neg: b2", i, b2[i], 103.f);121}122test_cp_neg(a1, a2, b1, b2);123for (int i=0; i<ARRLEN; i++) {124errn += verify("test_cp_neg: a1", i, a1[i], (byte)123);125errn += verify("test_cp_neg: b1", i, b1[i], 103.f);126}127128// Reset for opposite stride129for (int i=0; i<ARRLEN; i++) {130a1[i] = -1;131a2[i] = -1;132b1[i] = -1.f;133b2[i] = -1.f;134}135test_ci_oppos(a1, b1);136for (int i=0; i<ARRLEN; i++) {137errn += verify("test_ci_oppos: a1", i, a1[i], (byte)-123);138errn += verify("test_ci_oppos: b1", i, b1[i], -103.f);139}140test_vi_oppos(a2, b2, (byte)123, 103.f);141for (int i=0; i<ARRLEN; i++) {142errn += verify("test_vi_oppos: a2", i, a2[i], (byte)123);143errn += verify("test_vi_oppos: b2", i, b2[i], 103.f);144}145test_cp_oppos(a1, a2, b1, b2);146for (int i=0; i<ARRLEN; i++) {147errn += verify("test_cp_oppos: a1", i, a1[i], (byte)123);148errn += verify("test_cp_oppos: b1", i, b1[i], 103.f);149}150151// Reset for 2 arrays with relative aligned offset152for (int i=0; i<ARRLEN; i++) {153a1[i] = -1;154a2[i] = 123;155b1[i] = -1.f;156b2[i] = 123.f;157}158test_cp_alndst(a1, a2, b1, b2);159for (int i=0; i<ALIGN_OFF; i++) {160errn += verify("test_cp_alndst: a1", i, a1[i], (byte)-1);161errn += verify("test_cp_alndst: b1", i, b1[i], -1.f);162}163for (int i=ALIGN_OFF; i<ARRLEN; i++) {164errn += verify("test_cp_alndst: a1", i, a1[i], (byte)123);165errn += verify("test_cp_alndst: b1", i, b1[i], 123.f);166}167for (int i=0; i<ARRLEN; i++) {168a2[i] = -123;169b2[i] = -123.f;170}171test_cp_alnsrc(a1, a2, b1, b2);172for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {173errn += verify("test_cp_alnsrc: a1", i, a1[i], (byte)-123);174errn += verify("test_cp_alnsrc: b1", i, b1[i], -123.f);175}176for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {177errn += verify("test_cp_alnsrc: a1", i, a1[i], (byte)123);178errn += verify("test_cp_alnsrc: b1", i, b1[i], 123.f);179}180181for (int i=0; i<ARRLEN; i++) {182a1[i] = -1;183b1[i] = -1.f;184}185test_ci_aln(a1, b1);186for (int i=0; i<ALIGN_OFF; i++) {187errn += verify("test_ci_aln: a1", i, a1[i], (byte)-1);188}189for (int i=ALIGN_OFF; i<ARRLEN; i++) {190errn += verify("test_ci_aln: a1", i, a1[i], (byte)-123);191}192for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {193errn += verify("test_ci_aln: b1", i, b1[i], -103.f);194}195for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {196errn += verify("test_ci_aln: b1", i, b1[i], -1.f);197}198199for (int i=0; i<ARRLEN; i++) {200a1[i] = -1;201b1[i] = -1.f;202}203test_vi_aln(a1, b1, (byte)123, 103.f);204for (int i=0; i<ARRLEN-ALIGN_OFF; i++) {205errn += verify("test_vi_aln: a1", i, a1[i], (byte)123);206}207for (int i=ARRLEN-ALIGN_OFF; i<ARRLEN; i++) {208errn += verify("test_vi_aln: a1", i, a1[i], (byte)-1);209}210for (int i=0; i<ALIGN_OFF; i++) {211errn += verify("test_vi_aln: b1", i, b1[i], -1.f);212}213for (int i=ALIGN_OFF; i<ARRLEN; i++) {214errn += verify("test_vi_aln: b1", i, b1[i], 103.f);215}216217// Reset for 2 arrays with relative unaligned offset218for (int i=0; i<ARRLEN; i++) {219a1[i] = -1;220a2[i] = 123;221b1[i] = -1.f;222b2[i] = 123.f;223}224test_cp_unalndst(a1, a2, b1, b2);225for (int i=0; i<UNALIGN_OFF; i++) {226errn += verify("test_cp_unalndst: a1", i, a1[i], (byte)-1);227errn += verify("test_cp_unalndst: b1", i, b1[i], -1.f);228}229for (int i=UNALIGN_OFF; i<ARRLEN; i++) {230errn += verify("test_cp_unalndst: a1", i, a1[i], (byte)123);231errn += verify("test_cp_unalndst: b1", i, b1[i], 123.f);232}233for (int i=0; i<ARRLEN; i++) {234a2[i] = -123;235b2[i] = -123.f;236}237test_cp_unalnsrc(a1, a2, b1, b2);238for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {239errn += verify("test_cp_unalnsrc: a1", i, a1[i], (byte)-123);240errn += verify("test_cp_unalnsrc: b1", i, b1[i], -123.f);241}242for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {243errn += verify("test_cp_unalnsrc: a1", i, a1[i], (byte)123);244errn += verify("test_cp_unalnsrc: b1", i, b1[i], 123.f);245}246for (int i=0; i<ARRLEN; i++) {247a1[i] = -1;248b1[i] = -1;249}250test_ci_unaln(a1, b1);251for (int i=0; i<UNALIGN_OFF; i++) {252errn += verify("test_ci_unaln: a1", i, a1[i], (byte)-1);253}254for (int i=UNALIGN_OFF; i<ARRLEN; i++) {255errn += verify("test_ci_unaln: a1", i, a1[i], (byte)-123);256}257for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {258errn += verify("test_ci_unaln: b1", i, b1[i], -103.f);259}260for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {261errn += verify("test_ci_unaln: b1", i, b1[i], -1.f);262}263for (int i=0; i<ARRLEN; i++) {264a1[i] = -1;265b1[i] = -1;266}267test_vi_unaln(a1, b1, (byte)123, 103.f);268for (int i=0; i<ARRLEN-UNALIGN_OFF; i++) {269errn += verify("test_vi_unaln: a1", i, a1[i], (byte)123);270}271for (int i=ARRLEN-UNALIGN_OFF; i<ARRLEN; i++) {272errn += verify("test_vi_unaln: a1", i, a1[i], (byte)-1);273}274for (int i=0; i<UNALIGN_OFF; i++) {275errn += verify("test_vi_unaln: b1", i, b1[i], -1.f);276}277for (int i=UNALIGN_OFF; i<ARRLEN; i++) {278errn += verify("test_vi_unaln: b1", i, b1[i], 103.f);279}280281// Reset for aligned overlap initialization282for (int i=0; i<ALIGN_OFF; i++) {283a1[i] = (byte)i;284b1[i] = (float)i;285}286for (int i=ALIGN_OFF; i<ARRLEN; i++) {287a1[i] = -1;288b1[i] = -1.f;289}290test_cp_alndst(a1, a1, b1, b1);291for (int i=0; i<ARRLEN; i++) {292int v = i%ALIGN_OFF;293errn += verify("test_cp_alndst_overlap: a1", i, a1[i], (byte)v);294errn += verify("test_cp_alndst_overlap: b1", i, b1[i], (float)v);295}296for (int i=0; i<ALIGN_OFF; i++) {297a1[i+ALIGN_OFF] = -1;298b1[i+ALIGN_OFF] = -1.f;299}300test_cp_alnsrc(a1, a1, b1, b1);301for (int i=0; i<ALIGN_OFF; i++) {302errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], (byte)-1);303errn += verify("test_cp_alnsrc_overlap: b1", i, b1[i], -1.f);304}305for (int i=ALIGN_OFF; i<ARRLEN; i++) {306int v = i%ALIGN_OFF;307errn += verify("test_cp_alnsrc_overlap: a1", i, a1[i], (byte)v);308errn += verify("test_cp_alnsrc_overlap: b1", i, b1[i], (float)v);309}310311// Reset for unaligned overlap initialization312for (int i=0; i<UNALIGN_OFF; i++) {313a1[i] = (byte)i;314b1[i] = (float)i;315}316for (int i=UNALIGN_OFF; i<ARRLEN; i++) {317a1[i] = -1;318b1[i] = -1.f;319}320test_cp_unalndst(a1, a1, b1, b1);321for (int i=0; i<ARRLEN; i++) {322int v = i%UNALIGN_OFF;323errn += verify("test_cp_unalndst_overlap: a1", i, a1[i], (byte)v);324errn += verify("test_cp_unalndst_overlap: b1", i, b1[i], (float)v);325}326for (int i=0; i<UNALIGN_OFF; i++) {327a1[i+UNALIGN_OFF] = -1;328b1[i+UNALIGN_OFF] = -1.f;329}330test_cp_unalnsrc(a1, a1, b1, b1);331for (int i=0; i<UNALIGN_OFF; i++) {332errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], (byte)-1);333errn += verify("test_cp_unalnsrc_overlap: b1", i, b1[i], -1.f);334}335for (int i=UNALIGN_OFF; i<ARRLEN; i++) {336int v = i%UNALIGN_OFF;337errn += verify("test_cp_unalnsrc_overlap: a1", i, a1[i], (byte)v);338errn += verify("test_cp_unalnsrc_overlap: b1", i, b1[i], (float)v);339}340341}342343if (errn > 0)344return errn;345346System.out.println("Time");347long start, end;348start = System.currentTimeMillis();349for (int i=0; i<ITERS; i++) {350test_ci(a1, b1);351}352end = System.currentTimeMillis();353System.out.println("test_ci: " + (end - start));354start = System.currentTimeMillis();355for (int i=0; i<ITERS; i++) {356test_vi(a2, b2, (byte)123, 103.f);357}358end = System.currentTimeMillis();359System.out.println("test_vi: " + (end - start));360start = System.currentTimeMillis();361for (int i=0; i<ITERS; i++) {362test_cp(a1, a2, b1, b2);363}364end = System.currentTimeMillis();365System.out.println("test_cp: " + (end - start));366start = System.currentTimeMillis();367for (int i=0; i<ITERS; i++) {368test_ci_neg(a1, b1);369}370end = System.currentTimeMillis();371System.out.println("test_ci_neg: " + (end - start));372start = System.currentTimeMillis();373for (int i=0; i<ITERS; i++) {374test_vi_neg(a1, b1, (byte)123, 103.f);375}376end = System.currentTimeMillis();377System.out.println("test_vi_neg: " + (end - start));378start = System.currentTimeMillis();379for (int i=0; i<ITERS; i++) {380test_cp_neg(a1, a2, b1, b2);381}382end = System.currentTimeMillis();383System.out.println("test_cp_neg: " + (end - start));384start = System.currentTimeMillis();385for (int i=0; i<ITERS; i++) {386test_ci_oppos(a1, b1);387}388end = System.currentTimeMillis();389System.out.println("test_ci_oppos: " + (end - start));390start = System.currentTimeMillis();391for (int i=0; i<ITERS; i++) {392test_vi_oppos(a1, b1, (byte)123, 103.f);393}394end = System.currentTimeMillis();395System.out.println("test_vi_oppos: " + (end - start));396start = System.currentTimeMillis();397for (int i=0; i<ITERS; i++) {398test_cp_oppos(a1, a2, b1, b2);399}400end = System.currentTimeMillis();401System.out.println("test_cp_oppos: " + (end - start));402start = System.currentTimeMillis();403for (int i=0; i<ITERS; i++) {404test_ci_aln(a1, b1);405}406end = System.currentTimeMillis();407System.out.println("test_ci_aln: " + (end - start));408start = System.currentTimeMillis();409for (int i=0; i<ITERS; i++) {410test_vi_aln(a1, b1, (byte)123, 103.f);411}412end = System.currentTimeMillis();413System.out.println("test_vi_aln: " + (end - start));414start = System.currentTimeMillis();415for (int i=0; i<ITERS; i++) {416test_cp_alndst(a1, a2, b1, b2);417}418end = System.currentTimeMillis();419System.out.println("test_cp_alndst: " + (end - start));420start = System.currentTimeMillis();421for (int i=0; i<ITERS; i++) {422test_cp_alnsrc(a1, a2, b1, b2);423}424end = System.currentTimeMillis();425System.out.println("test_cp_alnsrc: " + (end - start));426start = System.currentTimeMillis();427for (int i=0; i<ITERS; i++) {428test_ci_unaln(a1, b1);429}430end = System.currentTimeMillis();431System.out.println("test_ci_unaln: " + (end - start));432start = System.currentTimeMillis();433for (int i=0; i<ITERS; i++) {434test_vi_unaln(a1, b1, (byte)123, 103.f);435}436end = System.currentTimeMillis();437System.out.println("test_vi_unaln: " + (end - start));438start = System.currentTimeMillis();439for (int i=0; i<ITERS; i++) {440test_cp_unalndst(a1, a2, b1, b2);441}442end = System.currentTimeMillis();443System.out.println("test_cp_unalndst: " + (end - start));444start = System.currentTimeMillis();445for (int i=0; i<ITERS; i++) {446test_cp_unalnsrc(a1, a2, b1, b2);447}448end = System.currentTimeMillis();449System.out.println("test_cp_unalnsrc: " + (end - start));450return errn;451}452453static void test_ci(byte[] a, float[] b) {454for (int i = 0; i < a.length; i+=1) {455a[i] = -123;456b[i] = -103.f;457}458}459static void test_vi(byte[] a, float[] b, byte c, float d) {460for (int i = 0; i < a.length; i+=1) {461a[i] = c;462b[i] = d;463}464}465static void test_cp(byte[] a, byte[] b, float[] c, float[] d) {466for (int i = 0; i < a.length; i+=1) {467a[i] = b[i];468c[i] = d[i];469}470}471static void test_ci_neg(byte[] a, float[] b) {472for (int i = a.length-1; i >= 0; i-=1) {473a[i] = -123;474b[i] = -103.f;475}476}477static void test_vi_neg(byte[] a, float[] b, byte c, float d) {478for (int i = a.length-1; i >= 0; i-=1) {479a[i] = c;480b[i] = d;481}482}483static void test_cp_neg(byte[] a, byte[] b, float[] c, float[] d) {484for (int i = a.length-1; i >= 0; i-=1) {485a[i] = b[i];486c[i] = d[i];487}488}489static void test_ci_oppos(byte[] a, float[] b) {490int limit = a.length-1;491for (int i = 0; i < a.length; i+=1) {492a[limit-i] = -123;493b[i] = -103.f;494}495}496static void test_vi_oppos(byte[] a, float[] b, byte c, float d) {497int limit = a.length-1;498for (int i = a.length-1; i >= 0; i-=1) {499a[i] = c;500b[limit-i] = d;501}502}503static void test_cp_oppos(byte[] a, byte[] b, float[] c, float[] d) {504int limit = a.length-1;505for (int i = 0; i < a.length; i+=1) {506a[i] = b[limit-i];507c[limit-i] = d[i];508}509}510static void test_ci_aln(byte[] a, float[] b) {511for (int i = 0; i < a.length-ALIGN_OFF; i+=1) {512a[i+ALIGN_OFF] = -123;513b[i] = -103.f;514}515}516static void test_vi_aln(byte[] a, float[] b, byte c, float d) {517for (int i = 0; i < a.length-ALIGN_OFF; i+=1) {518a[i] = c;519b[i+ALIGN_OFF] = d;520}521}522static void test_cp_alndst(byte[] a, byte[] b, float[] c, float[] d) {523for (int i = 0; i < a.length-ALIGN_OFF; i+=1) {524a[i+ALIGN_OFF] = b[i];525c[i+ALIGN_OFF] = d[i];526}527}528static void test_cp_alnsrc(byte[] a, byte[] b, float[] c, float[] d) {529for (int i = 0; i < a.length-ALIGN_OFF; i+=1) {530a[i] = b[i+ALIGN_OFF];531c[i] = d[i+ALIGN_OFF];532}533}534static void test_ci_unaln(byte[] a, float[] b) {535for (int i = 0; i < a.length-UNALIGN_OFF; i+=1) {536a[i+UNALIGN_OFF] = -123;537b[i] = -103.f;538}539}540static void test_vi_unaln(byte[] a, float[] b, byte c, float d) {541for (int i = 0; i < a.length-UNALIGN_OFF; i+=1) {542a[i] = c;543b[i+UNALIGN_OFF] = d;544}545}546static void test_cp_unalndst(byte[] a, byte[] b, float[] c, float[] d) {547for (int i = 0; i < a.length-UNALIGN_OFF; i+=1) {548a[i+UNALIGN_OFF] = b[i];549c[i+UNALIGN_OFF] = d[i];550}551}552static void test_cp_unalnsrc(byte[] a, byte[] b, float[] c, float[] d) {553for (int i = 0; i < a.length-UNALIGN_OFF; i+=1) {554a[i] = b[i+UNALIGN_OFF];555c[i] = d[i+UNALIGN_OFF];556}557}558559static int verify(String text, int i, byte elem, byte val) {560if (elem != val) {561System.err.println(text + "[" + i + "] = " + elem + " != " + val);562return 1;563}564return 0;565}566static int verify(String text, int i, float elem, float val) {567if (elem != val) {568System.err.println(text + "[" + i + "] = " + elem + " != " + val);569return 1;570}571return 0;572}573}574575576