⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 amd64.mcs

📁 miracl-大数运算库,大家使用有什么问题请多多提意见
💻 MCS
字号:
; MCS file for Gnu GCC 80386-Pentium compiler
;
; Sorry about all the %'s! Each % must be input here as %%
; Triple register is cl|rdi|rbp
; MUL_START. Initialise registers. Make rbx and rsi point to multipliers a 
; and b. rdi points at result c. Note rdi is shared.
; Initialise Triple register to 0
; See makemcs.txt for more information about this file
; 
MACRO MUL_START
  ASM (
  "movq %%0,%%%%rbx\n"
  "movq %%1,%%%%rsi\n"
  "movq %%2,%%%%rdi\n"
  "pushq %%%%rbp\n"
  "pushq %%%%rdi\n"
  "xorq %%%%rcx,%%%%rcx\n"
  "xorq %%%%rdi,%%%%rdi\n"
  "xorq %%%%rbp,%%%%rbp\n"
ENDM
;
; STEP macro. Calculates a double-register partial product
; and adds it to the triple register total
; Parameters 1 & 2: Indices i and j for partial product multipliers a[i] 
; and b[j]
MACRO STEP
  "movq 8*%d(%%%%rbx),%%%%rax\n"
  "mulq 8*%d(%%%%rsi)\n"
  "addq %%%%rax,%%%%rbp\n"
  "adcq %%%%rdx,%%%%rdi\n"
  "adc %%%%ch,%%%%cl\n"
ENDM
;
; LAST
;
MACRO LAST
  "movq 8*%d(%%%%rbx),%%%%rax\n"
  "mulq 8*%d(%%%%rsi)\n"
  "addq %%%%rax,%%%%rbp\n"
ENDM
;
; MFIN macro. Finish column calculation. Store Sum for this column
; and get Carry for next
; Parameter 1: Index k for Column Sum c[k]
MACRO MFIN
  "movq %%%%rdi,%%%%rdx\n"
  "popq %%%%rdi\n"
  "movq %%%%rbp,8*%d(%%%%rdi)\n"
  "pushq %%%%rdi\n"
  "movq %%%%rdx,%%%%rbp\n"
  "movq %%%%rcx,%%%%rdi\n"
  "xor %%%%cl,%%%%cl\n"
ENDM
;
; MUL_END
; Parameter 1: Index for final carry c[.]
MACRO MUL_END 
  "popq %%%%rdi\n"
  "movq %%%%rbp,8*%d(%%%%rdi)\n"
  "popq %%%%rbp\n"
   :
   :"m"(a),"m"(b),"m"(c)
   :"rax","rdi","rsi","rbx","rcx","rdx","rbp","memory"
  );
ENDM
;
; SQR_START
; 
MACRO SQR_START
  ASM (
  "movq %%0,%%%%rbx\n"
  "movq %%1,%%%%rsi\n"
  "pushq %%%%rbp\n"
  "xorq %%%%rcx,%%%%rcx\n"
  "xorq %%%%rdi,%%%%rdi\n"
  "xorq %%%%rbp,%%%%rbp\n"
ENDM
;
; DSTEP macro. Calculates a double-register partial product
; and add it twice to a triple register total
; Parameters 1 & 2 : Indices of partial product multipliers
MACRO DSTEP
  "movq 8*%d(%%%%rbx),%%%%rax\n"
  "mulq 8*%d(%%%%rbx)\n"
  "addq %%%%rax,%%%%rbp\n"
  "adcq %%%%rdx,%%%%rdi\n"
  "adc  %%%%ch,%%%%cl\n"
  "addq %%%%rax,%%%%rbp\n"
  "adcq %%%%rdx,%%%%rdi\n"
  "adc  %%%%ch,%%%%cl\n"
ENDM
;
; SELF macro. Calculate the double-register square and
; add it to a triple register total
; Parameter 1 : Index of diagonal element
MACRO SELF
  "movq 8*%d(%%%%rbx),%%%%rax\n"
  "mulq %%%%rax\n"
  "addq %%%%rax,%%%%rbp\n"
  "adcq %%%%rdx,%%%%rdi\n"
  "adc  %%%%ch,%%%%cl\n"
ENDM
;
; SFIN macro. Finish column calculation for squaring. Store Sum
; and get Carry for next column.
; Parameter 1: Index of Column Sum
MACRO SFIN
  "movq %%%%rbp,8*%d(%%%%rsi)\n"
  "movq %%%%rdi,%%%%rbp\n"
  "movq %%%%rcx,%%%%rdi\n"
  "xor  %%%%cl,%%%%cl\n"
ENDM
;
; SQR_END
; Parameter 1: Index for final carry
MACRO SQR_END
  "movq %%%%rbp,8*%d(%%%%rsi)\n"
  "popq %%%%rbp\n"
   :
   :"m"(a),"m"(c)
   :"rax","rdi","rsi","rbx","rcx","rdx","rbp","memory"
  );
ENDM
;
; REDC_START
;
MACRO REDC_START
  ASM (
  "movq %%0,%%%%rbx\n"
  "movq %%1,%%%%rsi\n"
  "movq %%2,%%%%rdx\n"
  "pushq %%%%rbp\n"
  "pushq %%%%rdx\n"
  "xorq %%%%rdi,%%%%rdi\n"
  "xorq %%%%rcx,%%%%rcx\n"
  "movq (%%%%rbx),%%%%rbp\n"
ENDM
;
; RFINU macro
;
MACRO RFINU
  "movq %%%%rbp,%%%%rax\n"
  "popq %%%%rdx\n"
  "pushq %%%%rdx\n"
  "mulq %%%%rdx\n"
  "movq %%%%rax,8*%d(%%%%rbx)\n"
  "mulq (%%%%rsi)\n"
  "addq %%%%rax,%%%%rbp\n"
  "adcq %%%%rdx,%%%%rdi\n"
  "adc  %%%%ch,%%%%cl\n"
  "movq %%%%rdi,%%%%rbp\n"
  "movq %%%%rcx,%%%%rdi\n"
  "xorq %%%%rcx,%%%%rcx\n"
  "addq 8*(%d+1)(%%%%rbx),%%%%rbp\n"
  "adcq %%%%rcx,%%%%rdi\n"
ENDM
;
; RFIND macro
;
MACRO RFIND
  "movq %%%%rbp,8*%d(%%%%rbx)\n"
  "movq %%%%rdi,%%%%rbp\n"
  "movq %%%%rcx,%%%%rdi\n"
  "xorq %%%%rcx,%%%%rcx\n"
  "addq 8*(%d+1)(%%%%rbx),%%%%rbp\n"
  "adcq %%%%rcx,%%%%rdi\n"
ENDM
;
; REDC_END
;
MACRO REDC_END
  "movq %%%%rbp,8*%d(%%%%rbx)\n"
  "movq %%%%rdi,8*(%d+1)(%%%%rbx)\n"
  "popq %%%%rdx\n"
  "popq %%%%rbp\n"
   :
   :"m"(a),"m"(b),"m"(ndash)
   :"rax","rdi","rsi","rbx","rcx","rdx","rbp","memory"
  );
ENDM
;
; ADD_START macro - initialise for add. Do first one
;
MACRO ADD_START
  ASM (
  "movq %%0,%%%%rsi\n"
  "movq %%1,%%%%rbx\n"
  "movq %%3,%%%%rdi\n"
  "movq (%%%%rsi),%%%%rax\n"
  "addq (%%%%rbx),%%%%rax\n"
  "movq %%%%rax,(%%%%rdi)\n"
ENDM
;
; ADD macro. Add two numbers from memory and store result in memory.
; Don't forget carry bit
;
MACRO ADD
  "movq 8*%d(%%%%rsi),%%%%rax\n"
  "adcq 8*%d(%%%%rbx),%%%%rax\n"
  "movq %%%%rax,8*%d(%%%%rdi)\n"
ENDM
;
; ADD_END macro. Catch Carry
;
MACRO ADD_END
  "movq $0,%%%%rax\n"
  "adcq %%%%rax,%%%%rax\n"
  "movq %%%%rax,%%2\n"
   :
   :"m"(a),"m"(b),"m"(carry),"m"(c)
   :"rax","rdi","rsi","rbx","memory"
  );
ENDM
;
; INC_START macro
;
MACRO INC_START
  ASM (
  "movq %%0,%%%%rdi\n"
  "movq %%1,%%%%rbx\n"
  "movq (%%%%rbx),%%%%rax\n"
  "addq %%%%rax,(%%%%rdi)\n"
ENDM
;
; INC macro. Increment number in memory. Don't forget carry
;
MACRO INC
  "movq 8*%d(%%%%rbx),%%%%rax\n"
  "adcq %%%%rax,8*%d(%%%%rdi)\n"
ENDM
;
; INC_END macro. Catch Carry
;
MACRO INC_END
  "movq $0,%%%%rax\n"
  "adcq %%%%rax,%%%%rax\n"
  "movq %%%%rax,%%2\n"
   :
   :"m"(a),"m"(b),"m"(carry)
   :"rax","rdi","rbx","memory"
  );
ENDM
;
; SUB_START macro. Do first one.
;
MACRO SUB_START
  ASM (
  "movq %%0,%%%%rsi\n"
  "movq %%1,%%%%rbx\n"
  "movq %%3,%%%%rdi\n"
  "movq (%%%%rsi),%%%%rax\n"
  "subq (%%%%rbx),%%%%rax\n"
  "movq %%%%rax,(%%%%rdi)\n"
ENDM
;
; SUB macro. Subtract two numbers in memory and store result in memory.
;
MACRO SUB
  "movq 8*%d(%%%%rsi),%%%%rax\n"
  "sbbq 8*%d(%%%%rbx),%%%%rax\n"
  "movq %%%%rax,8*%d(%%%%rdi)\n"
ENDM
;
; SUB_END macro. Catch Carry
;
MACRO SUB_END   
  "movq $0,%%%%rax\n"
  "adcq %%%%rax,%%%%rax\n"
  "movq %%%%rax,%%2\n"
   :
   :"m"(a),"m"(b),"m"(carry),"m"(c)
   :"rax","rdi","rsi","rbx","memory"
  );
ENDM
;
; DEC_START macro. Do first one.
;
MACRO DEC_START
  ASM (
  "movq %%0,%%%%rdi\n"
  "movq %%1,%%%%rbx\n"
  "movq (%%%%rbx),%%%%rax\n"
  "subq %%%%rax,(%%%%rdi)\n"
ENDM
;
; DEC macro. Decrement from number in memory. Don't forget borrow.
;
MACRO DEC
  "movq 8*%d(%%%%rbx),%%%%rax\n"
  "sbbq %%%%rax,8*%d(%%%%rdi)\n"
ENDM
;
; DEC_END macro
;
MACRO DEC_END
  "movq $0,%%%%rax\n"
  "adcq %%%%rax,%%%%rax\n"
  "movq %%%%rax,%%2\n"
   :
   :"m"(a),"m"(b),"m"(carry)
   :"rax","rdi","rbx","memory"
  );
ENDM
;
; KADD_START macro
;
MACRO KADD_START
  ASM (
  "movq %%0,%%%%rsi\n"
  "movq %%1,%%%%rbx\n"
  "movq %%3,%%%%rdi\n"
  "movq %%4,%%%%rcx\n"
  "xorq %%%%rax,%%%%rax\n"
  "k%d:\n"
ENDM
;
; KASL macro
;
MACRO KASL
  "decq %%%%rcx\n"  
  "je k%d\n"
  "leaq 8*%d(%%%%rsi),%%%%rsi\n"
  "leaq 8*%d(%%%%rbx),%%%%rbx\n"
  "leaq 8*%d(%%%%rdi),%%%%rdi\n"
  "jmp k%d\n"
  "k%d:\n"
ENDM
;
; KADD_END  macro
;
MACRO KADD_END
  "movq $0,%%%%rax\n"
  "adcq %%%%rax,%%%%rax\n"
  "movq %%%%rax,%%2\n"
   :
   :"m"(a),"m"(b),"m"(carry),"m"(c),"m"(n)
   :"rax","rdi","rsi","rbx","rcx","memory"
  );
ENDM
;
; KINC_START macro. Zero carry flag. 
;
MACRO KINC_START
  ASM (
  "movq %%0,%%%%rdi\n"
  "movq %%1,%%%%rbx\n"
  "movq %%3,%%%%rcx\n"
  "xorq %%%%rax,%%%%rax\n"
  "k%d:\n"
ENDM
;
; KIDL macro
;
MACRO KIDL
  "decq %%%%rcx\n"
  "je k%d\n"
  "leaq 8*%d(%%%%rbx),%%%%rbx\n"
  "leaq 8*%d(%%%%rdi),%%%%rdi\n"
  "jmp k%d\n"
  "k%d:\n"
ENDM
;
; KINC_END macro
;
MACRO KINC_END
  "movq $0,%%%%rax\n"
  "adcq %%%%rax,%%%%rax\n"
  "movq %%%%rax,%%2\n"
   :
   :"m"(a),"m"(b),"m"(carry),"m"(n)
   :"rax","rdi","rbx","rcx","memory"
  );
ENDM
;
; KDEC_START macro
;
MACRO KDEC_START
  ASM (
  "movq %%0,%%%%rdi\n"
  "movq %%1,%%%%rbx\n"
  "movq %%3,%%%%rcx\n"
  "xorq %%%%rax,%%%%rax\n"
  "k%d:\n"
ENDM
;
; KDEC_END macro
;
MACRO KDEC_END
  "movq $0,%%%%rax\n"
  "adcq %%%%rax,%%%%rax\n"
  "movq %%%%rax,%%2\n"
   :
   :"m"(a),"m"(b),"m"(carry),"m"(n)
   :"rax","rdi","rbx","rcx","memory"
  );
ENDM

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -