I'm having issues implementing a PRNG for ARM Assembly. I've tried a few algorithms that while working, end up taking a long time after the first few random number iterations, probably because the division (modulo) step takes a long time on large numbers. I'm trying to get a random number between 0 and 31. I've given my rough work below, with letters substituting specific registers.
start:
mov t, x // t = x
// t ^= t << 11
lsl temp, t, #11
eor t, temp
// t ^= t >> 8
lsr temp, t, #8
eor t, temp
// z = w
mov z, w
// x = y
mov x, y
// y = z
mov y, z
// w ^= w >> 19
lsr temp, w, #19
eor w, temp
// w ^= t
eor w, t
// r0 is the RETURNED RANDOM NUMBER
mov result, w
That's my algorithm that I tried to implement from the XORSHIFT page on wikipedia. I just need this to return a random number from 0 to 31, so implementing division on a 10-digit number takes a while and seems pretty overkill. If anyone can help me optimize or point out a mistake I'd appreciate it.
edit: The above subroutine returns the random number, and then I basically divide it by 31 (that code isn't given here) and take the remainder as my "random" number from 0 to 31.
Aucun commentaire:
Enregistrer un commentaire