bitmasks.nim 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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 = # also minimal allocatable memory block
  17. when defined(useMalloc):
  18. when defined(amd64): 16
  19. else: 8
  20. else: 16
  21. BitsPerPage = PageSize div MemAlign
  22. UnitsPerPage = BitsPerPage div (sizeof(int)*8)
  23. # how many ints do we need to describe a page:
  24. # on 32 bit systems this is only 16 (!)
  25. TrunkShift = 9
  26. BitsPerTrunk = 1 shl TrunkShift # needs to be power of 2 and divisible by 64
  27. TrunkMask = BitsPerTrunk - 1
  28. IntsPerTrunk = BitsPerTrunk div (sizeof(int)*8)
  29. IntShift = 5 + ord(sizeof(int) == 8) # 5 or 6, depending on int width
  30. IntMask = 1 shl IntShift - 1