Advertisement
ItsTotallyRSX

Parse floating point numbers to 2xints [int_a.int_b]

Jul 23rd, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.18 KB | None | 0 0
  1. #define D_TO_I(x) _mm_xor_si128(_mm_castpd_si128(_mm_add_pd(x, _mm_set1_pd(0x0010000000000000))),_mm_castpd_si128(_mm_set1_pd(0x0010000000000000)));
  2. void _printf_floating_point_strip(safe_double_ref d, int places, uint64_t * o_integer, uint64_t * o_fraction)
  3. {
  4. double _pow = 1; //
  5. for (int i = 0; i < places; i++) //there is no sse instruction and subsequent intrinsic for pow //
  6. _pow *= 10; // power := pow(10, places)
  7. //
  8. __m128d number_double = _mm_load1_pd(d); // number_double := d
  9. __m128d power_double = _mm_load1_pd(&_pow); // power_double := power
  10. //
  11. __m128d int_double = _mm_round_pd(number_double, 0x03 | 0x00); // int_double := round(number_double, truncate)
  12. __m128d frac_double = _mm_mul_pd(_mm_sub_pd(number_double, int_double), power_double); // frac_double := (number_double - int_double) * power_double
  13. //
  14. __m128i integer = D_TO_I(int_double); // integer := int_double
  15. __m128i fraction = D_TO_I(frac_double); // fraction := frac_double
  16. //
  17. *o_integer = integer.m128i_u64[0]; // *o_integer = integer
  18. *o_fraction = fraction.m128i_u64[0]; // *o_fraction = fraction
  19. }
  20. #undef D_TO_I
  21.  
  22.  
  23. .text:0000000180004550 sub_180004550 proc near ; CODE XREF: sub_1800042F0+35p
  24. .text:0000000180004550 ; DATA XREF: .pdata:000000018002A2D0o
  25. .text:0000000180004550
  26. .text:0000000180004550 var_s0 = qword ptr 0
  27. .text:0000000180004550 var_s8 = dword ptr 8
  28. .text:0000000180004550 var_s10 = xmmword ptr 10h
  29. .text:0000000180004550 var_s20 = xmmword ptr 20h
  30. .text:0000000180004550 var_s30 = xmmword ptr 30h
  31. .text:0000000180004550 var_s40 = xmmword ptr 40h
  32. .text:0000000180004550 var_s50 = xmmword ptr 50h
  33. .text:0000000180004550 arg_0 = qword ptr 0B0h
  34. .text:0000000180004550 arg_8 = dword ptr 0B8h
  35. .text:0000000180004550 arg_10 = qword ptr 0C0h
  36. .text:0000000180004550 arg_18 = qword ptr 0C8h
  37. .text:0000000180004550
  38. .text:0000000180004550 mov [rsp-0A8h+arg_18], r9
  39. .text:0000000180004555 mov [rsp-0A8h+arg_10], r8
  40. .text:000000018000455A mov [rsp-0A8h+arg_8], edx
  41. .text:000000018000455E mov [rsp-0A8h+arg_0], rcx
  42. .text:0000000180004563 push rbp
  43. .text:0000000180004564 sub rsp, 0A0h
  44. .text:000000018000456B mov rbp, rsp
  45. .text:000000018000456E movsd xmm0, cs:qword_180015DF0
  46. .text:0000000180004576 movsd [rbp+var_s0], xmm0
  47. .text:000000018000457B mov [rbp+var_s8], 0
  48. .text:0000000180004582 jmp short loc_18000458C
  49. .text:0000000180004584 ; ---------------------------------------------------------------------------
  50. .text:0000000180004584
  51. .text:0000000180004584 loc_180004584: ; CODE XREF: sub_180004550+59j
  52. .text:0000000180004584 mov eax, [rbp+var_s8]
  53. .text:0000000180004587 inc eax
  54. .text:0000000180004589 mov [rbp+var_s8], eax
  55. .text:000000018000458C
  56. .text:000000018000458C loc_18000458C: ; CODE XREF: sub_180004550+32j
  57. .text:000000018000458C mov eax, [rbp+arg_8]
  58. .text:0000000180004592 cmp [rbp+var_s8], eax
  59. .text:0000000180004595 jge short loc_1800045AB
  60. .text:0000000180004597 movsd xmm0, [rbp+var_s0]
  61. .text:000000018000459C mulsd xmm0, cs:qword_180015DF8
  62. .text:00000001800045A4 movsd [rbp+var_s0], xmm0
  63. .text:00000001800045A9 jmp short loc_180004584
  64. .text:00000001800045AB ; ---------------------------------------------------------------------------
  65. .text:00000001800045AB
  66. .text:00000001800045AB loc_1800045AB: ; CODE XREF: sub_180004550+45j
  67. .text:00000001800045AB movsd xmm0, [rbp+var_s0]
  68. .text:00000001800045B0 shufpd xmm0, xmm0, 0
  69. .text:00000001800045B5 movaps [rbp+var_s10], xmm0
  70. .text:00000001800045B9 mov rax, [rbp+arg_0]
  71. .text:00000001800045C0 movsd xmm0, qword ptr [rax]
  72. .text:00000001800045C4 shufpd xmm0, xmm0, 0
  73. .text:00000001800045C9 movaps [rbp+var_s20], xmm0
  74. .text:00000001800045CD movaps xmm0, [rbp+var_s20]
  75. .text:00000001800045D1 roundpd xmm0, xmm0, 3
  76. .text:00000001800045D7 movaps [rbp+var_s30], xmm0
  77. .text:00000001800045DB mov rax, 10000000000000h
  78. .text:00000001800045E5 cvtsi2sd xmm0, rax
  79. .text:00000001800045EA unpcklpd xmm0, xmm0
  80. .text:00000001800045EE mov rax, 10000000000000h
  81. .text:00000001800045F8 cvtsi2sd xmm1, rax
  82. .text:00000001800045FD unpcklpd xmm1, xmm1
  83. .text:0000000180004601 movaps xmm2, [rbp+var_s30]
  84. .text:0000000180004605 addpd xmm2, xmm1
  85. .text:0000000180004609 movaps xmm1, xmm2
  86. .text:000000018000460C pxor xmm1, xmm0
  87. .text:0000000180004610 movdqa xmm0, xmm1
  88. .text:0000000180004614 movdqa [rbp+var_s40], xmm0
  89. .text:0000000180004619 mov rax, 10000000000000h
  90. .text:0000000180004623 cvtsi2sd xmm0, rax
  91. .text:0000000180004628 unpcklpd xmm0, xmm0
  92. .text:000000018000462C mov rax, 10000000000000h
  93. .text:0000000180004636 cvtsi2sd xmm1, rax
  94. .text:000000018000463B unpcklpd xmm1, xmm1
  95. .text:000000018000463F movaps xmm2, [rbp+var_s20]
  96. .text:0000000180004643 subpd xmm2, [rbp+var_s30]
  97. .text:0000000180004648 mulpd xmm2, [rbp+var_s10]
  98. .text:000000018000464D addpd xmm2, xmm1
  99. .text:0000000180004651 movaps xmm1, xmm2
  100. .text:0000000180004654 pxor xmm1, xmm0
  101. .text:0000000180004658 movdqa xmm0, xmm1
  102. .text:000000018000465C movdqa [rbp+var_s50], xmm0
  103. .text:0000000180004661 mov eax, 8
  104. .text:0000000180004666 imul rax, 0
  105. .text:000000018000466A mov rcx, [rbp+arg_10]
  106. .text:0000000180004671 mov rax, qword ptr [rbp+rax+var_s40]
  107. .text:0000000180004676 mov [rcx], rax
  108. .text:0000000180004679 mov eax, 8
  109. .text:000000018000467E imul rax, 0
  110. .text:0000000180004682 mov rcx, [rbp+arg_18]
  111. .text:0000000180004689 mov rax, qword ptr [rbp+rax+var_s50]
  112. .text:000000018000468E mov [rcx], rax
  113. .text:0000000180004691 lea rsp, [rbp+0A0h]
  114. .text:0000000180004698 pop rbp
  115. .text:0000000180004699 retn
  116. .text:0000000180004699 sub_180004550 endp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement