idiv64.S 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (C) 1999-2000 Hewlett-Packard Co
  3. * Copyright (C) 1999-2000 David Mosberger-Tang <davidm@hpl.hp.com>
  4. *
  5. * 64-bit integer division.
  6. *
  7. * This code is based on the application note entitled "Divide, Square Root
  8. * and Remainder Algorithms for the IA-64 Architecture". This document
  9. * is available as Intel document number 248725-002 or via the web at
  10. * http://developer.intel.com/software/opensource/numerics/
  11. *
  12. * For more details on the theory behind these algorithms, see "IA-64
  13. * and Elementary Functions" by Peter Markstein; HP Professional Books
  14. * (http://www.goodreads.com/book/show/2019887.Ia_64_and_Elementary_Functions)
  15. */
  16. #include <asm/asmmacro.h>
  17. #include <asm/export.h>
  18. #ifdef MODULO
  19. # define OP mod
  20. #else
  21. # define OP div
  22. #endif
  23. #ifdef UNSIGNED
  24. # define SGN u
  25. # define INT_TO_FP(a,b) fcvt.xuf.s1 a=b
  26. # define FP_TO_INT(a,b) fcvt.fxu.trunc.s1 a=b
  27. #else
  28. # define SGN
  29. # define INT_TO_FP(a,b) fcvt.xf a=b
  30. # define FP_TO_INT(a,b) fcvt.fx.trunc.s1 a=b
  31. #endif
  32. #define PASTE1(a,b) a##b
  33. #define PASTE(a,b) PASTE1(a,b)
  34. #define NAME PASTE(PASTE(__,SGN),PASTE(OP,di3))
  35. GLOBAL_ENTRY(NAME)
  36. .regstk 2,0,0,0
  37. // Transfer inputs to FP registers.
  38. setf.sig f8 = in0
  39. setf.sig f9 = in1
  40. ;;
  41. // Convert the inputs to FP, to avoid FP software-assist faults.
  42. INT_TO_FP(f8, f8)
  43. INT_TO_FP(f9, f9)
  44. ;;
  45. frcpa.s1 f11, p6 = f8, f9 // y0 = frcpa(b)
  46. ;;
  47. (p6) fmpy.s1 f7 = f8, f11 // q0 = a*y0
  48. (p6) fnma.s1 f6 = f9, f11, f1 // e0 = -b*y0 + 1
  49. ;;
  50. (p6) fma.s1 f10 = f7, f6, f7 // q1 = q0*e0 + q0
  51. (p6) fmpy.s1 f7 = f6, f6 // e1 = e0*e0
  52. ;;
  53. #ifdef MODULO
  54. sub in1 = r0, in1 // in1 = -b
  55. #endif
  56. (p6) fma.s1 f10 = f10, f7, f10 // q2 = q1*e1 + q1
  57. (p6) fma.s1 f6 = f11, f6, f11 // y1 = y0*e0 + y0
  58. ;;
  59. (p6) fma.s1 f6 = f6, f7, f6 // y2 = y1*e1 + y1
  60. (p6) fnma.s1 f7 = f9, f10, f8 // r = -b*q2 + a
  61. ;;
  62. #ifdef MODULO
  63. setf.sig f8 = in0 // f8 = a
  64. setf.sig f9 = in1 // f9 = -b
  65. #endif
  66. (p6) fma.s1 f11 = f7, f6, f10 // q3 = r*y2 + q2
  67. ;;
  68. FP_TO_INT(f11, f11) // q = trunc(q3)
  69. ;;
  70. #ifdef MODULO
  71. xma.l f11 = f11, f9, f8 // r = q*(-b) + a
  72. ;;
  73. #endif
  74. getf.sig r8 = f11 // transfer result to result register
  75. br.ret.sptk.many rp
  76. END(NAME)
  77. EXPORT_SYMBOL(NAME)