Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1.  
  2.  
  3. // a:c = a+x+c c is bool - carry flag
  4. inline void ADC(u64*a, u64 x, u64*c) {
  5. __asm__("negq %1 ;"
  6. "adcq %3, %0 ;"
  7. "sbbq %1, %1 ;"
  8. : "=rm" (*a), "=r" (*c)
  9. : "1" (*c), "r" (x)
  10. : "cc");
  11. }
  12.  
  13.  
  14.  
  15. // zN:-borrow = zN - xN*y - w
  16. // return is borrow
  17. u64 _mulsub_NN1(u64*z, u64*x, u64 y, u64 w, i64 N) {
  18. assert(N>=0);
  19. u64 a=0, b=0; // two carry flags
  20. u64 l, h;
  21. for (i64 i=0; i<N; i++) {
  22.  
  23. INT3();
  24.  
  25. MUL(&l, &h, x[i], y);
  26. printf("after MUL:\n");
  27. printf("h: %llu \n",h);
  28. printf("b: %llu \n",b);
  29.  
  30. printf("l: %llu \n",l);
  31. printf("w: %llu \n",w);
  32. printf("a: %llu \n",a);
  33.  
  34. ADC(&l, w, &a);
  35.  
  36. printf("after ADC:\n");
  37. printf("l: %llu \n",l);
  38. printf("w: %llu \n",w);
  39. printf("a: %llu \n",a);
  40.  
  41.  
  42. SBB(&z[i], l, &b);
  43.  
  44. printf("after SBB:\n");
  45. printf("z[i]: %llu \n",z[i]);
  46. printf("l: %llu \n",l);
  47. printf("b: %llu \n",b);
  48.  
  49.  
  50. w = h;
  51. }
  52. ADC(&w, 0, &b);
  53. printf("w: %llu \n",w);
  54. return w;
  55. }
  56.  
  57.  
  58. program output
  59.  
  60. l: 6 <- these are all correct
  61. w: 0 <- these are all correct
  62. a: 0 <- these are all correct
  63. after ADC:
  64. l: 2357104 <- l should be 6 here, but is actually the address of l
  65. w: 0
  66. a: 0
  67. after SBB:
  68. z[i]: 1773168
  69. l: 2357104
  70. b: 0
  71. w: 2357176
  72. b: 2357176
  73. b: 2357160
  74. Assertion failed!
  75.  
  76. Program: C:\Users\pc\Dropbox\cas\cas.exe
  77. File: idiv.cpp, Line 268
  78.  
  79. Expression: b==0
  80.  
  81. This application has requested the Runtime to terminate it in an unusual way.
  82. Please contact the application's support team for more information.
  83.  
  84. C:\Users\pc\Dropbox\cas>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement