You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__udivmoddi4.c 587B

1234567891011121314151617181920212223242526272829303132
  1. #include "libgcc.h"
  2. __libgcc uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t *rem_p)
  3. {
  4. uint64_t quot = 0, qbit = 1;
  5. if ( den == 0 ) {
  6. return 1/((unsigned)den); /* Intentional divide by zero, without
  7. triggering a compiler warning which
  8. would abort the build */
  9. }
  10. /* Left-justify denominator and count shift */
  11. while ( (int64_t)den >= 0 ) {
  12. den <<= 1;
  13. qbit <<= 1;
  14. }
  15. while ( qbit ) {
  16. if ( den <= num ) {
  17. num -= den;
  18. quot += qbit;
  19. }
  20. den >>= 1;
  21. qbit >>= 1;
  22. }
  23. if ( rem_p )
  24. *rem_p = num;
  25. return quot;
  26. }