Annotation of OpenXM_contrib/gmp/mpn/sparc32/v9/addmul_1.asm, Revision 1.1.1.2
1.1.1.2 ! ohara 1: dnl SPARC v9 32-bit mpn_addmul_1 -- Multiply a limb vector with a limb and add
! 2: dnl the result to a second limb vector.
1.1 maekawa 3:
1.1.1.2 ! ohara 4: dnl Copyright 1998, 2000, 2001 Free Software Foundation, Inc.
1.1 maekawa 5:
6: dnl This file is part of the GNU MP Library.
7:
8: dnl The GNU MP Library is free software; you can redistribute it and/or modify
9: dnl it under the terms of the GNU Lesser General Public License as published
10: dnl by the Free Software Foundation; either version 2.1 of the License, or (at
11: dnl your option) any later version.
12:
13: dnl The GNU MP Library is distributed in the hope that it will be useful, but
14: dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16: dnl License for more details.
17:
18: dnl You should have received a copy of the GNU Lesser General Public License
19: dnl along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20: dnl the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21: dnl MA 02111-1307, USA.
22:
23: include(`../config.m4')
24:
1.1.1.2 ! ohara 25: C Algorithm: We use two floating-point multiplies per limb product, with the
! 26: C invariant v operand split into two 16-bit pieces, and the u operand split
! 27: C into 32-bit pieces. We convert the two 48-bit products and transfer them to
! 28: C the integer unit.
! 29:
! 30: C Speed: 7 cycles/limb on UltraSPARC-1/2.
! 31:
! 32: C Possible optimizations:
! 33: C 1. Combine 32-bit memory operations into 64-bit operations. Since we're
! 34: C memory bandwidth limited, this could save 1.5 cycles/limb.
! 35: C 2. Unroll the inner loop. Since we already use alternate temporary areas,
! 36: C it is very straightforward to unroll, using an exit branch midways.
! 37: C Unrolling would allow deeper scheduling which could improve speed for L2
! 38: C cache case.
! 39: C 3. For mpn_mul_1: Use more alternating temp areas. The std'es and ldx'es
! 40: C aren't sufficiently apart-scheduled with just two temp areas.
! 41: C 4. Do some cross-jumping to save about 1/2 the code size.
! 42: C 5. Specialize for particular v values. If its upper 16 bits are zero, we
! 43: C could save many operations.
1.1 maekawa 44:
1.1.1.2 ! ohara 45: C INPUT PARAMETERS
! 46: C rp i0
! 47: C up i1
! 48: C n i2
! 49: C v i3
1.1 maekawa 50:
1.1.1.2 ! ohara 51: define(`FSIZE',224)
1.1 maekawa 52:
1.1.1.2 ! ohara 53: ASM_START()
1.1 maekawa 54: PROLOGUE(mpn_addmul_1)
1.1.1.2 ! ohara 55: add %sp, -FSIZE, %sp
! 56: sethi %hi(0xffff), %g1
! 57: srl %o3, 16, %g2
! 58: or %g1, %lo(0xffff), %g1
! 59: and %o3, %g1, %g1
! 60: stx %g1, [%sp+104]
! 61: stx %g2, [%sp+112]
! 62: ldd [%sp+104], %f6
! 63: ldd [%sp+112], %f8
! 64: fxtod %f6, %f6
! 65: fxtod %f8, %f8
! 66: ld [%sp+104], %f10 C zero f10
! 67:
! 68: mov 0, %g3 C cy = 0
! 69:
! 70: define(`fanop', `fitod %f18, %f0') C A quasi nop running in the FA pipe
! 71:
! 72: add %sp, 160, %o5 C point in scratch area
! 73: and %o5, -32, %o5 C align at 0 (mod 32) in scratch area
! 74:
! 75: subcc %o2, 1, %o2
! 76: ld [%o1], %f11 C read up[i]
! 77: add %o1, 4, %o1 C up++
! 78: bne,pt %icc, .L_two_or_more
! 79: fxtod %f10, %f2
! 80: .L_1: fmuld %f2, %f8, %f16
! 81: fmuld %f2, %f6, %f4
! 82: fdtox %f16, %f14
! 83: fdtox %f4, %f12
! 84: std %f14, [%o5+16]
! 85: std %f12, [%o5+24]
! 86: ldx [%o5+16], %g2 C p16
! 87: ldx [%o5+24], %g1 C p0
! 88: lduw [%o0], %g5 C read rp[i]
! 89: sllx %g2, 16, %g4 C (p16 << 16)
! 90: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 91: add %g5, %g4, %g4 C p += rp[i]
! 92: stw %g4, [%o0]
! 93: srlx %g4, 32, %g3 C new cy
! 94: mov %g3, %o0
! 95: retl
! 96: sub %sp, -FSIZE, %sp
! 97:
! 98: .align 16
! 99: .L_two_or_more:
! 100: subcc %o2, 1, %o2
! 101: ld [%o1], %f11 C read up[i]
! 102: fmuld %f2, %f8, %f16
! 103: fmuld %f2, %f6, %f4
! 104: add %o1, 4, %o1 C up++
! 105: bne,pt %icc, .L_three_or_more
! 106: fxtod %f10, %f2
! 107: .L_2: fdtox %f16, %f14
! 108: fdtox %f4, %f12
! 109: std %f14, [%o5+16]
! 110: fmuld %f2, %f8, %f16
! 111: std %f12, [%o5+24]
! 112: fmuld %f2, %f6, %f4
! 113: fdtox %f16, %f14
! 114: fdtox %f4, %f12
! 115: std %f14, [%o5+0]
! 116: std %f12, [%o5+8]
! 117: lduw [%o0], %g5 C read rp[i]
! 118: ldx [%o5+16], %g2 C p16
! 119: ldx [%o5+24], %g1 C p0
! 120: sllx %g2, 16, %g4 C (p16 << 16) * crossjmp pt
! 121: ldx [%o5+0], %g2 C p16
! 122: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 123: ldx [%o5+8], %g1 C p0
! 124: add %g5, %g4, %g4 C p += rp[i]
! 125: stw %g4, [%o0+0]
! 126: srlx %g4, 32, %g3 C new cy
! 127: lduw [%o0+4], %g5 C read rp[i]
! 128: sllx %g2, 16, %g4 C (p16 << 16)
! 129: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 130: add %g3, %g4, %g4 C p += cy
! 131: add %g5, %g4, %g4 C p += rp[i]
! 132: stw %g4, [%o0+4]
! 133: srlx %g4, 32, %g3 C new cy
! 134: mov %g3, %o0
! 135: retl
! 136: sub %sp, -FSIZE, %sp
! 137:
! 138: .align 16
! 139: .L_three_or_more:
! 140: subcc %o2, 1, %o2
! 141: ld [%o1], %f11 C read up[i]
! 142: fdtox %f16, %f14
! 143: fdtox %f4, %f12
! 144: std %f14, [%o5+16]
! 145: fmuld %f2, %f8, %f16
! 146: std %f12, [%o5+24]
! 147: fmuld %f2, %f6, %f4
! 148: add %o1, 4, %o1 C up++
! 149: bne,pt %icc, .L_four_or_more
! 150: fxtod %f10, %f2
! 151: .L_3: fdtox %f16, %f14
! 152: fdtox %f4, %f12
! 153: std %f14, [%o5+0]
! 154: fmuld %f2, %f8, %f16
! 155: std %f12, [%o5+8]
! 156: fmuld %f2, %f6, %f4
! 157: fdtox %f16, %f14
! 158: ldx [%o5+16], %g2 C p16
! 159: fdtox %f4, %f12
! 160: ldx [%o5+24], %g1 C p0
! 161: std %f14, [%o5+16]
! 162: std %f12, [%o5+24]
! 163: lduw [%o0], %g5 C read rp[i]
! 164: sllx %g2, 16, %g4 C (p16 << 16)
! 165: ldx [%o5+0], %g2 C p16
! 166: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 167: ldx [%o5+8], %g1 C p0
! 168: add %g5, %g4, %g4 C p += rp[i]
! 169: stw %g4, [%o0+0]
! 170: srlx %g4, 32, %g3 C new cy
! 171: lduw [%o0+4], %g5 C read rp[i]
! 172: sllx %g2, 16, %g4 C (p16 << 16)
! 173: ldx [%o5+16], %g2 C p16
! 174: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 175: ldx [%o5+24], %g1 C p0
! 176: add %g3, %g4, %g4 C p += cy
! 177: add %g5, %g4, %g4 C p += rp[i]
! 178: stw %g4, [%o0+4]
! 179: srlx %g4, 32, %g3 C new cy
! 180: lduw [%o0+8], %g5 C read rp[i]
! 181: sllx %g2, 16, %g4 C (p16 << 16)
! 182: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 183: add %g3, %g4, %g4 C p += cy
! 184: add %g5, %g4, %g4 C p += rp[i]
! 185: stw %g4, [%o0+8]
! 186: srlx %g4, 32, %g3 C new cy
! 187: mov %g3, %o0
! 188: retl
! 189: sub %sp, -FSIZE, %sp
! 190:
! 191: .align 16
! 192: .L_four_or_more:
! 193: subcc %o2, 1, %o2
! 194: ld [%o1], %f11 C read up[i]
! 195: fdtox %f16, %f14
! 196: fdtox %f4, %f12
! 197: std %f14, [%o5+0]
! 198: fmuld %f2, %f8, %f16
! 199: std %f12, [%o5+8]
! 200: fmuld %f2, %f6, %f4
! 201: add %o1, 4, %o1 C up++
! 202: bne,pt %icc, .L_five_or_more
! 203: fxtod %f10, %f2
! 204: .L_4: fdtox %f16, %f14
! 205: ldx [%o5+16], %g2 C p16
! 206: fdtox %f4, %f12
! 207: ldx [%o5+24], %g1 C p0
! 208: std %f14, [%o5+16]
! 209: fmuld %f2, %f8, %f16
! 210: std %f12, [%o5+24]
! 211: fmuld %f2, %f6, %f4
! 212: add %o1, 4, %o1 C up++
! 213: lduw [%o0], %g5 C read rp[i]
! 214: fdtox %f16, %f14
! 215: sllx %g2, 16, %g4 C (p16 << 16)
! 216: ldx [%o5+0], %g2 C p16
! 217: fdtox %f4, %f12
! 218: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 219: ldx [%o5+8], %g1 C p0
! 220: std %f14, [%o5+0]
! 221: add %g5, %g4, %g4 C p += rp[i]
! 222: std %f12, [%o5+8]
! 223: stw %g4, [%o0+0]
! 224: srlx %g4, 32, %g3 C new cy
! 225: lduw [%o0+4], %g5 C read rp[i]
! 226: sllx %g2, 16, %g4 C (p16 << 16)
! 227: ldx [%o5+16], %g2 C p16
! 228: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 229: ldx [%o5+24], %g1 C p0
! 230: add %g3, %g4, %g4 C p += cy
! 231: add %g5, %g4, %g4 C p += rp[i]
! 232: stw %g4, [%o0+4]
! 233: srlx %g4, 32, %g3 C new cy
! 234: lduw [%o0+8], %g5 C read rp[i]
! 235: sllx %g2, 16, %g4 C (p16 << 16)
! 236: ldx [%o5+0], %g2 C p16
! 237: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 238: ldx [%o5+8], %g1 C p0
! 239: add %g3, %g4, %g4 C p += cy
! 240: add %g5, %g4, %g4 C p += rp[i]
! 241: stw %g4, [%o0+8]
! 242: srlx %g4, 32, %g3 C new cy
! 243: lduw [%o0+12], %g5 C read rp[i]
! 244: sllx %g2, 16, %g4 C (p16 << 16)
! 245: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 246: add %g3, %g4, %g4 C p += cy
! 247: add %g5, %g4, %g4 C p += rp[i]
! 248: stw %g4, [%o0+12]
! 249: srlx %g4, 32, %g3 C new cy
! 250: mov %g3, %o0
! 251: retl
! 252: sub %sp, -FSIZE, %sp
! 253:
! 254: .align 16
! 255: .L_five_or_more:
! 256: subcc %o2, 1, %o2
! 257: ld [%o1], %f11 C read up[i]
! 258: fdtox %f16, %f14
! 259: ldx [%o5+16], %g2 C p16
! 260: fdtox %f4, %f12
! 261: ldx [%o5+24], %g1 C p0
! 262: std %f14, [%o5+16]
! 263: fmuld %f2, %f8, %f16
! 264: std %f12, [%o5+24]
! 265: fmuld %f2, %f6, %f4
! 266: add %o1, 4, %o1 C up++
! 267: lduw [%o0], %g5 C read rp[i]
! 268: bne,pt %icc, .Loop
! 269: fxtod %f10, %f2
! 270: b,a .L_out_5
1.1 maekawa 271:
1.1.1.2 ! ohara 272: C BEGIN MAIN LOOP
1.1 maekawa 273: .align 16
1.1.1.2 ! ohara 274: C -- 0
! 275: .Loop: nop
! 276: subcc %o2, 1, %o2
! 277: ld [%o1], %f11 C read up[i]
! 278: fdtox %f16, %f14
! 279: C -- 1
! 280: sllx %g2, 16, %g4 C (p16 << 16)
! 281: add %o0, 4, %o0 C rp++
! 282: ldx [%o5+0], %g2 C p16
! 283: fdtox %f4, %f12
! 284: C -- 2
! 285: nop
! 286: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 287: ldx [%o5+8], %g1 C p0
! 288: fanop
! 289: C -- 3
! 290: nop
! 291: add %g3, %g4, %g4 C p += cy
! 292: std %f14, [%o5+0]
! 293: fmuld %f2, %f8, %f16
! 294: C -- 4
! 295: nop
! 296: add %g5, %g4, %g4 C p += rp[i]
! 297: std %f12, [%o5+8]
! 298: fmuld %f2, %f6, %f4
! 299: C -- 5
! 300: xor %o5, 16, %o5 C alternate scratch variables
! 301: add %o1, 4, %o1 C up++
! 302: stw %g4, [%o0-4]
! 303: fanop
! 304: C -- 6
! 305: srlx %g4, 32, %g3 C new cy
! 306: lduw [%o0], %g5 C read rp[i]
! 307: bne,pt %icc, .Loop
! 308: fxtod %f10, %f2
! 309: C END MAIN LOOP
! 310:
! 311:
! 312: .L_out_5:
! 313: fdtox %f16, %f14
! 314: sllx %g2, 16, %g4 C (p16 << 16)
! 315: ldx [%o5+0], %g2 C p16
! 316: fdtox %f4, %f12
! 317: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 318: ldx [%o5+8], %g1 C p0
! 319: add %g4, %g3, %g4 C p += cy
! 320: std %f14, [%o5+0]
! 321: fmuld %f2, %f8, %f16
! 322: add %g5, %g4, %g4 C p += rp[i]
! 323: std %f12, [%o5+8]
! 324: fmuld %f2, %f6, %f4
! 325: xor %o5, 16, %o5
! 326: stw %g4, [%o0+0]
! 327: srlx %g4, 32, %g3 C new cy
! 328: lduw [%o0+4], %g5 C read rp[i]
! 329:
! 330: fdtox %f16, %f14
! 331: sllx %g2, 16, %g4 C (p16 << 16)
! 332: ldx [%o5+0], %g2 C p16
! 333: fdtox %f4, %f12
! 334: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 335: ldx [%o5+8], %g1 C p0
! 336: add %g3, %g4, %g4 C p += cy
! 337: std %f14, [%o5+0]
! 338: add %g5, %g4, %g4 C p += rp[i]
! 339: std %f12, [%o5+8]
! 340: xor %o5, 16, %o5
! 341: stw %g4, [%o0+4]
! 342: srlx %g4, 32, %g3 C new cy
! 343: lduw [%o0+8], %g5 C read rp[i]
! 344:
! 345: sllx %g2, 16, %g4 C (p16 << 16)
! 346: ldx [%o5+0], %g2 C p16
! 347: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 348: ldx [%o5+8], %g1 C p0
! 349: add %g3, %g4, %g4 C p += cy
! 350: add %g5, %g4, %g4 C p += rp[i]
! 351: xor %o5, 16, %o5
! 352: stw %g4, [%o0+8]
! 353: srlx %g4, 32, %g3 C new cy
! 354: lduw [%o0+12], %g5 C read rp[i]
! 355:
! 356: sllx %g2, 16, %g4 C (p16 << 16)
! 357: ldx [%o5+0], %g2 C p16
! 358: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 359: ldx [%o5+8], %g1 C p0
! 360: add %g3, %g4, %g4 C p += cy
! 361: add %g5, %g4, %g4 C p += rp[i]
! 362: stw %g4, [%o0+12]
! 363: srlx %g4, 32, %g3 C new cy
! 364: lduw [%o0+16], %g5 C read rp[i]
! 365:
! 366: sllx %g2, 16, %g4 C (p16 << 16)
! 367: add %g1, %g4, %g4 C p = p0 + (p16 << 16)
! 368: add %g3, %g4, %g4 C p += cy
! 369: add %g5, %g4, %g4 C p += rp[i]
! 370: stw %g4, [%o0+16]
! 371: srlx %g4, 32, %g3 C new cy
! 372:
! 373: mov %g3, %o0
! 374: retl
! 375: sub %sp, -FSIZE, %sp
1.1 maekawa 376: EPILOGUE(mpn_addmul_1)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>