1 /* 2 * File : __udivsi3.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 15 #include <stdint.h> 16 __udivsi3(uint32_t num,uint32_t den)17uint32_t __udivsi3(uint32_t num, uint32_t den) 18 { 19 uint32_t quot = 0, qbit = 1; 20 21 if (den == 0) 22 { 23 asm volatile ("int $0"); 24 return 0; /* If trap returns... */ 25 } 26 27 /* Left-justify denominator and count shift */ 28 while ((int32_t) den >= 0) 29 { 30 den <<= 1; 31 qbit <<= 1; 32 } 33 34 while (qbit) 35 { 36 if (den <= num) 37 { 38 num -= den; 39 quot += qbit; 40 } 41 den >>= 1; 42 qbit >>= 1; 43 } 44 45 return quot; 46 } 47