__umodsi3.c 888 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * File : __umodsi3.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-10-09 Bernard the first version for i386
  13. */
  14. #include <rtthread.h>
  15. typedef rt_uint32_t uint32_t;
  16. typedef rt_int32_t int32_t;
  17. uint32_t __umodsi3(uint32_t num, uint32_t den)
  18. {
  19. register uint32_t quot = 0, qbit = 1;
  20. if (den == 0)
  21. {
  22. asm volatile ("int $0");
  23. return 0; /* if trap returns... */
  24. }
  25. /* left-justify denominator and count shift */
  26. while ((int32_t) den >= 0)
  27. {
  28. den <<= 1;
  29. qbit <<= 1;
  30. }
  31. while (qbit)
  32. {
  33. if (den <= num)
  34. {
  35. num -= den;
  36. quot += qbit;
  37. }
  38. den >>= 1;
  39. qbit >>= 1;
  40. }
  41. return num;
  42. }