Unpredictable results in calculations under Cortex-A53

127 Views Asked by At

The Java code below returns unpredictable results when ran on a Cortex-A53 and specifically on Xperia XA devices.

The first iterations print the correct values:

[24, 42, 61, 45, 29, 46, 35, 36, 48, 47, 20, 64, 45, 15, 37, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70]

and after some repetitions it prints:

[24, 61, 29, 35, 48, 20, 45, 37, 1886962617, 41137, 6952, 58489, 6151, 55208, 154, 57100, 20418, 57100, 20418, 57100, 20418, 57100, 20418, 57100, 20418, 57100, 20418, 57100, 20418, 57100, 20418]

If I use float or double or int instead of long, the results are still wrong but different:

[24.0, 61.0, 29.0, 35.0, 48.0, 20.0, 45.0, 37.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

On other devices it runs as expected. Is this a problem of JVM or caused by a CPU errata?

public static void runTest() {

    long[] t = new long[]{ 23,41, 60, 44, 28, 45, 34, 35, 47, 46, 19, 63, 44, 14, 36, 69};

    for(int i = 0; i < 40; i++) {
        long[] output = calculate(t);

        Log.e("TEST", Arrays.toString(output));
    }
}

private static long[] calculate(long[] input) {
    long[] result = new long[31];

    for (int i = 0; i < 16; i ++) {
        for (int j = 0; j < 16; j++) {
            result[i + j] = input[i] + 1;
        }
    }

    return result;
}

If I move the code from calculate inside the runTest's for-loop, it runs correctly. Also, if I read the input values inside calculate it works.

So, what is the cause of this issue and where should I leave my feedback to get this resolved?

0

There are 0 best solutions below