carta_random.S 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Fast, simple, yet decent quality random number generator based on
  4. * a paper by David G. Carta ("Two Fast Implementations of the
  5. * `Minimal Standard' Random Number Generator," Communications of the
  6. * ACM, January, 1990).
  7. *
  8. * Copyright (C) 2002 Hewlett-Packard Co
  9. * David Mosberger-Tang <davidm@hpl.hp.com>
  10. */
  11. #include <asm/asmmacro.h>
  12. #define a r2
  13. #define m r3
  14. #define lo r8
  15. #define hi r9
  16. #define t0 r16
  17. #define t1 r17
  18. #define seed r32
  19. GLOBAL_ENTRY(carta_random32)
  20. movl a = (16807 << 16) | 16807
  21. ;;
  22. pmpyshr2.u t0 = a, seed, 0
  23. pmpyshr2.u t1 = a, seed, 16
  24. ;;
  25. unpack2.l t0 = t1, t0
  26. dep m = -1, r0, 0, 31
  27. ;;
  28. zxt4 lo = t0
  29. shr.u hi = t0, 32
  30. ;;
  31. dep t0 = 0, hi, 15, 49 // t0 = (hi & 0x7fff)
  32. ;;
  33. shl t0 = t0, 16 // t0 = (hi & 0x7fff) << 16
  34. shr t1 = hi, 15 // t1 = (hi >> 15)
  35. ;;
  36. add lo = lo, t0
  37. ;;
  38. cmp.gtu p6, p0 = lo, m
  39. ;;
  40. (p6) and lo = lo, m
  41. ;;
  42. (p6) add lo = 1, lo
  43. ;;
  44. add lo = lo, t1
  45. ;;
  46. cmp.gtu p6, p0 = lo, m
  47. ;;
  48. (p6) and lo = lo, m
  49. ;;
  50. (p6) add lo = 1, lo
  51. br.ret.sptk.many rp
  52. END(carta_random32)