I am trying to adapt this java code in order to be compatible with SIMD instructions.
int[] arr1 = {50002, 51000, 52040, 53078, 54065, 55004, 56077, 57073, 58020, 59000, 60095, 61046, 62051, 63018, 64480, 65460};
int[] arr2 = {50, 57, 60, 63, 66, 70, 73, 74, 80, 81, 87, 88, 90, 92, 96, 103};
int[] result = new int[16];
for (int i = 0; i < 16; i++) {
double a = arr1[i] / (double) arr2[i];
int b = (int) ((Math.round(a * a) - 1) % 25) + 1; // I need help to adapt this line of code.
result[i] = b;
}
I am trying to write a new java code adapted to SIMD instructions:
int[] arr1 = {50002, 51000, 52040, 53078, 54065, 55004, 56077, 57073, 58020, 59000, 60095, 61046, 62051, 63018, 64480, 65460};
int[] arr2 = {50, 57, 60, 63, 66, 70, 73, 74, 80, 81, 87, 88, 90, 92, 96, 103};
int[] result = new int[16];
var species = IntVector.SPECIES_PREFERRED;
var Vec1 = IntVector.fromArray(species, arr1, 0);
var Vec2 = IntVector.fromArray(species, arr2, 0);
var RESULT = Vec1.mul(Vec1).div(Vec2.mul(Vec2); // I need help to write the lines highlighted in the previous code.
RESULT.intoArray(result, 0);
I simply cannot find a way to adapt the formula.
Edit 1: As my knowledge is limited (beginner), I notice now that it is more complex than I thought. So, let me explain better what the function does: In fact, arr1 has 50 million prime numbers (from 2 to 982451653) and arr2 has 5000 numbers (from 1 to 5000). There are 2 loops, the first loop (arr2) and the second loop (arr1). The real java code is:
int[] arr1 = {2, 3, 5, 7, ... , 982451609, 982451629, 982451653}; // 50 million prime numbers.
int[] arr2 = {1, 2, 3, 4, 5, ... , 4998, 4999, 5000};
for (int i = 0; i < 5000; i++) {
int[] result = new int[50000000];
for (int j = 0; j < 50000000; j++) {
double a = arr1[j] / (double) arr2[i];
int b = (int) ((Math.round(a * a) - 1) % 25) + 1; // I need help to adapt this line of code.
result[j] = b;
}
// do something with result[] before discarding it
}
For example: arr1[1034158] is 16050707 and arr2[452] is 453
sqr(arr1/arr2) is equal to 1255428344.7599
The result of the formula should be 20 (round 1255428344.7599 -> 1255428345. Then, 1255428345 minus 1255428325 is 20.