diff options
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/src/lisp.h b/src/lisp.h index 80a9ab343c3..a45e9c2c892 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -20,6 +20,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 20 | #ifndef EMACS_LISP_H | 20 | #ifndef EMACS_LISP_H |
| 21 | #define EMACS_LISP_H | 21 | #define EMACS_LISP_H |
| 22 | 22 | ||
| 23 | #include <stdalign.h> | ||
| 23 | #include <stdarg.h> | 24 | #include <stdarg.h> |
| 24 | #include <stddef.h> | 25 | #include <stddef.h> |
| 25 | #include <inttypes.h> | 26 | #include <inttypes.h> |
| @@ -151,10 +152,6 @@ extern int suppress_checking EXTERNALLY_VISIBLE; | |||
| 151 | on the few static Lisp_Objects used: all the defsubr as well | 152 | on the few static Lisp_Objects used: all the defsubr as well |
| 152 | as the two special buffers buffer_defaults and buffer_local_symbols. */ | 153 | as the two special buffers buffer_defaults and buffer_local_symbols. */ |
| 153 | 154 | ||
| 154 | /* First, try and define DECL_ALIGN(type,var) which declares a static | ||
| 155 | variable VAR of type TYPE with the added requirement that it be | ||
| 156 | TYPEBITS-aligned. */ | ||
| 157 | |||
| 158 | enum Lisp_Bits | 155 | enum Lisp_Bits |
| 159 | { | 156 | { |
| 160 | /* Number of bits in a Lisp_Object tag. This can be used in #if, | 157 | /* Number of bits in a Lisp_Object tag. This can be used in #if, |
| @@ -163,6 +160,12 @@ enum Lisp_Bits | |||
| 163 | #define GCTYPEBITS 3 | 160 | #define GCTYPEBITS 3 |
| 164 | GCTYPEBITS, | 161 | GCTYPEBITS, |
| 165 | 162 | ||
| 163 | /* 2**GCTYPEBITS. This must also be a macro that expands to a | ||
| 164 | literal integer constant, for MSVC. */ | ||
| 165 | GCALIGNMENT = | ||
| 166 | #define GCALIGNMENT 8 | ||
| 167 | GCALIGNMENT, | ||
| 168 | |||
| 166 | /* Number of bits in a Lisp_Object value, not counting the tag. */ | 169 | /* Number of bits in a Lisp_Object value, not counting the tag. */ |
| 167 | VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS, | 170 | VALBITS = BITS_PER_EMACS_INT - GCTYPEBITS, |
| 168 | 171 | ||
| @@ -173,36 +176,22 @@ enum Lisp_Bits | |||
| 173 | FIXNUM_BITS = VALBITS + 1 | 176 | FIXNUM_BITS = VALBITS + 1 |
| 174 | }; | 177 | }; |
| 175 | 178 | ||
| 179 | #if GCALIGNMENT != 1 << GCTYPEBITS | ||
| 180 | # error "GCALIGNMENT and GCTYPEBITS are inconsistent" | ||
| 181 | #endif | ||
| 182 | |||
| 176 | /* The maximum value that can be stored in a EMACS_INT, assuming all | 183 | /* The maximum value that can be stored in a EMACS_INT, assuming all |
| 177 | bits other than the type bits contribute to a nonnegative signed value. | 184 | bits other than the type bits contribute to a nonnegative signed value. |
| 178 | This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */ | 185 | This can be used in #if, e.g., '#if VAL_MAX < UINTPTR_MAX' below. */ |
| 179 | #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1)) | 186 | #define VAL_MAX (EMACS_INT_MAX >> (GCTYPEBITS - 1)) |
| 180 | 187 | ||
| 181 | #ifndef NO_DECL_ALIGN | ||
| 182 | # ifndef DECL_ALIGN | ||
| 183 | # if HAVE_ATTRIBUTE_ALIGNED | ||
| 184 | # define DECL_ALIGN(type, var) \ | ||
| 185 | type __attribute__ ((__aligned__ (1 << GCTYPEBITS))) var | ||
| 186 | # elif defined(_MSC_VER) | ||
| 187 | # define ALIGN_GCTYPEBITS 8 | ||
| 188 | # if (1 << GCTYPEBITS) != ALIGN_GCTYPEBITS | ||
| 189 | # error ALIGN_GCTYPEBITS is wrong! | ||
| 190 | # endif | ||
| 191 | # define DECL_ALIGN(type, var) \ | ||
| 192 | type __declspec(align(ALIGN_GCTYPEBITS)) var | ||
| 193 | # else | ||
| 194 | /* What directives do other compilers use? */ | ||
| 195 | # endif | ||
| 196 | # endif | ||
| 197 | #endif | ||
| 198 | |||
| 199 | /* Unless otherwise specified, use USE_LSB_TAG on systems where: */ | 188 | /* Unless otherwise specified, use USE_LSB_TAG on systems where: */ |
| 200 | #ifndef USE_LSB_TAG | 189 | #ifndef USE_LSB_TAG |
| 201 | /* 1. We know malloc returns a multiple of 8. */ | 190 | /* 1. We know malloc returns a multiple of 8. */ |
| 202 | # if (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \ | 191 | # if (defined GNU_MALLOC || defined DOUG_LEA_MALLOC || defined __GLIBC__ \ |
| 203 | || defined DARWIN_OS || defined __sun) | 192 | || defined DARWIN_OS || defined __sun) |
| 204 | /* 2. We can specify multiple-of-8 alignment on static variables. */ | 193 | /* 2. We can specify multiple-of-8 alignment on static variables. */ |
| 205 | # ifdef DECL_ALIGN | 194 | # ifdef alignas |
| 206 | /* 3. Pointers-as-ints exceed VAL_MAX. | 195 | /* 3. Pointers-as-ints exceed VAL_MAX. |
| 207 | On hosts where pointers-as-ints do not exceed VAL_MAX, USE_LSB_TAG is: | 196 | On hosts where pointers-as-ints do not exceed VAL_MAX, USE_LSB_TAG is: |
| 208 | a. unnecessary, because the top bits of an EMACS_INT are unused, and | 197 | a. unnecessary, because the top bits of an EMACS_INT are unused, and |
| @@ -223,12 +212,11 @@ enum enum_USE_LSB_TAG { USE_LSB_TAG = 0 }; | |||
| 223 | # define USE_LSB_TAG 0 | 212 | # define USE_LSB_TAG 0 |
| 224 | #endif | 213 | #endif |
| 225 | 214 | ||
| 226 | /* If we cannot use 8-byte alignment, make DECL_ALIGN a no-op. */ | 215 | #ifndef alignas |
| 227 | #ifndef DECL_ALIGN | 216 | # define alignas(alignment) /* empty */ |
| 228 | # if USE_LSB_TAG | 217 | # if USE_LSB_TAG |
| 229 | # error "USE_LSB_TAG used without defining DECL_ALIGN" | 218 | # error "USE_LSB_TAG requires alignas" |
| 230 | # endif | 219 | # endif |
| 231 | # define DECL_ALIGN(type, var) type var | ||
| 232 | #endif | 220 | #endif |
| 233 | 221 | ||
| 234 | 222 | ||
| @@ -1882,7 +1870,7 @@ typedef struct { | |||
| 1882 | #ifdef _MSC_VER | 1870 | #ifdef _MSC_VER |
| 1883 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ | 1871 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ |
| 1884 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ | 1872 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ |
| 1885 | static DECL_ALIGN (struct Lisp_Subr, sname) = \ | 1873 | static struct Lisp_Subr alignas (GCALIGNMENT) sname = \ |
| 1886 | { (PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS) \ | 1874 | { (PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS) \ |
| 1887 | | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ | 1875 | | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ |
| 1888 | { (Lisp_Object (__cdecl *)(void))fnname }, \ | 1876 | { (Lisp_Object (__cdecl *)(void))fnname }, \ |
| @@ -1891,7 +1879,7 @@ typedef struct { | |||
| 1891 | #else /* not _MSC_VER */ | 1879 | #else /* not _MSC_VER */ |
| 1892 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ | 1880 | #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ |
| 1893 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ | 1881 | Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ |
| 1894 | static DECL_ALIGN (struct Lisp_Subr, sname) = \ | 1882 | static struct Lisp_Subr alignas (GCALIGNMENT) sname = \ |
| 1895 | { PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS, \ | 1883 | { PVEC_SUBR << PSEUDOVECTOR_SIZE_BITS, \ |
| 1896 | { .a ## maxargs = fnname }, \ | 1884 | { .a ## maxargs = fnname }, \ |
| 1897 | minargs, maxargs, lname, intspec, 0}; \ | 1885 | minargs, maxargs, lname, intspec, 0}; \ |