v7-arch.c 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. * these routines should be cheap enough that there will
  17. * be no hesitation to use them.
  18. *
  19. * once 5c in-lines vlong ops, just use the vlong versions.
  20. */
  21. /* see Hacker's Delight if this isn't obvious */
  22. #define ISPOW2(i) (((i) & ((i) - 1)) == 0)
  23. int
  24. ispow2(uvlong uvl)
  25. {
  26. /* see Hacker's Delight if this isn't obvious */
  27. return ISPOW2(uvl);
  28. }
  29. static int
  30. isulpow2(ulong ul) /* temporary speed hack */
  31. {
  32. return ISPOW2(ul);
  33. }
  34. /*
  35. * return exponent of smallest power of 2 ≥ n
  36. */
  37. int
  38. log2(ulong n)
  39. {
  40. int i;
  41. i = BI2BY*BY2WD - 1 - clz(n);
  42. if (n == 0 || !ISPOW2(n))
  43. i++;
  44. return i;
  45. }