bitmasks.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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(nimPage256) or defined(cpu16): 3
  13. elif defined(nimPage512): 9
  14. elif defined(nimPage1k): 10
  15. else: 12 # \ # my tests showed no improvements for using larger page sizes.
  16. PageSize = 1 shl PageShift
  17. PageMask = PageSize-1
  18. MemAlign = # also minimal allocatable memory block
  19. when defined(nimMemAlignTiny): 4
  20. elif defined(useMalloc):
  21. when defined(amd64): 16
  22. else: 8
  23. else: 16
  24. BitsPerPage = PageSize div MemAlign
  25. UnitsPerPage = BitsPerPage div (sizeof(int)*8)
  26. # how many ints do we need to describe a page:
  27. # on 32 bit systems this is only 16 (!)
  28. TrunkShift = 9
  29. BitsPerTrunk = 1 shl TrunkShift # needs to be power of 2 and divisible by 64
  30. TrunkMask = BitsPerTrunk - 1
  31. IntsPerTrunk = BitsPerTrunk div (sizeof(int)*8)
  32. IntShift = 5 + ord(sizeof(int) == 8) # 5 or 6, depending on int width
  33. IntMask = 1 shl IntShift - 1