1*1da177e4SLinus Torvalds/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 2*1da177e4SLinus Torvalds 3*1da177e4SLinus TorvaldsThis file is part of GNU CC. 4*1da177e4SLinus Torvalds 5*1da177e4SLinus TorvaldsGNU CC is free software; you can redistribute it and/or modify 6*1da177e4SLinus Torvaldsit under the terms of the GNU General Public License as published by 7*1da177e4SLinus Torvaldsthe Free Software Foundation; either version 2, or (at your option) 8*1da177e4SLinus Torvaldsany later version. 9*1da177e4SLinus Torvalds 10*1da177e4SLinus TorvaldsGNU CC is distributed in the hope that it will be useful, 11*1da177e4SLinus Torvaldsbut WITHOUT ANY WARRANTY; without even the implied warranty of 12*1da177e4SLinus TorvaldsMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*1da177e4SLinus TorvaldsGNU General Public License for more details. 14*1da177e4SLinus Torvalds 15*1da177e4SLinus TorvaldsYou should have received a copy of the GNU General Public License 16*1da177e4SLinus Torvaldsalong with GNU CC; see the file COPYING. If not, write to 17*1da177e4SLinus Torvaldsthe Free Software Foundation, 59 Temple Place - Suite 330, 18*1da177e4SLinus TorvaldsBoston, MA 02111-1307, USA. */ 19*1da177e4SLinus Torvalds 20*1da177e4SLinus Torvalds .data 21*1da177e4SLinus Torvalds .align 8 22*1da177e4SLinus Torvalds .globl __clz_tab 23*1da177e4SLinus Torvalds__clz_tab: 24*1da177e4SLinus Torvalds .byte 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5 25*1da177e4SLinus Torvalds .byte 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6 26*1da177e4SLinus Torvalds .byte 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 27*1da177e4SLinus Torvalds .byte 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 28*1da177e4SLinus Torvalds .byte 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 29*1da177e4SLinus Torvalds .byte 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 30*1da177e4SLinus Torvalds .byte 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 31*1da177e4SLinus Torvalds .byte 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 32*1da177e4SLinus Torvalds .size __clz_tab,256 33*1da177e4SLinus Torvalds .global .udiv 34*1da177e4SLinus Torvalds 35*1da177e4SLinus Torvalds .text 36*1da177e4SLinus Torvalds .align 4 37*1da177e4SLinus Torvalds .globl __divdi3 38*1da177e4SLinus Torvalds__divdi3: 39*1da177e4SLinus Torvalds save %sp,-104,%sp 40*1da177e4SLinus Torvalds cmp %i0,0 41*1da177e4SLinus Torvalds bge .LL40 42*1da177e4SLinus Torvalds mov 0,%l4 43*1da177e4SLinus Torvalds mov -1,%l4 44*1da177e4SLinus Torvalds sub %g0,%i1,%o0 45*1da177e4SLinus Torvalds mov %o0,%o5 46*1da177e4SLinus Torvalds subcc %g0,%o0,%g0 47*1da177e4SLinus Torvalds sub %g0,%i0,%o0 48*1da177e4SLinus Torvalds subx %o0,0,%o4 49*1da177e4SLinus Torvalds mov %o4,%i0 50*1da177e4SLinus Torvalds mov %o5,%i1 51*1da177e4SLinus Torvalds.LL40: 52*1da177e4SLinus Torvalds cmp %i2,0 53*1da177e4SLinus Torvalds bge .LL84 54*1da177e4SLinus Torvalds mov %i3,%o4 55*1da177e4SLinus Torvalds xnor %g0,%l4,%l4 56*1da177e4SLinus Torvalds sub %g0,%i3,%o0 57*1da177e4SLinus Torvalds mov %o0,%o3 58*1da177e4SLinus Torvalds subcc %g0,%o0,%g0 59*1da177e4SLinus Torvalds sub %g0,%i2,%o0 60*1da177e4SLinus Torvalds subx %o0,0,%o2 61*1da177e4SLinus Torvalds mov %o2,%i2 62*1da177e4SLinus Torvalds mov %o3,%i3 63*1da177e4SLinus Torvalds mov %i3,%o4 64*1da177e4SLinus Torvalds.LL84: 65*1da177e4SLinus Torvalds cmp %i2,0 66*1da177e4SLinus Torvalds bne .LL45 67*1da177e4SLinus Torvalds mov %i1,%i3 68*1da177e4SLinus Torvalds cmp %o4,%i0 69*1da177e4SLinus Torvalds bleu .LL46 70*1da177e4SLinus Torvalds mov %i3,%o1 71*1da177e4SLinus Torvalds mov 32,%g1 72*1da177e4SLinus Torvalds subcc %i0,%o4,%g0 73*1da177e4SLinus Torvalds1: bcs 5f 74*1da177e4SLinus Torvalds addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb 75*1da177e4SLinus Torvalds sub %i0,%o4,%i0 ! this kills msb of n 76*1da177e4SLinus Torvalds addx %i0,%i0,%i0 ! so this cannot give carry 77*1da177e4SLinus Torvalds subcc %g1,1,%g1 78*1da177e4SLinus Torvalds2: bne 1b 79*1da177e4SLinus Torvalds subcc %i0,%o4,%g0 80*1da177e4SLinus Torvalds bcs 3f 81*1da177e4SLinus Torvalds addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb 82*1da177e4SLinus Torvalds b 3f 83*1da177e4SLinus Torvalds sub %i0,%o4,%i0 ! this kills msb of n 84*1da177e4SLinus Torvalds4: sub %i0,%o4,%i0 85*1da177e4SLinus Torvalds5: addxcc %i0,%i0,%i0 86*1da177e4SLinus Torvalds bcc 2b 87*1da177e4SLinus Torvalds subcc %g1,1,%g1 88*1da177e4SLinus Torvalds! Got carry from n. Subtract next step to cancel this carry. 89*1da177e4SLinus Torvalds bne 4b 90*1da177e4SLinus Torvalds addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb 91*1da177e4SLinus Torvalds sub %i0,%o4,%i0 92*1da177e4SLinus Torvalds3: xnor %o1,0,%o1 93*1da177e4SLinus Torvalds b .LL50 94*1da177e4SLinus Torvalds mov 0,%o2 95*1da177e4SLinus Torvalds.LL46: 96*1da177e4SLinus Torvalds cmp %o4,0 97*1da177e4SLinus Torvalds bne .LL85 98*1da177e4SLinus Torvalds mov %i0,%o2 99*1da177e4SLinus Torvalds mov 1,%o0 100*1da177e4SLinus Torvalds call .udiv,0 101*1da177e4SLinus Torvalds mov 0,%o1 102*1da177e4SLinus Torvalds mov %o0,%o4 103*1da177e4SLinus Torvalds mov %i0,%o2 104*1da177e4SLinus Torvalds.LL85: 105*1da177e4SLinus Torvalds mov 0,%g3 106*1da177e4SLinus Torvalds mov 32,%g1 107*1da177e4SLinus Torvalds subcc %g3,%o4,%g0 108*1da177e4SLinus Torvalds1: bcs 5f 109*1da177e4SLinus Torvalds addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb 110*1da177e4SLinus Torvalds sub %g3,%o4,%g3 ! this kills msb of n 111*1da177e4SLinus Torvalds addx %g3,%g3,%g3 ! so this cannot give carry 112*1da177e4SLinus Torvalds subcc %g1,1,%g1 113*1da177e4SLinus Torvalds2: bne 1b 114*1da177e4SLinus Torvalds subcc %g3,%o4,%g0 115*1da177e4SLinus Torvalds bcs 3f 116*1da177e4SLinus Torvalds addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb 117*1da177e4SLinus Torvalds b 3f 118*1da177e4SLinus Torvalds sub %g3,%o4,%g3 ! this kills msb of n 119*1da177e4SLinus Torvalds4: sub %g3,%o4,%g3 120*1da177e4SLinus Torvalds5: addxcc %g3,%g3,%g3 121*1da177e4SLinus Torvalds bcc 2b 122*1da177e4SLinus Torvalds subcc %g1,1,%g1 123*1da177e4SLinus Torvalds! Got carry from n. Subtract next step to cancel this carry. 124*1da177e4SLinus Torvalds bne 4b 125*1da177e4SLinus Torvalds addcc %o2,%o2,%o2 ! shift n1n0 and a 0-bit in lsb 126*1da177e4SLinus Torvalds sub %g3,%o4,%g3 127*1da177e4SLinus Torvalds3: xnor %o2,0,%o2 128*1da177e4SLinus Torvalds mov %g3,%i0 129*1da177e4SLinus Torvalds mov %i3,%o1 130*1da177e4SLinus Torvalds mov 32,%g1 131*1da177e4SLinus Torvalds subcc %i0,%o4,%g0 132*1da177e4SLinus Torvalds1: bcs 5f 133*1da177e4SLinus Torvalds addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb 134*1da177e4SLinus Torvalds sub %i0,%o4,%i0 ! this kills msb of n 135*1da177e4SLinus Torvalds addx %i0,%i0,%i0 ! so this cannot give carry 136*1da177e4SLinus Torvalds subcc %g1,1,%g1 137*1da177e4SLinus Torvalds2: bne 1b 138*1da177e4SLinus Torvalds subcc %i0,%o4,%g0 139*1da177e4SLinus Torvalds bcs 3f 140*1da177e4SLinus Torvalds addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb 141*1da177e4SLinus Torvalds b 3f 142*1da177e4SLinus Torvalds sub %i0,%o4,%i0 ! this kills msb of n 143*1da177e4SLinus Torvalds4: sub %i0,%o4,%i0 144*1da177e4SLinus Torvalds5: addxcc %i0,%i0,%i0 145*1da177e4SLinus Torvalds bcc 2b 146*1da177e4SLinus Torvalds subcc %g1,1,%g1 147*1da177e4SLinus Torvalds! Got carry from n. Subtract next step to cancel this carry. 148*1da177e4SLinus Torvalds bne 4b 149*1da177e4SLinus Torvalds addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb 150*1da177e4SLinus Torvalds sub %i0,%o4,%i0 151*1da177e4SLinus Torvalds3: xnor %o1,0,%o1 152*1da177e4SLinus Torvalds b .LL86 153*1da177e4SLinus Torvalds mov %o1,%l1 154*1da177e4SLinus Torvalds.LL45: 155*1da177e4SLinus Torvalds cmp %i2,%i0 156*1da177e4SLinus Torvalds bleu .LL51 157*1da177e4SLinus Torvalds sethi %hi(65535),%o0 158*1da177e4SLinus Torvalds b .LL78 159*1da177e4SLinus Torvalds mov 0,%o1 160*1da177e4SLinus Torvalds.LL51: 161*1da177e4SLinus Torvalds or %o0,%lo(65535),%o0 162*1da177e4SLinus Torvalds cmp %i2,%o0 163*1da177e4SLinus Torvalds bgu .LL58 164*1da177e4SLinus Torvalds mov %i2,%o1 165*1da177e4SLinus Torvalds cmp %i2,256 166*1da177e4SLinus Torvalds addx %g0,-1,%o0 167*1da177e4SLinus Torvalds b .LL64 168*1da177e4SLinus Torvalds and %o0,8,%o2 169*1da177e4SLinus Torvalds.LL58: 170*1da177e4SLinus Torvalds sethi %hi(16777215),%o0 171*1da177e4SLinus Torvalds or %o0,%lo(16777215),%o0 172*1da177e4SLinus Torvalds cmp %i2,%o0 173*1da177e4SLinus Torvalds bgu .LL64 174*1da177e4SLinus Torvalds mov 24,%o2 175*1da177e4SLinus Torvalds mov 16,%o2 176*1da177e4SLinus Torvalds.LL64: 177*1da177e4SLinus Torvalds srl %o1,%o2,%o0 178*1da177e4SLinus Torvalds sethi %hi(__clz_tab),%o1 179*1da177e4SLinus Torvalds or %o1,%lo(__clz_tab),%o1 180*1da177e4SLinus Torvalds ldub [%o0+%o1],%o0 181*1da177e4SLinus Torvalds add %o0,%o2,%o0 182*1da177e4SLinus Torvalds mov 32,%o1 183*1da177e4SLinus Torvalds subcc %o1,%o0,%o3 184*1da177e4SLinus Torvalds bne,a .LL72 185*1da177e4SLinus Torvalds sub %o1,%o3,%o1 186*1da177e4SLinus Torvalds cmp %i0,%i2 187*1da177e4SLinus Torvalds bgu .LL74 188*1da177e4SLinus Torvalds cmp %i3,%o4 189*1da177e4SLinus Torvalds blu .LL78 190*1da177e4SLinus Torvalds mov 0,%o1 191*1da177e4SLinus Torvalds.LL74: 192*1da177e4SLinus Torvalds b .LL78 193*1da177e4SLinus Torvalds mov 1,%o1 194*1da177e4SLinus Torvalds.LL72: 195*1da177e4SLinus Torvalds sll %i2,%o3,%o2 196*1da177e4SLinus Torvalds srl %o4,%o1,%o0 197*1da177e4SLinus Torvalds or %o2,%o0,%i2 198*1da177e4SLinus Torvalds sll %o4,%o3,%o4 199*1da177e4SLinus Torvalds srl %i0,%o1,%o2 200*1da177e4SLinus Torvalds sll %i0,%o3,%o0 201*1da177e4SLinus Torvalds srl %i3,%o1,%o1 202*1da177e4SLinus Torvalds or %o0,%o1,%i0 203*1da177e4SLinus Torvalds sll %i3,%o3,%i3 204*1da177e4SLinus Torvalds mov %i0,%o1 205*1da177e4SLinus Torvalds mov 32,%g1 206*1da177e4SLinus Torvalds subcc %o2,%i2,%g0 207*1da177e4SLinus Torvalds1: bcs 5f 208*1da177e4SLinus Torvalds addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb 209*1da177e4SLinus Torvalds sub %o2,%i2,%o2 ! this kills msb of n 210*1da177e4SLinus Torvalds addx %o2,%o2,%o2 ! so this cannot give carry 211*1da177e4SLinus Torvalds subcc %g1,1,%g1 212*1da177e4SLinus Torvalds2: bne 1b 213*1da177e4SLinus Torvalds subcc %o2,%i2,%g0 214*1da177e4SLinus Torvalds bcs 3f 215*1da177e4SLinus Torvalds addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb 216*1da177e4SLinus Torvalds b 3f 217*1da177e4SLinus Torvalds sub %o2,%i2,%o2 ! this kills msb of n 218*1da177e4SLinus Torvalds4: sub %o2,%i2,%o2 219*1da177e4SLinus Torvalds5: addxcc %o2,%o2,%o2 220*1da177e4SLinus Torvalds bcc 2b 221*1da177e4SLinus Torvalds subcc %g1,1,%g1 222*1da177e4SLinus Torvalds! Got carry from n. Subtract next step to cancel this carry. 223*1da177e4SLinus Torvalds bne 4b 224*1da177e4SLinus Torvalds addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb 225*1da177e4SLinus Torvalds sub %o2,%i2,%o2 226*1da177e4SLinus Torvalds3: xnor %o1,0,%o1 227*1da177e4SLinus Torvalds mov %o2,%i0 228*1da177e4SLinus Torvalds wr %g0,%o1,%y ! SPARC has 0-3 delay insn after a wr 229*1da177e4SLinus Torvalds sra %o4,31,%g2 ! Do not move this insn 230*1da177e4SLinus Torvalds and %o1,%g2,%g2 ! Do not move this insn 231*1da177e4SLinus Torvalds andcc %g0,0,%g1 ! Do not move this insn 232*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 233*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 234*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 235*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 236*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 237*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 238*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 239*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 240*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 241*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 242*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 243*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 244*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 245*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 246*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 247*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 248*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 249*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 250*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 251*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 252*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 253*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 254*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 255*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 256*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 257*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 258*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 259*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 260*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 261*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 262*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 263*1da177e4SLinus Torvalds mulscc %g1,%o4,%g1 264*1da177e4SLinus Torvalds mulscc %g1,0,%g1 265*1da177e4SLinus Torvalds add %g1,%g2,%o0 266*1da177e4SLinus Torvalds rd %y,%o2 267*1da177e4SLinus Torvalds cmp %o0,%i0 268*1da177e4SLinus Torvalds bgu,a .LL78 269*1da177e4SLinus Torvalds add %o1,-1,%o1 270*1da177e4SLinus Torvalds bne,a .LL50 271*1da177e4SLinus Torvalds mov 0,%o2 272*1da177e4SLinus Torvalds cmp %o2,%i3 273*1da177e4SLinus Torvalds bleu .LL50 274*1da177e4SLinus Torvalds mov 0,%o2 275*1da177e4SLinus Torvalds add %o1,-1,%o1 276*1da177e4SLinus Torvalds.LL78: 277*1da177e4SLinus Torvalds mov 0,%o2 278*1da177e4SLinus Torvalds.LL50: 279*1da177e4SLinus Torvalds mov %o1,%l1 280*1da177e4SLinus Torvalds.LL86: 281*1da177e4SLinus Torvalds mov %o2,%l0 282*1da177e4SLinus Torvalds mov %l0,%i0 283*1da177e4SLinus Torvalds mov %l1,%i1 284*1da177e4SLinus Torvalds cmp %l4,0 285*1da177e4SLinus Torvalds be .LL81 286*1da177e4SLinus Torvalds sub %g0,%i1,%o0 287*1da177e4SLinus Torvalds mov %o0,%l3 288*1da177e4SLinus Torvalds subcc %g0,%o0,%g0 289*1da177e4SLinus Torvalds sub %g0,%i0,%o0 290*1da177e4SLinus Torvalds subx %o0,0,%l2 291*1da177e4SLinus Torvalds mov %l2,%i0 292*1da177e4SLinus Torvalds mov %l3,%i1 293*1da177e4SLinus Torvalds.LL81: 294*1da177e4SLinus Torvalds ret 295*1da177e4SLinus Torvalds restore 296