Home | History | Annotate | Line # | Download | only in arm64
gcd_22.asm revision 1.1
      1 dnl  ARM v8a mpn_gcd_22.
      2 
      3 dnl  Copyright 2019 Free Software Foundation, Inc.
      4 
      5 dnl  This file is part of the GNU MP Library.
      6 dnl
      7 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
      8 dnl  it under the terms of either:
      9 dnl
     10 dnl    * the GNU Lesser General Public License as published by the Free
     11 dnl      Software Foundation; either version 3 of the License, or (at your
     12 dnl      option) any later version.
     13 dnl
     14 dnl  or
     15 dnl
     16 dnl    * the GNU General Public License as published by the Free Software
     17 dnl      Foundation; either version 2 of the License, or (at your option) any
     18 dnl      later version.
     19 dnl
     20 dnl  or both in parallel, as here.
     21 dnl
     22 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
     23 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     24 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     25 dnl  for more details.
     26 dnl
     27 dnl  You should have received copies of the GNU General Public License and the
     28 dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
     29 dnl  see https://www.gnu.org/licenses/.
     30 
     31 include(`../config.m4')
     32 
     33 changecom(blah)
     34 
     35 C	     cycles/bit (approx)
     36 C Cortex-A35	 ?
     37 C Cortex-A53	 7.26
     38 C Cortex-A55	 ?
     39 C Cortex-A57	 ?
     40 C Cortex-A72	 5.72
     41 C Cortex-A73	 6.43
     42 C Cortex-A75	 ?
     43 C Cortex-A76	 ?
     44 C Cortex-A77	 ?
     45 
     46 
     47 define(`u1',    `x0')
     48 define(`u0',    `x1')
     49 define(`v1',    `x2')
     50 define(`v0',    `x3')
     51 
     52 define(`t0',    `x5')
     53 define(`t1',    `x6')
     54 define(`cnt',   `x7')
     55 define(`tnc',   `x8')
     56 
     57 ASM_START()
     58 PROLOGUE(mpn_gcd_22)
     59 
     60 	ALIGN(16)
     61 L(top):	subs	t0, u0, v0		C 0 6
     62 	cbz	t0, L(lowz)
     63 	sbcs	t1, u1, v1		C 1 7
     64 
     65 	rbit	cnt, t0			C 1
     66 
     67 	cneg	t0, t0, cc		C 2
     68 	cinv	t1, t1, cc		C 2 u = |u - v|
     69 L(bck):	csel	v0, v0, u0, cs		C 2
     70 	csel	v1, v1, u1, cs		C 2 v = min(u,v)
     71 
     72 	clz	cnt, cnt		C 2
     73 	sub	tnc, xzr, cnt		C 3
     74 
     75 	lsr	u0, t0, cnt		C 3
     76 	lsl	x14, t1, tnc		C 4
     77 	lsr	u1, t1, cnt		C 3
     78 	orr	u0, u0, x14		C 5
     79 
     80 	orr	x11, u1, v1
     81 	cbnz	x11, L(top)
     82 
     83 
     84 	subs	x4, u0, v0		C			0
     85 	b.eq	L(end1)			C
     86 
     87 	ALIGN(16)
     88 L(top1):rbit	x12, x4			C			1,5
     89 	clz	x12, x12		C			2
     90 	csneg	x4, x4, x4, cs		C v = abs(u-v), even	1
     91 	csel	u0, v0, u0, cs		C u = min(u,v)		1
     92 	lsr	v0, x4, x12		C			3
     93 	subs	x4, u0, v0		C			4
     94 	b.ne	L(top1)			C
     95 L(end1):mov	x0, u0
     96 	mov	x1, #0
     97 	ret
     98 
     99 L(lowz):C We come here when v0 - u0 = 0
    100 	C 1. If v1 - u1 = 0, then gcd is u = v.
    101 	C 2. Else compute gcd_21({v1,v0}, |u1-v1|)
    102 	subs	t0, u1, v1
    103 	b.eq	L(end)
    104 	mov	t1, #0
    105 	rbit	cnt, t0			C 1
    106 	cneg	t0, t0, cc		C 2
    107 	b	L(bck)			C FIXME: make conditional
    108 
    109 L(end):	mov	x0, v0
    110 	mov	x1, v1
    111 	ret
    112 EPILOGUE()
    113