int64p.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 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. {$if (not defined(CPUTHUMB)) and defined(CPUARM_HAS_UMULL)}
  12. {$define FPC_SYSTEM_HAS_MUL_QWORD}
  13. function fpc_mul_qword(f1,f2 : qword) : qword;assembler;nostackframe;[public,alias: 'FPC_MUL_QWORD']; compilerproc;
  14. asm
  15. stmfd sp!,{r4,r5,r6,r14}
  16. mov r6,#0
  17. // r4 = result lo, r5 = result hi
  18. {$ifdef ENDIAN_LITTLE}
  19. // lo(f1)*lo(f2)
  20. umull r4,r5,r0,r2
  21. // lo(f1)*hi(f2)
  22. umlal r5,r6,r0,r3
  23. // hi(f1)*lo(f2)
  24. umlal r5,r6,r1,r2
  25. mov r0,r4
  26. mov r1,r5
  27. {$else}
  28. // lo(f1)*lo(f2)
  29. umull r4,r5,r1,r3
  30. // lo(f1)*hi(f2)
  31. umlal r5,r6,r1,r2
  32. // hi(f1)*lo(f2)
  33. umlal r5,r6,r0,r3
  34. mov r1,r4
  35. mov r0,r5
  36. {$endif}
  37. ldmfd sp!,{r4,r5,r6,r15}
  38. end;
  39. function fpc_mul_qword_checkoverflow(f1,f2 : qword) : qword;assembler;nostackframe;[public,alias: 'FPC_MUL_QWORD_CHECKOVERFLOW']; compilerproc;
  40. asm
  41. stmfd sp!,{r4,r5,r6,r14}
  42. mov r6,#0
  43. // r4 = result lo, r5 = result hi
  44. {$ifdef ENDIAN_LITTLE}
  45. // lo(f1)*lo(f2)
  46. umull r4,r5,r0,r2
  47. // lo(f1)*hi(f2)
  48. umlal r5,r6,r0,r3
  49. // overflow?
  50. // hi(f1)*hi(f2)
  51. mul r0,r1,r3
  52. // hi(f1)*lo(f2)
  53. umlal r5,r6,r1,r2
  54. // check for overflow
  55. orrs r6,r6,r0
  56. mov r0,r4
  57. mov r1,r5
  58. {$else}
  59. // lo(f1)*lo(f2)
  60. umull r4,r5,r1,r3
  61. // lo(f1)*hi(f2)
  62. umlal r5,r6,r1,r2
  63. // overflow?
  64. // hi(f1)*hi(f2)
  65. mul r1,r0,r2
  66. // hi(f1)*lo(f2)
  67. umlal r5,r6,r0,r3
  68. // check for overflow
  69. orrs r6,r6,r1
  70. mov r1,r4
  71. mov r0,r5
  72. {$endif}
  73. // no overflow?
  74. beq .Lexit
  75. mov r0,#215
  76. mov r1,fp
  77. bl HandleErrorFrame
  78. .Lexit:
  79. ldmfd sp!,{r4,r5,r6,r15}
  80. end;
  81. {$endif (not defined(CPUTHUMB)) and defined(CPUARM_HAS_UMULL)}