1 #line 2 "../src/kernel/x86-64/asm0.h" 2 /* $Id: asm0.h 9123 2007-10-29 10:47:21Z kb $ 3 4 Copyright (C) 2004 The PARI group. 5 6 This file is part of the PARI/GP package. 7 8 PARI/GP is free software; you can redistribute it and/or modify it under the 9 terms of the GNU General Public License as published by the Free Software 10 Foundation. It is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY WHATSOEVER. 12 13 Check the License for details. You should have received a copy of it, along 14 with the package; see the file 'COPYING'. If not, write to the Free Software 15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 16 17 /* 18 ASM addll mulll bfffo divll 19 */ 20 /* Written by Bill Allombert from the ix86 version by Bruno Haible. Basically 21 * change insl to insq*/ 22 #ifdef ASMINLINE 23 #define LOCAL_HIREMAINDER register ulong hiremainder 24 #define LOCAL_OVERFLOW register ulong overflow 25 26 #define addll(a,b) \ 27 ({ ulong __value, __arg1 = (a), __arg2 = (b); \ 28 __asm__ ("addq %3,%0 ; adcq %1,%1" \ 29 : "=r" (__value), "=r" (overflow) \ 30 : "0" (__arg1), "g" (__arg2), "1" ((ulong)0) \ 31 : "cc"); \ 32 __value; \ 33 }) 34 35 #define addllx(a,b) \ 36 ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \ 37 __asm__ ("subq %5,%2 ; adcq %4,%0 ; adcq %1,%1" \ 38 : "=r" (__value), "=&r" (overflow), "=r" (__temp) \ 39 : "0" (__arg1), "g" (__arg2), "g" (overflow), "1" ((ulong)0), "2" ((ulong)0) \ 40 : "cc"); \ 41 __value; \ 42 }) 43 44 #define subll(a,b) \ 45 ({ ulong __value, __arg1 = (a), __arg2 = (b); \ 46 __asm__ ("subq %3,%0 ; adcq %1,%1" \ 47 : "=r" (__value), "=r" (overflow) \ 48 : "0" (__arg1), "g" (__arg2), "1" ((ulong)0) \ 49 : "cc"); \ 50 __value; \ 51 }) 52 53 #define subllx(a,b) \ 54 ({ ulong __value, __arg1 = (a), __arg2 = (b), __temp; \ 55 __asm__ ("subq %5,%2 ; sbbq %4,%0 ; adcq %1,%1" \ 56 : "=r" (__value), "=&r" (overflow), "=r" (__temp) \ 57 : "0" (__arg1), "g" (__arg2), "g" (overflow), "1" ((ulong)0), "2" ((ulong)0) \ 58 : "cc"); \ 59 __value; \ 60 }) 61 62 #define mulll(a,b) \ 63 ({ ulong __valuelo, __arg1 = (a), __arg2 = (b); \ 64 __asm__ ("mulq %3" \ 65 : "=a" /* %eax */ (__valuelo), "=d" /* %edx */ (hiremainder) \ 66 : "0" (__arg1), "rm" (__arg2)); \ 67 __valuelo; \ 68 }) 69 70 #define addmul(a,b) \ 71 ({ ulong __valuelo, __arg1 = (a), __arg2 = (b), __temp; \ 72 __asm__ ("mulq %4 ; addq %5,%0 ; adcq %6,%1" \ 73 : "=a" /* %eax */ (__valuelo), "=&d" /* %edx */ (hiremainder), "=r" (__temp) \ 74 : "0" (__arg1), "rm" (__arg2), "g" (hiremainder), "2" ((ulong)0)); \ 75 __valuelo; \ 76 }) 77 78 #define divll(a,b) \ 79 ({ ulong __value, __arg1 = (a), __arg2 = (b); \ 80 __asm__ ("divq %4" \ 81 : "=a" /* %eax */ (__value), "=&d" /* %edx */ (hiremainder) \ 82 : "0" /* %eax */ (__arg1), "1" /* %edx */ (hiremainder), "mr" (__arg2)); \ 83 __value; \ 84 }) 85 86 #define bfffo(x) \ 87 ({ ulong __arg = (x); \ 88 long leading_one_position; \ 89 __asm__ ("bsrq %1,%0" : "=r" (leading_one_position) : "rm" (__arg)); \ 90 63 - leading_one_position; \ 91 }) 92 #endif 93