Madmouse

lightweight xorshift prng implementation

Jun 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;////////////////////////////////////////////////////////////////////////////////
  2. ;// THE SCOTCH-WARE LICENSE (Revision 0):
  3. ;// <aaronryool/gmail.com> wrote this file. As long as you retain this notice you
  4. ;// can do whatever you want with this stuff. If we meet some day, and you think
  5. ;// this stuff is worth it, you can buy me a shot of scotch in return
  6. ;////////////////////////////////////////////////////////////////////////////////
  7.  
  8. ; George Marsaglia's xorshift PRNG
  9. ; t = r10
  10. prng_state:
  11. w: dq 99999
  12. x: dq 100
  13. y: dq 35
  14. z: dq 27365
  15.  
  16. prng_seed:
  17. rdtsc
  18. mov qword [x], rax
  19. ret
  20.  
  21. prng:
  22. ; t = x
  23. mov r10, qword [x]
  24. ; t ^= t << 11
  25. mov rax, r10
  26. shl rax, 11
  27. xor r10, rax
  28. ; t ^= t >> 8
  29. mov rax, r10
  30. shr rax, 8
  31. xor r10, rax
  32. ; x = y, y = z, z = w
  33. push qword [w]
  34. push qword [y]
  35. push qword [z]
  36. pop qword [y]
  37. pop qword [x]
  38. pop qword [z]
  39. ; w ^= w >> 19
  40. mov rax, [w]
  41. shr rax, 19
  42. xor qword [w], rax
  43. ; w ^= t
  44. xor qword [w], r10
  45.  
  46. ; return w
  47. mov rax, qword [w]
  48. ret
Add Comment
Please, Sign In to add comment