int64p.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2006 by the Free Pascal development team
  4. This file contains some helper routines for int64 and qword
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$ifndef FPC_SYSTEM_HAS_MUL_LONGINT_TO_INT64}
  12. {$define FPC_SYSTEM_HAS_MUL_LONGINT_TO_INT64}
  13. function fpc_mul_longint_to_int64(f1,f2 : longint) : int64;[public,alias: 'FPC_MUL_LONGINT_TO_INT64']; assembler; nostackframe; compilerproc;
  14. asm
  15. tst.l d0
  16. beq.s @xit0
  17. tst.l d1
  18. beq.s @xit0
  19. movem.l d2-d5,-(sp)
  20. move.l d0,d5
  21. eor.l d1,d5
  22. move.l d0,d2
  23. bpl.s @pos0
  24. neg.l d2
  25. neg.l d0
  26. @pos0:
  27. move.l d1,d4
  28. bpl.s @pos1
  29. neg.l d4
  30. neg.l d1
  31. @pos1:
  32. move.l d0,d3
  33. swap d4
  34. swap d3
  35. mulu.w d1,d0
  36. mulu.w d3,d1
  37. mulu.w d4,d2
  38. mulu.w d4,d3
  39. swap d0
  40. clr.l d4
  41. add.w d1,d0
  42. addx.l d4,d3
  43. add.w d2,d0
  44. addx.l d4,d3
  45. clr.w d1
  46. clr.w d2
  47. swap d1
  48. swap d2
  49. add.l d3,d1
  50. swap d0
  51. add.l d2,d1
  52. tst.l d5
  53. bpl.s @xit
  54. neg.l d0
  55. negx.l d1
  56. @xit:
  57. movem.l (sp)+,d2-d5
  58. exg.l d0,d1
  59. rts
  60. @xit0:
  61. clr.l d0
  62. clr.l d1
  63. end;
  64. {$endif FPC_SYSTEM_HAS_MUL_LONGINT_TO_INT64}