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