page_constants.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Part of Scheme 48 1.9. See file COPYING for notices and license.
  3. *
  4. * Authors: David Frese, Robert Ransom
  5. */
  6. #ifndef __S48_PAGE_CONSTANTS_H
  7. #define __S48_PAGE_CONSTANTS_H
  8. #include "memory.h"
  9. #define LOG_BYTES_PER_PAGE 12
  10. #define BYTES_PER_PAGE (1L << LOG_BYTES_PER_PAGE)
  11. #define PAGE_INDEX_MASK (BYTES_PER_PAGE - 1)
  12. #define PAGE_START_ADDRESS(address) ((s48_address)(((long)address) & \
  13. (~ PAGE_INDEX_MASK)))
  14. #define INDEX_IN_PAGE(address) ((long)((address) & PAGE_INDEX_MASK))
  15. /* This macro evaluates its argument twice to avoid a possible integer
  16. overflow. */
  17. #define BYTES_TO_PAGES(n) (((n) >> LOG_BYTES_PER_PAGE) + \
  18. (((n) & PAGE_INDEX_MASK) ? 1 : 0))
  19. /* This macro can produce an integer overflow, even if applied to a
  20. number which was returned from BYTES_TO_PAGES. Use with extreme
  21. care. */
  22. #define PAGES_TO_BYTES_I_KNOW_THIS_CAN_OVERFLOW(n) \
  23. ((unsigned long)(n) << LOG_BYTES_PER_PAGE)
  24. /* Needed for gc_config.h, where it is used to precompute a constant
  25. that the preprocessor must be able to compare to another constant.
  26. (CPP can't handle "unsigned long" in an arithmetic expression.) */
  27. #define PAGES_TO_BYTES_SMALL_CONST_FOR_CPP(n) ((n) << LOG_BYTES_PER_PAGE)
  28. #define PAGES_TO_BYTES_LOSSAGE_MASK ((long)(~((unsigned long)(-1L) >> LOG_BYTES_PER_PAGE)))
  29. #define PAGES_TO_BYTES_LOSES_P(n) ((n) & PAGES_TO_BYTES_LOSSAGE_MASK)
  30. /* This macro can produce an integer overflow, and was unused. */
  31. /* #define PAGES_TO_CELLS(n) (S48_BYTES_TO_CELLS((n) << LOG_BYTES_PER_PAGE)) */
  32. #define ADD_PAGES_I_KNOW_THIS_CAN_OVERFLOW(address, pages) ((s48_address)((address) + \
  33. PAGES_TO_BYTES_I_KNOW_THIS_CAN_OVERFLOW(pages)))
  34. #endif