int64p.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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;checkoverflow : longbool) : 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. // overflow?
  24. // hi(f1)*hi(f2)
  25. mul r0,r1,r3
  26. // hi(f1)*lo(f2)
  27. umlal r5,r6,r1,r2
  28. // check for overflow
  29. orrs r6,r6,r0
  30. mov r0,r4
  31. mov r1,r5
  32. {$else}
  33. // lo(f1)*lo(f2)
  34. umull r4,r5,r1,r3
  35. // lo(f1)*hi(f2)
  36. umlal r5,r6,r1,r2
  37. // overflow?
  38. // hi(f1)*hi(f2)
  39. mul r1,r0,r2
  40. // hi(f1)*lo(f2)
  41. umlal r5,r6,r0,r3
  42. // check for overflow
  43. orrs r6,r6,r1
  44. mov r1,r4
  45. mov r0,r5
  46. {$endif}
  47. // no overflow?
  48. beq .Lexit
  49. // checkoverflow?
  50. ldr r2,[sp,#16]
  51. cmp r2,#0
  52. beq .Lexit
  53. mov r0,#215
  54. mov r1,fp
  55. bl HandleErrorFrame
  56. .Lexit:
  57. ldmfd sp!,{r4,r5,r6,r15}
  58. end;
  59. {$endif (not defined(CPUTHUMB)) and defined(CPUARM_HAS_UMULL)}