github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/x86_64/missing.asm (about)

     1  
     2  	dnl  AMD64 MULX/ADX simulation support.
     3  
     4  dnl  Contributed to the GNU project by Torbjörn Granlund.
     5  
     6  dnl  Copyright 2013 Free Software Foundation, Inc.
     7  
     8  dnl  This file is part of the GNU MP Library.
     9  dnl
    10  dnl  The GNU MP Library is free software; you can redistribute it and/or modify
    11  dnl  it under the terms of either:
    12  dnl
    13  dnl    * the GNU Lesser General Public License as published by the Free
    14  dnl      Software Foundation; either version 3 of the License, or (at your
    15  dnl      option) any later version.
    16  dnl
    17  dnl  or
    18  dnl
    19  dnl    * the GNU General Public License as published by the Free Software
    20  dnl      Foundation; either version 2 of the License, or (at your option) any
    21  dnl      later version.
    22  dnl
    23  dnl  or both in parallel, as here.
    24  dnl
    25  dnl  The GNU MP Library is distributed in the hope that it will be useful, but
    26  dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    27  dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    28  dnl  for more details.
    29  dnl
    30  dnl  You should have received copies of the GNU General Public License and the
    31  dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
    32  dnl  see https://www.gnu.org/licenses/.
    33  
    34  
    35  include(`../config.m4')
    36  
    37  ASM_START()
    38  
    39  C Fake the MULX instruction
    40  C
    41  C Accept the single explicit parameter on the stack, return the two result
    42  C words on the stack.  This calling convention means that we need to move the
    43  C return address up.
    44  C
    45  PROLOGUE(__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
    60  EPILOGUE()
    61  PROTECT(__gmp_mulx)
    62  
    63  
    64  C Fake the ADOX instruction
    65  C
    66  C Accept the two parameters on the stack, return the result word on the stack.
    67  C This calling convention means that we need to move the return address down.
    68  C
    69  PROLOGUE(__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
    77  C 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
    83  C put manipulated flags into eflags, execute a plain adc
    84  	popfq
    85  	adc	%rcx, 48(%rsp)
    86  C 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
    93  C put manipulated flags into eflags
    94  	popfq
    95  	pop	%rax
    96  	pop	%rbx
    97  	pop	%rcx
    98  	lea	8(%rsp), %rsp
    99  	ret
   100  EPILOGUE()
   101  PROTECT(__gmp_adox)
   102  
   103  
   104  C Fake the ADCX instruction
   105  C
   106  C Accept the two parameters on the stack, return the result word on the stack.
   107  C This calling convention means that we need to move the return address down.
   108  C
   109  PROLOGUE(__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
   129  EPILOGUE()
   130  PROTECT(__gmp_adcx)