From 7b0611393a98399063aefaa87583b05fef13f6e3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 10 May 2014 15:40:29 +0800 Subject: [PATCH] Kernel/arch - Fix common division macro to handle numerators around datatype max --- KernelLand/Kernel/arch/helpers.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/KernelLand/Kernel/arch/helpers.h b/KernelLand/Kernel/arch/helpers.h index 4d85fcb4..b4780310 100644 --- a/KernelLand/Kernel/arch/helpers.h +++ b/KernelLand/Kernel/arch/helpers.h @@ -14,10 +14,10 @@ // > If the `N` value is greater than `D`, we can set this bit #define DEF_DIVMOD(s) Uint##s __divmod##s(Uint##s N, Uint##s D, Uint##s*Rem){\ Uint##s ret=0,add=1;\ - while(N>=D&&add) {D<<=1;add<<=1;}\ - while(add>1){\ - add>>=1;D>>=1;\ + while(N/2>=D&&add) {D<<=1;add<<=1;}\ + while(add>0){\ if(N>=D){ret+=add;N-=D;}\ + add>>=1;D>>=1;\ }\ if(Rem)*Rem = N;\ return ret;\ -- 2.20.1