/*1* Copyright (C) 2000 Hewlett-Packard Co2* Copyright (C) 2000 David Mosberger-Tang <[email protected]>3*4* 32-bit integer division.5*6* This code is based on the application note entitled "Divide, Square Root7* and Remainder Algorithms for the IA-64 Architecture". This document8* is available as Intel document number 248725-002 or via the web at9* http://developer.intel.com/software/opensource/numerics/10*11* For more details on the theory behind these algorithms, see "IA-6412* and Elementary Functions" by Peter Markstein; HP Professional Books13* (http://www.hp.com/go/retailbooks/)14*/1516#include <asm/asmmacro.h>1718#ifdef MODULO19# define OP mod20#else21# define OP div22#endif2324#ifdef UNSIGNED25# define SGN u26# define EXTEND zxt427# define INT_TO_FP(a,b) fcvt.xuf.s1 a=b28# define FP_TO_INT(a,b) fcvt.fxu.trunc.s1 a=b29#else30# define SGN31# define EXTEND sxt432# define INT_TO_FP(a,b) fcvt.xf a=b33# define FP_TO_INT(a,b) fcvt.fx.trunc.s1 a=b34#endif3536#define PASTE1(a,b) a##b37#define PASTE(a,b) PASTE1(a,b)38#define NAME PASTE(PASTE(__,SGN),PASTE(OP,si3))3940GLOBAL_ENTRY(NAME)41.regstk 2,0,0,042// Transfer inputs to FP registers.43mov r2 = 0xffdd // r2 = -34 + 65535 (fp reg format bias)44EXTEND in0 = in0 // in0 = a45EXTEND in1 = in1 // in1 = b46;;47setf.sig f8 = in048setf.sig f9 = in149#ifdef MODULO50sub in1 = r0, in1 // in1 = -b51#endif52;;53// Convert the inputs to FP, to avoid FP software-assist faults.54INT_TO_FP(f8, f8)55INT_TO_FP(f9, f9)56;;57setf.exp f7 = r2 // f7 = 2^-3458frcpa.s1 f6, p6 = f8, f9 // y0 = frcpa(b)59;;60(p6) fmpy.s1 f8 = f8, f6 // q0 = a*y061(p6) fnma.s1 f6 = f9, f6, f1 // e0 = -b*y0 + 162;;63#ifdef MODULO64setf.sig f9 = in1 // f9 = -b65#endif66(p6) fma.s1 f8 = f6, f8, f8 // q1 = e0*q0 + q067(p6) fma.s1 f6 = f6, f6, f7 // e1 = e0*e0 + 2^-3468;;69#ifdef MODULO70setf.sig f7 = in071#endif72(p6) fma.s1 f6 = f6, f8, f8 // q2 = e1*q1 + q173;;74FP_TO_INT(f6, f6) // q = trunc(q2)75;;76#ifdef MODULO77xma.l f6 = f6, f9, f7 // r = q*(-b) + a78;;79#endif80getf.sig r8 = f6 // transfer result to result register81br.ret.sptk.many rp82END(NAME)838485