diff options
| author | Nicolás Bértolo | 2020-05-08 14:30:14 -0300 |
|---|---|---|
| committer | Andrea Corallo | 2020-05-20 20:46:39 +0100 |
| commit | 7fa83f9ac96bd201a15f7b0ae4a2cd20a70fd7ef (patch) | |
| tree | 19eb5fbb75b4a8f706000d4fc0ffbbc834d16f89 /src | |
| parent | 5ff2cbdb04fe190c12b43a6c0f95a311da767872 (diff) | |
| download | emacs-7fa83f9ac96bd201a15f7b0ae4a2cd20a70fd7ef.tar.gz emacs-7fa83f9ac96bd201a15f7b0ae4a2cd20a70fd7ef.zip | |
Handle LISP_WORDS_ARE_POINTERS and CHECK_LISP_OBJECT_TYPE.
* src/comp.c: Introduce the Lisp_X, Lisp_Word, and Lisp_Word_tag
types. These types are used instead of long or long long. Use
emacs_int_type and emacs_uint_types where appropriate.
(emit_coerce): Add special logic that handles the case when
Lisp_Object is a struct. This is necessary for handling the
--enable-check-lisp-object-type configure option.
* src/lisp.h: Since libgccjit does not support opaque unions, change
Lisp_X to be struct. This is done to ensure that the same types are
used in the same binary. It is probably unnecessary since only a
pointer to it is used.
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp.c | 319 | ||||
| -rw-r--r-- | src/lisp.h | 5 |
2 files changed, 218 insertions, 106 deletions
diff --git a/src/comp.c b/src/comp.c index 15dd0487c01..acb018bab7b 100644 --- a/src/comp.c +++ b/src/comp.c | |||
| @@ -116,6 +116,16 @@ typedef struct { | |||
| 116 | gcc_jit_type *char_ptr_type; | 116 | gcc_jit_type *char_ptr_type; |
| 117 | gcc_jit_type *ptrdiff_type; | 117 | gcc_jit_type *ptrdiff_type; |
| 118 | gcc_jit_type *uintptr_type; | 118 | gcc_jit_type *uintptr_type; |
| 119 | #if LISP_WORDS_ARE_POINTERS | ||
| 120 | gcc_jit_struct *lisp_X_s; | ||
| 121 | gcc_jit_type *lisp_X; | ||
| 122 | #endif | ||
| 123 | gcc_jit_type *lisp_word_type; | ||
| 124 | gcc_jit_type *lisp_word_tag_type; | ||
| 125 | #ifdef LISP_OBJECT_IS_STRUCT | ||
| 126 | gcc_jit_field *lisp_obj_i; | ||
| 127 | gcc_jit_struct *lisp_obj_s; | ||
| 128 | #endif | ||
| 119 | gcc_jit_type *lisp_obj_type; | 129 | gcc_jit_type *lisp_obj_type; |
| 120 | gcc_jit_type *lisp_obj_ptr_type; | 130 | gcc_jit_type *lisp_obj_ptr_type; |
| 121 | /* struct Lisp_Cons */ | 131 | /* struct Lisp_Cons */ |
| @@ -158,7 +168,8 @@ typedef struct { | |||
| 158 | gcc_jit_field *cast_union_as_c_p; | 168 | gcc_jit_field *cast_union_as_c_p; |
| 159 | gcc_jit_field *cast_union_as_v_p; | 169 | gcc_jit_field *cast_union_as_v_p; |
| 160 | gcc_jit_field *cast_union_as_lisp_cons_ptr; | 170 | gcc_jit_field *cast_union_as_lisp_cons_ptr; |
| 161 | gcc_jit_field *cast_union_as_lisp_obj; | 171 | gcc_jit_field *cast_union_as_lisp_word; |
| 172 | gcc_jit_field *cast_union_as_lisp_word_tag; | ||
| 162 | gcc_jit_field *cast_union_as_lisp_obj_ptr; | 173 | gcc_jit_field *cast_union_as_lisp_obj_ptr; |
| 163 | gcc_jit_function *func; /* Current function being compiled. */ | 174 | gcc_jit_function *func; /* Current function being compiled. */ |
| 164 | bool func_has_non_local; /* From comp-func has-non-local slot. */ | 175 | bool func_has_non_local; /* From comp-func has-non-local slot. */ |
| @@ -344,8 +355,10 @@ type_to_cast_field (gcc_jit_type *type) | |||
| 344 | field = comp.cast_union_as_c_p; | 355 | field = comp.cast_union_as_c_p; |
| 345 | else if (type == comp.lisp_cons_ptr_type) | 356 | else if (type == comp.lisp_cons_ptr_type) |
| 346 | field = comp.cast_union_as_lisp_cons_ptr; | 357 | field = comp.cast_union_as_lisp_cons_ptr; |
| 347 | else if (type == comp.lisp_obj_type) | 358 | else if (type == comp.lisp_word_type) |
| 348 | field = comp.cast_union_as_lisp_obj; | 359 | field = comp.cast_union_as_lisp_word; |
| 360 | else if (type == comp.lisp_word_tag_type) | ||
| 361 | field = comp.cast_union_as_lisp_word_tag; | ||
| 349 | else if (type == comp.lisp_obj_ptr_type) | 362 | else if (type == comp.lisp_obj_ptr_type) |
| 350 | field = comp.cast_union_as_lisp_obj_ptr; | 363 | field = comp.cast_union_as_lisp_obj_ptr; |
| 351 | else | 364 | else |
| @@ -624,6 +637,31 @@ emit_coerce (gcc_jit_type *new_type, gcc_jit_rvalue *obj) | |||
| 624 | if (new_type == old_type) | 637 | if (new_type == old_type) |
| 625 | return obj; | 638 | return obj; |
| 626 | 639 | ||
| 640 | #ifdef LISP_OBJECT_IS_STRUCT | ||
| 641 | if (old_type == comp.lisp_obj_type) | ||
| 642 | { | ||
| 643 | gcc_jit_rvalue *lwordobj = | ||
| 644 | gcc_jit_rvalue_access_field (obj, NULL, comp.lisp_obj_i); | ||
| 645 | return emit_coerce (new_type, lwordobj); | ||
| 646 | } | ||
| 647 | |||
| 648 | if (new_type == comp.lisp_obj_type) | ||
| 649 | { | ||
| 650 | gcc_jit_rvalue *lwordobj = | ||
| 651 | emit_coerce (comp.lisp_word_type, obj); | ||
| 652 | |||
| 653 | gcc_jit_lvalue *tmp_s | ||
| 654 | = gcc_jit_function_new_local (comp.func, NULL, comp.lisp_obj_type, | ||
| 655 | format_string ("lisp_obj_%td", i++)); | ||
| 656 | |||
| 657 | gcc_jit_block_add_assignment (comp.block, NULL, | ||
| 658 | gcc_jit_lvalue_access_field (tmp_s, NULL, | ||
| 659 | comp.lisp_obj_i), | ||
| 660 | lwordobj); | ||
| 661 | return gcc_jit_lvalue_as_rvalue (tmp_s); | ||
| 662 | } | ||
| 663 | #endif | ||
| 664 | |||
| 627 | gcc_jit_field *orig_field = | 665 | gcc_jit_field *orig_field = |
| 628 | type_to_cast_field (old_type); | 666 | type_to_cast_field (old_type); |
| 629 | gcc_jit_field *dest_field = type_to_cast_field (new_type); | 667 | gcc_jit_field *dest_field = type_to_cast_field (new_type); |
| @@ -661,14 +699,8 @@ emit_binary_op (enum gcc_jit_binary_op op, | |||
| 661 | /* Should come with libgccjit. */ | 699 | /* Should come with libgccjit. */ |
| 662 | 700 | ||
| 663 | static gcc_jit_rvalue * | 701 | static gcc_jit_rvalue * |
| 664 | emit_rvalue_from_long_long (long long n) | 702 | emit_rvalue_from_long_long (gcc_jit_type *type, long long n) |
| 665 | { | 703 | { |
| 666 | #ifndef WIDE_EMACS_INT | ||
| 667 | xsignal1 (Qnative_ice, | ||
| 668 | build_string ("emit_rvalue_from_long_long called in non wide int" | ||
| 669 | " configuration")); | ||
| 670 | #endif | ||
| 671 | |||
| 672 | emit_comment (format_string ("emit long long: %lld", n)); | 704 | emit_comment (format_string ("emit long long: %lld", n)); |
| 673 | 705 | ||
| 674 | gcc_jit_rvalue *high = | 706 | gcc_jit_rvalue *high = |
| @@ -694,7 +726,7 @@ emit_rvalue_from_long_long (long long n) | |||
| 694 | 32)); | 726 | 32)); |
| 695 | 727 | ||
| 696 | return | 728 | return |
| 697 | emit_coerce (comp.long_long_type, | 729 | emit_coerce (type, |
| 698 | emit_binary_op ( | 730 | emit_binary_op ( |
| 699 | GCC_JIT_BINARY_OP_BITWISE_OR, | 731 | GCC_JIT_BINARY_OP_BITWISE_OR, |
| 700 | comp.unsigned_long_long_type, | 732 | comp.unsigned_long_long_type, |
| @@ -709,26 +741,120 @@ emit_rvalue_from_long_long (long long n) | |||
| 709 | } | 741 | } |
| 710 | 742 | ||
| 711 | static gcc_jit_rvalue * | 743 | static gcc_jit_rvalue * |
| 712 | emit_most_positive_fixnum (void) | 744 | emit_rvalue_from_unsigned_long_long (gcc_jit_type *type, unsigned long long n) |
| 745 | { | ||
| 746 | emit_comment (format_string ("emit unsigned long long: %llu", n)); | ||
| 747 | |||
| 748 | gcc_jit_rvalue *high = | ||
| 749 | gcc_jit_context_new_rvalue_from_long (comp.ctxt, | ||
| 750 | comp.unsigned_long_long_type, | ||
| 751 | n >> 32); | ||
| 752 | gcc_jit_rvalue *low = | ||
| 753 | emit_binary_op (GCC_JIT_BINARY_OP_RSHIFT, | ||
| 754 | comp.unsigned_long_long_type, | ||
| 755 | emit_binary_op (GCC_JIT_BINARY_OP_LSHIFT, | ||
| 756 | comp.unsigned_long_long_type, | ||
| 757 | gcc_jit_context_new_rvalue_from_long ( | ||
| 758 | comp.ctxt, | ||
| 759 | comp.unsigned_long_long_type, | ||
| 760 | n), | ||
| 761 | gcc_jit_context_new_rvalue_from_int ( | ||
| 762 | comp.ctxt, | ||
| 763 | comp.unsigned_long_long_type, | ||
| 764 | 32)), | ||
| 765 | gcc_jit_context_new_rvalue_from_int ( | ||
| 766 | comp.ctxt, | ||
| 767 | comp.unsigned_long_long_type, | ||
| 768 | 32)); | ||
| 769 | |||
| 770 | return emit_coerce ( | ||
| 771 | type, | ||
| 772 | emit_binary_op ( | ||
| 773 | GCC_JIT_BINARY_OP_BITWISE_OR, | ||
| 774 | comp.unsigned_long_long_type, | ||
| 775 | emit_binary_op ( | ||
| 776 | GCC_JIT_BINARY_OP_LSHIFT, | ||
| 777 | comp.unsigned_long_long_type, | ||
| 778 | high, | ||
| 779 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, | ||
| 780 | comp.unsigned_long_long_type, | ||
| 781 | 32)), | ||
| 782 | low)); | ||
| 783 | } | ||
| 784 | |||
| 785 | static gcc_jit_rvalue * | ||
| 786 | emit_rvalue_from_emacs_uint (EMACS_UINT val) | ||
| 787 | { | ||
| 788 | if (val != (long) val) | ||
| 789 | { | ||
| 790 | return emit_rvalue_from_unsigned_long_long (comp.emacs_uint_type, val); | ||
| 791 | } | ||
| 792 | else | ||
| 793 | { | ||
| 794 | return gcc_jit_context_new_rvalue_from_long (comp.ctxt, | ||
| 795 | comp.emacs_uint_type, | ||
| 796 | val); | ||
| 797 | } | ||
| 798 | } | ||
| 799 | |||
| 800 | static gcc_jit_rvalue * | ||
| 801 | emit_rvalue_from_emacs_int (EMACS_INT val) | ||
| 802 | { | ||
| 803 | if (val != (long) val) | ||
| 804 | { | ||
| 805 | return emit_rvalue_from_long_long (comp.emacs_int_type, val); | ||
| 806 | } | ||
| 807 | else | ||
| 808 | { | ||
| 809 | return gcc_jit_context_new_rvalue_from_long (comp.ctxt, | ||
| 810 | comp.emacs_int_type, val); | ||
| 811 | } | ||
| 812 | } | ||
| 813 | |||
| 814 | static gcc_jit_rvalue * | ||
| 815 | emit_rvalue_from_lisp_word_tag (Lisp_Word_tag val) | ||
| 816 | { | ||
| 817 | if (val != (long) val) | ||
| 818 | { | ||
| 819 | return emit_rvalue_from_unsigned_long_long (comp.lisp_word_tag_type, val); | ||
| 820 | } | ||
| 821 | else | ||
| 822 | { | ||
| 823 | return gcc_jit_context_new_rvalue_from_long (comp.ctxt, | ||
| 824 | comp.lisp_word_tag_type, | ||
| 825 | val); | ||
| 826 | } | ||
| 827 | } | ||
| 828 | |||
| 829 | static gcc_jit_rvalue * | ||
| 830 | emit_rvalue_from_lisp_word (Lisp_Word val) | ||
| 713 | { | 831 | { |
| 714 | #if EMACS_INT_MAX > LONG_MAX | 832 | #if LISP_WORDS_ARE_POINTERS |
| 715 | return emit_rvalue_from_long_long (MOST_POSITIVE_FIXNUM); | 833 | return gcc_jit_context_new_rvalue_from_ptr (comp.ctxt, |
| 834 | comp.lisp_word_type, | ||
| 835 | val); | ||
| 716 | #else | 836 | #else |
| 717 | return gcc_jit_context_new_rvalue_from_long (comp.ctxt, | 837 | if (val != (long) val) |
| 718 | comp.emacs_int_type, | 838 | { |
| 719 | MOST_POSITIVE_FIXNUM); | 839 | return emit_rvalue_from_unsigned_long_long (comp.lisp_word_type, val); |
| 840 | } | ||
| 841 | else | ||
| 842 | { | ||
| 843 | return gcc_jit_context_new_rvalue_from_long (comp.ctxt, | ||
| 844 | comp.lisp_word_type, | ||
| 845 | val); | ||
| 846 | } | ||
| 720 | #endif | 847 | #endif |
| 721 | } | 848 | } |
| 722 | 849 | ||
| 723 | static gcc_jit_rvalue * | 850 | static gcc_jit_rvalue * |
| 724 | emit_most_negative_fixnum (void) | 851 | emit_rvalue_from_lisp_obj (Lisp_Object obj) |
| 725 | { | 852 | { |
| 726 | #if EMACS_INT_MAX > LONG_MAX | 853 | #ifdef LISP_OBJECT_IS_STRUCT |
| 727 | return emit_rvalue_from_long_long (MOST_NEGATIVE_FIXNUM); | 854 | return emit_coerce (comp.lisp_obj_type, |
| 855 | emit_rvalue_from_lisp_word (obj.i)); | ||
| 728 | #else | 856 | #else |
| 729 | return gcc_jit_context_new_rvalue_from_long (comp.ctxt, | 857 | return emit_rvalue_from_lisp_word (obj); |
| 730 | comp.emacs_int_type, | ||
| 731 | MOST_NEGATIVE_FIXNUM); | ||
| 732 | #endif | 858 | #endif |
| 733 | } | 859 | } |
| 734 | 860 | ||
| @@ -766,7 +892,7 @@ static gcc_jit_rvalue * | |||
| 766 | emit_XLI (gcc_jit_rvalue *obj) | 892 | emit_XLI (gcc_jit_rvalue *obj) |
| 767 | { | 893 | { |
| 768 | emit_comment ("XLI"); | 894 | emit_comment ("XLI"); |
| 769 | return obj; | 895 | return emit_coerce (comp.emacs_int_type, obj); |
| 770 | } | 896 | } |
| 771 | 897 | ||
| 772 | static gcc_jit_lvalue * | 898 | static gcc_jit_lvalue * |
| @@ -776,54 +902,40 @@ emit_lval_XLI (gcc_jit_lvalue *obj) | |||
| 776 | return obj; | 902 | return obj; |
| 777 | } | 903 | } |
| 778 | 904 | ||
| 779 | /* | 905 | |
| 780 | static gcc_jit_rvalue * | 906 | static gcc_jit_rvalue * |
| 781 | emit_XLP (gcc_jit_rvalue *obj) | 907 | emit_XLP (gcc_jit_rvalue *obj) |
| 782 | { | 908 | { |
| 783 | emit_comment ("XLP"); | 909 | emit_comment ("XLP"); |
| 784 | 910 | ||
| 785 | return gcc_jit_rvalue_access_field (obj, | 911 | return emit_coerce (comp.void_ptr_type, obj); |
| 786 | NULL, | ||
| 787 | comp.lisp_obj_as_ptr); | ||
| 788 | } | 912 | } |
| 789 | 913 | ||
| 790 | static gcc_jit_lvalue * | 914 | /* TODO */ |
| 791 | emit_lval_XLP (gcc_jit_lvalue *obj) | 915 | /* static gcc_jit_lvalue * */ |
| 792 | { | 916 | /* emit_lval_XLP (gcc_jit_lvalue *obj) */ |
| 793 | emit_comment ("lval_XLP"); | 917 | /* { */ |
| 918 | /* emit_comment ("lval_XLP"); */ | ||
| 919 | |||
| 920 | /* return gcc_jit_lvalue_access_field (obj, */ | ||
| 921 | /* NULL, */ | ||
| 922 | /* comp.lisp_obj_as_ptr); */ | ||
| 923 | /* } */ | ||
| 794 | 924 | ||
| 795 | return gcc_jit_lvalue_access_field (obj, | ||
| 796 | NULL, | ||
| 797 | comp.lisp_obj_as_ptr); | ||
| 798 | } */ | ||
| 799 | static gcc_jit_rvalue * | 925 | static gcc_jit_rvalue * |
| 800 | emit_XUNTAG (gcc_jit_rvalue *a, gcc_jit_type *type, long long lisp_word_tag) | 926 | emit_XUNTAG (gcc_jit_rvalue *a, gcc_jit_type *type, Lisp_Word_tag lisp_word_tag) |
| 801 | { | 927 | { |
| 802 | /* #define XUNTAG(a, type, ctype) ((ctype *) | 928 | /* #define XUNTAG(a, type, ctype) ((ctype *) |
| 803 | ((char *) XLP (a) - LISP_WORD_TAG (type))) */ | 929 | ((char *) XLP (a) - LISP_WORD_TAG (type))) */ |
| 804 | emit_comment ("XUNTAG"); | 930 | emit_comment ("XUNTAG"); |
| 805 | 931 | ||
| 806 | #ifndef WIDE_EMACS_INT | ||
| 807 | return emit_coerce ( | 932 | return emit_coerce ( |
| 808 | gcc_jit_type_get_pointer (type), | 933 | gcc_jit_type_get_pointer (type), |
| 809 | emit_binary_op ( | 934 | emit_binary_op ( |
| 810 | GCC_JIT_BINARY_OP_MINUS, | 935 | GCC_JIT_BINARY_OP_MINUS, |
| 811 | comp.emacs_int_type, | 936 | comp.uintptr_type, |
| 812 | emit_XLI (a), | 937 | emit_XLP (a), |
| 813 | gcc_jit_context_new_rvalue_from_int ( | 938 | emit_rvalue_from_lisp_word_tag(lisp_word_tag))); |
| 814 | comp.ctxt, | ||
| 815 | comp.emacs_int_type, | ||
| 816 | lisp_word_tag))); | ||
| 817 | #else | ||
| 818 | return emit_coerce ( | ||
| 819 | gcc_jit_type_get_pointer (type), | ||
| 820 | emit_binary_op ( | ||
| 821 | GCC_JIT_BINARY_OP_MINUS, | ||
| 822 | comp.unsigned_long_long_type, | ||
| 823 | /* FIXME Should be XLP. */ | ||
| 824 | emit_XLI (a), | ||
| 825 | emit_rvalue_from_long_long (lisp_word_tag))); | ||
| 826 | #endif | ||
| 827 | } | 939 | } |
| 828 | 940 | ||
| 829 | static gcc_jit_rvalue * | 941 | static gcc_jit_rvalue * |
| @@ -850,7 +962,7 @@ emit_EQ (gcc_jit_rvalue *x, gcc_jit_rvalue *y) | |||
| 850 | } | 962 | } |
| 851 | 963 | ||
| 852 | static gcc_jit_rvalue * | 964 | static gcc_jit_rvalue * |
| 853 | emit_TAGGEDP (gcc_jit_rvalue *obj, ptrdiff_t tag) | 965 | emit_TAGGEDP (gcc_jit_rvalue *obj, Lisp_Word_tag tag) |
| 854 | { | 966 | { |
| 855 | /* (! (((unsigned) (XLI (a) >> (USE_LSB_TAG ? 0 : VALBITS)) \ | 967 | /* (! (((unsigned) (XLI (a) >> (USE_LSB_TAG ? 0 : VALBITS)) \ |
| 856 | - (unsigned) (tag)) \ | 968 | - (unsigned) (tag)) \ |
| @@ -1051,17 +1163,7 @@ emit_make_fixnum_LSB_TAG (gcc_jit_rvalue *n) | |||
| 1051 | comp.emacs_int_type, | 1163 | comp.emacs_int_type, |
| 1052 | tmp, comp.lisp_int0); | 1164 | tmp, comp.lisp_int0); |
| 1053 | 1165 | ||
| 1054 | gcc_jit_lvalue *res = gcc_jit_function_new_local (comp.func, | 1166 | return emit_coerce (comp.lisp_obj_type, tmp); |
| 1055 | NULL, | ||
| 1056 | comp.lisp_obj_type, | ||
| 1057 | "lisp_obj_fixnum"); | ||
| 1058 | |||
| 1059 | gcc_jit_block_add_assignment (comp.block, | ||
| 1060 | NULL, | ||
| 1061 | emit_lval_XLI (res), | ||
| 1062 | tmp); | ||
| 1063 | |||
| 1064 | return gcc_jit_lvalue_as_rvalue (res); | ||
| 1065 | } | 1167 | } |
| 1066 | 1168 | ||
| 1067 | static gcc_jit_rvalue * | 1169 | static gcc_jit_rvalue * |
| @@ -1073,10 +1175,8 @@ emit_make_fixnum_MSB_TAG (gcc_jit_rvalue *n) | |||
| 1073 | return XIL (n); | 1175 | return XIL (n); |
| 1074 | */ | 1176 | */ |
| 1075 | 1177 | ||
| 1076 | gcc_jit_rvalue *intmask = | 1178 | gcc_jit_rvalue *intmask = emit_rvalue_from_emacs_uint (INTMASK); |
| 1077 | emit_coerce (comp.emacs_uint_type, | 1179 | |
| 1078 | emit_rvalue_from_long_long ((EMACS_INT_MAX | ||
| 1079 | >> (INTTYPEBITS - 1)))); | ||
| 1080 | n = emit_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND, | 1180 | n = emit_binary_op (GCC_JIT_BINARY_OP_BITWISE_AND, |
| 1081 | comp.emacs_uint_type, | 1181 | comp.emacs_uint_type, |
| 1082 | intmask, n); | 1182 | intmask, n); |
| @@ -1087,12 +1187,10 @@ emit_make_fixnum_MSB_TAG (gcc_jit_rvalue *n) | |||
| 1087 | emit_binary_op (GCC_JIT_BINARY_OP_LSHIFT, | 1187 | emit_binary_op (GCC_JIT_BINARY_OP_LSHIFT, |
| 1088 | comp.emacs_uint_type, | 1188 | comp.emacs_uint_type, |
| 1089 | comp.lisp_int0, | 1189 | comp.lisp_int0, |
| 1090 | gcc_jit_context_new_rvalue_from_int ( | 1190 | emit_rvalue_from_emacs_uint (VALBITS)), |
| 1091 | comp.ctxt, | ||
| 1092 | comp.emacs_uint_type, | ||
| 1093 | VALBITS)), | ||
| 1094 | n); | 1191 | n); |
| 1095 | return emit_XLI (emit_coerce (comp.emacs_int_type, n)); | 1192 | |
| 1193 | return emit_coerce (comp.lisp_obj_type, n); | ||
| 1096 | } | 1194 | } |
| 1097 | 1195 | ||
| 1098 | 1196 | ||
| @@ -1124,17 +1222,10 @@ emit_lisp_obj_rval (Lisp_Object obj) | |||
| 1124 | emit_comment (format_string ("const lisp obj: %s", | 1222 | emit_comment (format_string ("const lisp obj: %s", |
| 1125 | SSDATA (Fprin1_to_string (obj, Qnil)))); | 1223 | SSDATA (Fprin1_to_string (obj, Qnil)))); |
| 1126 | 1224 | ||
| 1127 | if (NIL_IS_ZERO && EQ (obj, Qnil)) | 1225 | if (EQ (obj, Qnil)) |
| 1128 | { | 1226 | { |
| 1129 | gcc_jit_rvalue *n; | 1227 | gcc_jit_rvalue *n; |
| 1130 | #ifdef WIDE_EMACS_INT | 1228 | n = emit_rvalue_from_lisp_word ((Lisp_Word) iQnil); |
| 1131 | eassert (NIL_IS_ZERO); | ||
| 1132 | n = emit_rvalue_from_long_long (0); | ||
| 1133 | #else | ||
| 1134 | n = gcc_jit_context_new_rvalue_from_ptr (comp.ctxt, | ||
| 1135 | comp.void_ptr_type, | ||
| 1136 | NULL); | ||
| 1137 | #endif | ||
| 1138 | return emit_coerce (comp.lisp_obj_type, n); | 1229 | return emit_coerce (comp.lisp_obj_type, n); |
| 1139 | } | 1230 | } |
| 1140 | 1231 | ||
| @@ -1360,16 +1451,7 @@ emit_mvar_rval (Lisp_Object mvar) | |||
| 1360 | { | 1451 | { |
| 1361 | /* We can still emit directly objects that are self-contained in a | 1452 | /* We can still emit directly objects that are self-contained in a |
| 1362 | word (read fixnums). */ | 1453 | word (read fixnums). */ |
| 1363 | gcc_jit_rvalue *word; | 1454 | return emit_rvalue_from_lisp_obj (constant); |
| 1364 | #ifdef WIDE_EMACS_INT | ||
| 1365 | word = emit_rvalue_from_long_long (constant); | ||
| 1366 | #else | ||
| 1367 | word = | ||
| 1368 | gcc_jit_context_new_rvalue_from_ptr (comp.ctxt, | ||
| 1369 | comp.void_ptr_type, | ||
| 1370 | XLP (constant)); | ||
| 1371 | #endif | ||
| 1372 | return emit_coerce (comp.lisp_obj_type, word); | ||
| 1373 | } | 1455 | } |
| 1374 | /* Other const objects are fetched from the reloc array. */ | 1456 | /* Other const objects are fetched from the reloc array. */ |
| 1375 | return emit_lisp_obj_rval (constant); | 1457 | return emit_lisp_obj_rval (constant); |
| @@ -2537,11 +2619,16 @@ define_cast_union (void) | |||
| 2537 | NULL, | 2619 | NULL, |
| 2538 | comp.lisp_cons_ptr_type, | 2620 | comp.lisp_cons_ptr_type, |
| 2539 | "cons_ptr"); | 2621 | "cons_ptr"); |
| 2540 | comp.cast_union_as_lisp_obj = | 2622 | comp.cast_union_as_lisp_word = |
| 2541 | gcc_jit_context_new_field (comp.ctxt, | 2623 | gcc_jit_context_new_field (comp.ctxt, |
| 2542 | NULL, | 2624 | NULL, |
| 2543 | comp.lisp_obj_type, | 2625 | comp.lisp_word_type, |
| 2544 | "lisp_obj"); | 2626 | "lisp_word"); |
| 2627 | comp.cast_union_as_lisp_word_tag = | ||
| 2628 | gcc_jit_context_new_field (comp.ctxt, | ||
| 2629 | NULL, | ||
| 2630 | comp.lisp_word_tag_type, | ||
| 2631 | "lisp_word_tag"); | ||
| 2545 | comp.cast_union_as_lisp_obj_ptr = | 2632 | comp.cast_union_as_lisp_obj_ptr = |
| 2546 | gcc_jit_context_new_field (comp.ctxt, | 2633 | gcc_jit_context_new_field (comp.ctxt, |
| 2547 | NULL, | 2634 | NULL, |
| @@ -2562,7 +2649,8 @@ define_cast_union (void) | |||
| 2562 | comp.cast_union_as_c_p, | 2649 | comp.cast_union_as_c_p, |
| 2563 | comp.cast_union_as_v_p, | 2650 | comp.cast_union_as_v_p, |
| 2564 | comp.cast_union_as_lisp_cons_ptr, | 2651 | comp.cast_union_as_lisp_cons_ptr, |
| 2565 | comp.cast_union_as_lisp_obj, | 2652 | comp.cast_union_as_lisp_word, |
| 2653 | comp.cast_union_as_lisp_word_tag, | ||
| 2566 | comp.cast_union_as_lisp_obj_ptr }; | 2654 | comp.cast_union_as_lisp_obj_ptr }; |
| 2567 | comp.cast_union_type = | 2655 | comp.cast_union_type = |
| 2568 | gcc_jit_context_new_union_type (comp.ctxt, | 2656 | gcc_jit_context_new_union_type (comp.ctxt, |
| @@ -2829,8 +2917,8 @@ define_add1_sub1 (void) | |||
| 2829 | GCC_JIT_COMPARISON_NE, | 2917 | GCC_JIT_COMPARISON_NE, |
| 2830 | n_fixnum, | 2918 | n_fixnum, |
| 2831 | i == 0 | 2919 | i == 0 |
| 2832 | ? emit_most_positive_fixnum () | 2920 | ? emit_rvalue_from_emacs_int (MOST_POSITIVE_FIXNUM) |
| 2833 | : emit_most_negative_fixnum ())), | 2921 | : emit_rvalue_from_emacs_int (MOST_NEGATIVE_FIXNUM))), |
| 2834 | inline_block, | 2922 | inline_block, |
| 2835 | fcall_block); | 2923 | fcall_block); |
| 2836 | 2924 | ||
| @@ -2900,7 +2988,8 @@ define_negate (void) | |||
| 2900 | NULL, | 2988 | NULL, |
| 2901 | GCC_JIT_COMPARISON_NE, | 2989 | GCC_JIT_COMPARISON_NE, |
| 2902 | n_fixnum, | 2990 | n_fixnum, |
| 2903 | emit_most_negative_fixnum ())), | 2991 | emit_rvalue_from_emacs_int ( |
| 2992 | MOST_NEGATIVE_FIXNUM))), | ||
| 2904 | inline_block, | 2993 | inline_block, |
| 2905 | fcall_block); | 2994 | fcall_block); |
| 2906 | 2995 | ||
| @@ -3318,9 +3407,31 @@ DEFUN ("comp--init-ctxt", Fcomp__init_ctxt, Scomp__init_ctxt, | |||
| 3318 | comp.emacs_uint_type = gcc_jit_context_get_int_type (comp.ctxt, | 3407 | comp.emacs_uint_type = gcc_jit_context_get_int_type (comp.ctxt, |
| 3319 | sizeof (EMACS_UINT), | 3408 | sizeof (EMACS_UINT), |
| 3320 | false); | 3409 | false); |
| 3321 | /* No XLP is emitted for now so lets define this always as integer | 3410 | #if LISP_WORDS_ARE_POINTERS |
| 3322 | disregarding LISP_WORDS_ARE_POINTERS value. */ | 3411 | comp.lisp_X_s = gcc_jit_context_new_opaque_struct (comp.ctxt, |
| 3323 | comp.lisp_obj_type = comp.emacs_int_type; | 3412 | NULL, |
| 3413 | "Lisp_X"); | ||
| 3414 | comp.lisp_X = gcc_jit_struct_as_type (comp.lisp_X_s); | ||
| 3415 | comp.lisp_word_type = gcc_jit_type_get_pointer (comp.lisp_X); | ||
| 3416 | #else | ||
| 3417 | comp.lisp_word_type = comp.emacs_int_type; | ||
| 3418 | #endif | ||
| 3419 | comp.lisp_word_tag_type | ||
| 3420 | = gcc_jit_context_get_int_type (comp.ctxt, sizeof (Lisp_Word_tag), false); | ||
| 3421 | #ifdef LISP_OBJECT_IS_STRUCT | ||
| 3422 | comp.lisp_obj_i = gcc_jit_context_new_field (comp.ctxt, | ||
| 3423 | NULL, | ||
| 3424 | comp.lisp_word_type, | ||
| 3425 | "i"); | ||
| 3426 | comp.lisp_obj_s = gcc_jit_context_new_struct_type (comp.ctxt, | ||
| 3427 | NULL, | ||
| 3428 | "Lisp_Object", | ||
| 3429 | 1, | ||
| 3430 | &comp.lisp_obj_i); | ||
| 3431 | comp.lisp_obj_type = gcc_jit_struct_as_type (comp.lisp_obj_s); | ||
| 3432 | #else | ||
| 3433 | comp.lisp_obj_type = comp.lisp_word_type; | ||
| 3434 | #endif | ||
| 3324 | comp.lisp_obj_ptr_type = gcc_jit_type_get_pointer (comp.lisp_obj_type); | 3435 | comp.lisp_obj_ptr_type = gcc_jit_type_get_pointer (comp.lisp_obj_type); |
| 3325 | comp.one = | 3436 | comp.one = |
| 3326 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, | 3437 | gcc_jit_context_new_rvalue_from_int (comp.ctxt, |
diff --git a/src/lisp.h b/src/lisp.h index 893e278afe0..9e4d53ccf17 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -299,12 +299,12 @@ error !; | |||
| 299 | 299 | ||
| 300 | /* Lisp_Word is a scalar word suitable for holding a tagged pointer or | 300 | /* Lisp_Word is a scalar word suitable for holding a tagged pointer or |
| 301 | integer. Usually it is a pointer to a deliberately-incomplete type | 301 | integer. Usually it is a pointer to a deliberately-incomplete type |
| 302 | 'union Lisp_X'. However, it is EMACS_INT when Lisp_Objects and | 302 | 'struct Lisp_X'. However, it is EMACS_INT when Lisp_Objects and |
| 303 | pointers differ in width. */ | 303 | pointers differ in width. */ |
| 304 | 304 | ||
| 305 | #define LISP_WORDS_ARE_POINTERS (EMACS_INT_MAX == INTPTR_MAX) | 305 | #define LISP_WORDS_ARE_POINTERS (EMACS_INT_MAX == INTPTR_MAX) |
| 306 | #if LISP_WORDS_ARE_POINTERS | 306 | #if LISP_WORDS_ARE_POINTERS |
| 307 | typedef union Lisp_X *Lisp_Word; | 307 | typedef struct Lisp_X *Lisp_Word; |
| 308 | #else | 308 | #else |
| 309 | typedef EMACS_INT Lisp_Word; | 309 | typedef EMACS_INT Lisp_Word; |
| 310 | #endif | 310 | #endif |
| @@ -573,6 +573,7 @@ enum Lisp_Fwd_Type | |||
| 573 | 573 | ||
| 574 | #ifdef CHECK_LISP_OBJECT_TYPE | 574 | #ifdef CHECK_LISP_OBJECT_TYPE |
| 575 | typedef struct Lisp_Object { Lisp_Word i; } Lisp_Object; | 575 | typedef struct Lisp_Object { Lisp_Word i; } Lisp_Object; |
| 576 | # define LISP_OBJECT_IS_STRUCT | ||
| 576 | # define LISP_INITIALLY(w) {w} | 577 | # define LISP_INITIALLY(w) {w} |
| 577 | # undef CHECK_LISP_OBJECT_TYPE | 578 | # undef CHECK_LISP_OBJECT_TYPE |
| 578 | enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = true }; | 579 | enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = true }; |