]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/teg2/v7-arch.c
devarch: restrict i/o port access to 64K, disallow msr 32-bit wrap arround (thanks...
[plan9front.git] / sys / src / 9 / teg2 / v7-arch.c
1 /*
2  * arm arch v7 routines other than cache-related ones.
3  *
4  * calling this arch-v7.c would confuse the mk scripts,
5  * to which a filename arch*.c is magic.
6  */
7 #include "u.h"
8 #include "../port/lib.h"
9 #include "mem.h"
10 #include "dat.h"
11 #include "fns.h"
12 #include "../port/error.h"
13 #include "io.h"
14 #include "arm.h"
15
16 /*
17  * these routines should be cheap enough that there will
18  * be no hesitation to use them.
19  *
20  * once 5c in-lines vlong ops, just use the vlong versions.
21  */
22
23 /* see Hacker's Delight if this isn't obvious */
24 #define ISPOW2(i) (((i) & ((i) - 1)) == 0)
25
26 int
27 ispow2(uvlong uvl)
28 {
29         /* see Hacker's Delight if this isn't obvious */
30         return ISPOW2(uvl);
31 }
32
33 static int
34 isulpow2(ulong ul)                              /* temporary speed hack */
35 {
36         return ISPOW2(ul);
37 }
38
39 /*
40  * return exponent of smallest power of 2 ≥ n
41  */
42 int
43 log2(ulong n)
44 {
45         int i;
46
47         i = BI2BY*BY2WD - 1 - clz(n);
48         if (n == 0 || !ISPOW2(n))
49                 i++;
50         return i;
51 }