int64p.inc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. {$define FPC_SYSTEM_HAS_MUL_QWORD}
  12. function fpc_mul_qword(f1,f2 : qword;checkoverflow : longbool) : qword;assembler;nostackframe;[public,alias: 'FPC_MUL_QWORD']; compilerproc;
  13. asm
  14. stmfd sp!,{r4,r5,r6,r14}
  15. mov r6,#0
  16. // r4 = result lo, r5 = result hi
  17. {$ifdef ENDIAN_LITTLE}
  18. // lo(f1)*lo(f2)
  19. umull r4,r5,r0,r2
  20. // lo(f1)*hi(f2)
  21. umlal r5,r6,r0,r3
  22. // overflow?
  23. // hi(f1)*hi(f2)
  24. mul r0,r1,r3
  25. // hi(f1)*lo(f2)
  26. umlal r5,r6,r1,r2
  27. // check for overflow
  28. orrs r6,r6,r0
  29. mov r0,r4
  30. mov r1,r5
  31. {$else}
  32. // lo(f1)*lo(f2)
  33. umull r4,r5,r1,r3
  34. // lo(f1)*hi(f2)
  35. umlal r5,r6,r1,r2
  36. // overflow?
  37. // hi(f1)*hi(f2)
  38. mul r1,r0,r2
  39. // hi(f1)*lo(f2)
  40. umlal r5,r6,r0,r3
  41. // check for overflow
  42. orrs r6,r6,r1
  43. mov r1,r4
  44. mov r0,r5
  45. {$endif}
  46. // no overflow?
  47. beq .Lexit
  48. // checkoverflow?
  49. ldr r2,[sp,#16]
  50. cmp r2,#0
  51. beq .Lexit
  52. mov r0,#215
  53. mov r1,fp
  54. bl HandleErrorFrame
  55. .Lexit:
  56. ldmfd sp!,{r4,r5,r6,r15}
  57. end;