Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // a:c = a+x+c c is bool - carry flag
- inline void ADC(u64*a, u64 x, u64*c) {
- __asm__("negq %1 ;"
- "adcq %3, %0 ;"
- "sbbq %1, %1 ;"
- : "=rm" (*a), "=r" (*c)
- : "1" (*c), "r" (x)
- : "cc");
- }
- // zN:-borrow = zN - xN*y - w
- // return is borrow
- u64 _mulsub_NN1(u64*z, u64*x, u64 y, u64 w, i64 N) {
- assert(N>=0);
- u64 a=0, b=0; // two carry flags
- u64 l, h;
- for (i64 i=0; i<N; i++) {
- INT3();
- MUL(&l, &h, x[i], y);
- printf("after MUL:\n");
- printf("h: %llu \n",h);
- printf("b: %llu \n",b);
- printf("l: %llu \n",l);
- printf("w: %llu \n",w);
- printf("a: %llu \n",a);
- ADC(&l, w, &a);
- printf("after ADC:\n");
- printf("l: %llu \n",l);
- printf("w: %llu \n",w);
- printf("a: %llu \n",a);
- SBB(&z[i], l, &b);
- printf("after SBB:\n");
- printf("z[i]: %llu \n",z[i]);
- printf("l: %llu \n",l);
- printf("b: %llu \n",b);
- w = h;
- }
- ADC(&w, 0, &b);
- printf("w: %llu \n",w);
- return w;
- }
- program output
- l: 6 <- these are all correct
- w: 0 <- these are all correct
- a: 0 <- these are all correct
- after ADC:
- l: 2357104 <- l should be 6 here, but is actually the address of l
- w: 0
- a: 0
- after SBB:
- z[i]: 1773168
- l: 2357104
- b: 0
- w: 2357176
- b: 2357176
- b: 2357160
- Assertion failed!
- Program: C:\Users\pc\Dropbox\cas\cas.exe
- File: idiv.cpp, Line 268
- Expression: b==0
- This application has requested the Runtime to terminate it in an unusual way.
- Please contact the application's support team for more information.
- C:\Users\pc\Dropbox\cas>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement