bitmasks.nim 987 B

12345678910111213141516171819202122232425262728293031
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. # Page size of the system; in most cases 4096 bytes. For exotic OS or
  10. # CPU this needs to be changed:
  11. const
  12. PageShift = when defined(cpu16): 8 else: 12 # \
  13. # my tests showed no improvements for using larger page sizes.
  14. PageSize = 1 shl PageShift
  15. PageMask = PageSize-1
  16. MemAlign = 16 # also minimal allocatable memory block
  17. BitsPerPage = PageSize div MemAlign
  18. UnitsPerPage = BitsPerPage div (sizeof(int)*8)
  19. # how many ints do we need to describe a page:
  20. # on 32 bit systems this is only 16 (!)
  21. TrunkShift = 9
  22. BitsPerTrunk = 1 shl TrunkShift # needs to be power of 2 and divisible by 64
  23. TrunkMask = BitsPerTrunk - 1
  24. IntsPerTrunk = BitsPerTrunk div (sizeof(int)*8)
  25. IntShift = 5 + ord(sizeof(int) == 8) # 5 or 6, depending on int width
  26. IntMask = 1 shl IntShift - 1