I need to optimize some code, where I multiply the vector ints (32 bits) by scalar modulo p (where p is a prime number (2 ^ 32) -5), and then subtract this vector from another vector modulo p,
The code is as follows:
public static void multiplyAndSubtract(long fragmentCoefficient, long[] equationToSubtractFrom, long[] equationToSubtract) { for (int i = 0; i < equationToSubtractFrom.length; i++) { equationToSubtractFrom[i] = modP(equationToSubtractFrom[i] - multiplyModP(fragmentCoefficient, equationToSubtract[i])); } }
I use longs because Java does not support unsigned integers, but both vectors are mod p, so you can expect each number to be 0 <= x <(2 ^ 32) -5
Any ideas to optimize this? The mod p operation is what takes most of the execution time, so one way to optimize it may somehow not do modP after multiplication and only do it after subtraction. Any ideas on how to do this?
java performance optimization primes modulo
Yrlec
source share