/*1* Copyright (C) 1999-2000 Hewlett-Packard Co2* Copyright (C) 1999-2000 David Mosberger-Tang <[email protected]>3*4* 64-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 INT_TO_FP(a,b) fcvt.xuf.s1 a=b27# define FP_TO_INT(a,b) fcvt.fxu.trunc.s1 a=b28#else29# define SGN30# define INT_TO_FP(a,b) fcvt.xf a=b31# define FP_TO_INT(a,b) fcvt.fx.trunc.s1 a=b32#endif3334#define PASTE1(a,b) a##b35#define PASTE(a,b) PASTE1(a,b)36#define NAME PASTE(PASTE(__,SGN),PASTE(OP,di3))3738GLOBAL_ENTRY(NAME)39.regstk 2,0,0,040// Transfer inputs to FP registers.41setf.sig f8 = in042setf.sig f9 = in143;;44// Convert the inputs to FP, to avoid FP software-assist faults.45INT_TO_FP(f8, f8)46INT_TO_FP(f9, f9)47;;48frcpa.s1 f11, p6 = f8, f9 // y0 = frcpa(b)49;;50(p6) fmpy.s1 f7 = f8, f11 // q0 = a*y051(p6) fnma.s1 f6 = f9, f11, f1 // e0 = -b*y0 + 152;;53(p6) fma.s1 f10 = f7, f6, f7 // q1 = q0*e0 + q054(p6) fmpy.s1 f7 = f6, f6 // e1 = e0*e055;;56#ifdef MODULO57sub in1 = r0, in1 // in1 = -b58#endif59(p6) fma.s1 f10 = f10, f7, f10 // q2 = q1*e1 + q160(p6) fma.s1 f6 = f11, f6, f11 // y1 = y0*e0 + y061;;62(p6) fma.s1 f6 = f6, f7, f6 // y2 = y1*e1 + y163(p6) fnma.s1 f7 = f9, f10, f8 // r = -b*q2 + a64;;65#ifdef MODULO66setf.sig f8 = in0 // f8 = a67setf.sig f9 = in1 // f9 = -b68#endif69(p6) fma.s1 f11 = f7, f6, f10 // q3 = r*y2 + q270;;71FP_TO_INT(f11, f11) // q = trunc(q3)72;;73#ifdef MODULO74xma.l f11 = f11, f9, f8 // r = q*(-b) + a75;;76#endif77getf.sig r8 = f11 // transfer result to result register78br.ret.sptk.many rp79END(NAME)808182