github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/arm/v5/gcd_1.asm (about)

     1  dnl  ARM v5 mpn_gcd_1.
     2  
     3  dnl  Based on the K7 gcd_1.asm, by Kevin Ryde.  Rehacked for ARM by Torbjörn
     4  dnl  Granlund.
     5  
     6  dnl  Copyright 2000-2002, 2005, 2009, 2011, 2012 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  include(`../config.m4')
    35  
    36  C	     cycles/bit (approx)
    37  C StrongARM	 -
    38  C XScale	 ?
    39  C Cortex-A7	 ?
    40  C Cortex-A8	 ?
    41  C Cortex-A9	 5.9
    42  C Cortex-A15	 ?
    43  C Numbers measured with: speed -CD -s8-32 -t24 mpn_gcd_1
    44  
    45  C TODO
    46  C  * Optimise inner-loop better.
    47  
    48  C Threshold of when to call bmod when U is one limb.  Should be about
    49  C (time_in_cycles(bmod_1,1) + call_overhead) / (cycles/bit).
    50  define(`BMOD_THRES_LOG2', 6)
    51  
    52  C INPUT PARAMETERS
    53  define(`up',    `r0')
    54  define(`n',     `r1')
    55  define(`v0',    `r2')
    56  
    57  ifdef(`BMOD_1_TO_MOD_1_THRESHOLD',,
    58    `define(`BMOD_1_TO_MOD_1_THRESHOLD',0xffffffff)')
    59  
    60  ASM_START()
    61  	TEXT
    62  	ALIGN(16)
    63  PROLOGUE(mpn_gcd_1)
    64  	push	{r4, r7, lr}
    65  	ldr	r3, [up]	C U low limb
    66  
    67  	orr	r3, r3, v0
    68  	rsb	r4, r3, #0
    69  	and	r4, r4, r3
    70  	clz	r4, r4		C min(ctz(u0),ctz(v0))
    71  	rsb	r4, r4, #31
    72  
    73  	rsb	r12, v0, #0
    74  	and	r12, r12, v0
    75  	clz	r12, r12
    76  	rsb	r12, r12, #31
    77  	mov	v0, v0, lsr r12
    78  
    79  	mov	r7, v0
    80  
    81  	cmp	n, #1
    82  	bne	L(nby1)
    83  
    84  C Both U and V are single limbs, reduce with bmod if u0 >> v0.
    85  	ldr	r3, [up]
    86  	cmp	v0, r3, lsr #BMOD_THRES_LOG2
    87  	bhi	L(red1)
    88  
    89  L(bmod):mov	r3, #0		C carry argument
    90  	bl	mpn_modexact_1c_odd
    91  	b	L(red0)
    92  
    93  L(nby1):cmp	n, #BMOD_1_TO_MOD_1_THRESHOLD
    94  	blo	L(bmod)
    95  
    96  	bl	mpn_mod_1
    97  
    98  L(red0):mov	r3, r0
    99  L(red1):rsbs	r12, r3, #0
   100  	and	r12, r12, r3
   101  	clz	r12, r12
   102  	rsb	r12, r12, #31
   103  	bne	L(mid)
   104  	b	L(end)
   105  
   106  	ALIGN(8)
   107  L(top):	rsb	r12, r12, #31
   108  	movcc	r3, r1		C if x-y < 0
   109  	movcc	r7, r0		C use x,y-x
   110  L(mid):	mov	r3, r3, lsr r12	C
   111  	mov	r0, r3		C
   112  	sub	r1, r7, r3	C
   113  	rsbs	r3, r7, r3	C
   114  	and	r12, r1, r3	C
   115  	clz	r12, r12	C
   116  	bne	L(top)		C
   117  
   118  L(end):	mov	r0, r7, lsl r4
   119  	pop	{r4, r7, pc}
   120  EPILOGUE()