Advertisement
Guest User

Inlined thread locals

a guest
May 13th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. uint64_t getRandomUnsigned64() {
  2. static thread_local uint64_t RandomStateA =
  3. static_cast<uint64_t>(time(nullptr));
  4. static thread_local uint64_t RandomStateB = xorShiftStar64();
  5.  
  6. uint64_t A = RandomStateA;
  7. const uint64_t B = RandomStateB;
  8. RandomStateA = B;
  9.  
  10. A ^= A << 23;
  11. A ^= A >> 17;
  12. A ^= B ^ (B >> 26);
  13.  
  14. RandomStateB = A;
  15. return A + B;
  16. }
  17.  
  18. ==========================================================================
  19. 00000000004006b0 <gwp_asan::random::getRandomUnsigned64()>:
  20. 4006b0: 53 push %rbx
  21. 4006b1: 66 66 66 64 48 8b 04 data16 data16 data16 mov %fs:0x0,%rax
  22. 4006b8: 25 00 00 00 00
  23. 4006bd: 48 89 c3 mov %rax,%rbx
  24. # TLS init check/branch for RandomStateA.
  25. 4006c0: 80 b8 d8 ff ff ff 00 cmpb $0x0,-0x28(%rax)
  26. 4006c7: 74 51 je 40071a <gwp_asan::random::getRandomUnsigned64()+0x6a> #
  27. # TLS init check/branch for RandomStateB (with an unneccessary `%rbx = %rax` copy).
  28. 4006c9: 48 89 d8 mov %rbx,%rax
  29. 4006cc: 80 bb e8 ff ff ff 01 cmpb $0x1,-0x18(%rbx)
  30. 4006d3: 75 6c jne 400741 <gwp_asan::random::getRandomUnsigned64()+0x91>
  31. 4006d5: 48 89 d8 mov %rbx,%rax
  32. 4006d8: 48 8b 93 e0 ff ff ff mov -0x20(%rbx),%rdx
  33. 4006df: 48 8b b3 d0 ff ff ff mov -0x30(%rbx),%rsi
  34. 4006e6: 48 89 93 d0 ff ff ff mov %rdx,-0x30(%rbx)
  35. 4006ed: 48 89 f1 mov %rsi,%rcx
  36. 4006f0: 48 c1 e1 17 shl $0x17,%rcx
  37. 4006f4: 48 31 f1 xor %rsi,%rcx
  38. 4006f7: 48 89 d0 mov %rdx,%rax
  39. 4006fa: 48 c1 e8 1a shr $0x1a,%rax
  40. 4006fe: 48 31 d0 xor %rdx,%rax
  41. 400701: 48 31 c8 xor %rcx,%rax
  42. 400704: 48 c1 e9 11 shr $0x11,%rcx
  43. 400708: 48 31 c1 xor %rax,%rcx
  44. 40070b: 48 89 8b e0 ff ff ff mov %rcx,-0x20(%rbx)
  45. 400712: 48 01 d1 add %rdx,%rcx
  46. 400715: 48 89 c8 mov %rcx,%rax
  47. 400718: 5b pop %rbx
  48. 400719: c3 retq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement