1 2 dnl AMD64 MULX/ADX simulation support. 3 4dnl Contributed to the GNU project by Torbj��rn Granlund. 5 6dnl Copyright 2013 Free Software Foundation, Inc. 7 8dnl This file is part of the GNU MP Library. 9dnl 10dnl The GNU MP Library is free software; you can redistribute it and/or modify 11dnl it under the terms of either: 12dnl 13dnl * the GNU Lesser General Public License as published by the Free 14dnl Software Foundation; either version 3 of the License, or (at your 15dnl option) any later version. 16dnl 17dnl or 18dnl 19dnl * the GNU General Public License as published by the Free Software 20dnl Foundation; either version 2 of the License, or (at your option) any 21dnl later version. 22dnl 23dnl or both in parallel, as here. 24dnl 25dnl The GNU MP Library is distributed in the hope that it will be useful, but 26dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 27dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28dnl for more details. 29dnl 30dnl You should have received copies of the GNU General Public License and the 31dnl GNU Lesser General Public License along with the GNU MP Library. If not, 32dnl see https://www.gnu.org/licenses/. 33 34 35include(`../config.m4') 36 37ASM_START() 38 39C Fake the MULX instruction 40C 41C Accept the single explicit parameter on the stack, return the two result 42C words on the stack. This calling convention means that we need to move the 43C return address up. 44C 45PROLOGUE(__gmp_mulx) 46 lea -8(%rsp), %rsp 47 push %rax 48 push %rdx 49 pushfq C preserve all flags 50 mov 32(%rsp), %rax C move retaddr... 51 mov %rax, 24(%rsp) C ...up the stack 52 mov 40(%rsp), %rax C input parameter 53 mul %rdx 54 mov %rax, 32(%rsp) 55 mov %rdx, 40(%rsp) 56 popfq C restore eflags 57 pop %rdx 58 pop %rax 59 ret 60EPILOGUE() 61PROTECT(__gmp_mulx) 62 63 64C Fake the ADOX instruction 65C 66C Accept the two parameters on the stack, return the result word on the stack. 67C This calling convention means that we need to move the return address down. 68C 69PROLOGUE(__gmp_adox) 70 push %rcx 71 push %rbx 72 push %rax 73 mov 32(%rsp), %rcx C src2 74 mov 24(%rsp), %rax C move retaddr... 75 mov %rax, 32(%rsp) C ...down the stack 76 pushfq 77C copy 0(%rsp):11 to 0(%rsp):0 78 mov (%rsp), %rbx 79 shr %rbx 80 bt $10, %rbx 81 adc %rbx, %rbx 82 push %rbx 83C put manipulated flags into eflags, execute a plain adc 84 popfq 85 adc %rcx, 48(%rsp) 86C copy CF to 0(%rsp):11 87 pop %rbx 88 sbb R32(%rax), R32(%rax) 89 and $0x800, R32(%rax) 90 and $0xfffffffffffff7ff, %rbx 91 or %rax, %rbx 92 push %rbx 93C put manipulated flags into eflags 94 popfq 95 pop %rax 96 pop %rbx 97 pop %rcx 98 lea 8(%rsp), %rsp 99 ret 100EPILOGUE() 101PROTECT(__gmp_adox) 102 103 104C Fake the ADCX instruction 105C 106C Accept the two parameters on the stack, return the result word on the stack. 107C This calling convention means that we need to move the return address down. 108C 109PROLOGUE(__gmp_adcx) 110 push %rcx 111 push %rbx 112 push %rax 113 mov 32(%rsp), %rcx C src2 114 mov 24(%rsp), %rax C move retaddr... 115 mov %rax, 32(%rsp) C ...down the stack 116 pushfq 117 adc %rcx, 48(%rsp) 118 pop %rbx 119 sbb R32(%rax), R32(%rax) 120 and $`'0xfffffffffffffffe, %rbx 121 sub %rax, %rbx 122 push %rbx 123 popfq 124 pop %rax 125 pop %rbx 126 pop %rcx 127 lea 8(%rsp), %rsp 128 ret 129EPILOGUE() 130PROTECT(__gmp_adcx) 131