public class Test2b {
    static final int ARRLEN = 1024;
    static final int ITERS  = 11000;

    public static void main(String args[]) {
        float[] finp = new float[ARRLEN];
        short[] sout = new short[ARRLEN];
        short[] sgold = new short[ARRLEN];

        for (int i = 0; i < ARRLEN; i++) {
            finp[i] = (float)1;
        }

        fill(sgold);
        test(sgold, finp);

        for (int i = 0; i < ITERS; i++) {
            fill(sout);
            test(sout, finp);
        }

        long err = 0;
        for (int i = 0; i < ARRLEN; i++) {
            if (sgold[i] != sout[i]) {
                err++;
                System.out.println("wrong: i=" + i + " sgold_i=" + sgold[i] + " sout_i=" + sout[i]);
            }
        }
        if (err > 0) {
            throw new RuntimeException("errors: " + err);
        }
    }

    public static void fill(short[] s) {
        for (int i = 0; i < ARRLEN; i++) {
            s[i] = (short)i;
        }
    }

    public static void test(short[] sout, float[] finp) {
        for (int i = 0; i < finp.length; i+=4) {
            sout[i+0] = Float.floatToFloat16(finp[i+0]); // 2-element vector
            sout[i+1] = Float.floatToFloat16(finp[i+1]);
            // gap of 2 elements
        }
    }
}
