Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / modulong.c
blob67b1fb85b73f3c3c9e50d6e30d48dfedc7f150eb
1 /*
2 modulong.c
3 A modulo algrithm. The point of this test is that it triggers otherwise untested peephole rules.
4 */
6 #include <testfwk.h>
8 #define MSB_SET(x) ((x >> (8*sizeof(x)-1)) & 1)
10 unsigned long
11 modulong (unsigned long a, unsigned long b)
13 unsigned char count = 0;
15 while (!MSB_SET(b))
17 b <<= 1;
18 if (b > a)
20 b >>=1;
21 break;
23 count++;
27 if (a >= b)
28 a -= b;
29 b >>= 1;
31 while (count--);
33 return a;
36 void
37 testMod(void)
39 ASSERT (modulong (42ul, 23ul) == 42ul % 23ul);