aboutsummaryrefslogtreecommitdiffstats
path: root/src/comp.c
diff options
context:
space:
mode:
authorAndrea Corallo2019-06-08 17:24:29 +0200
committerAndrea Corallo2020-01-01 11:33:40 +0100
commit1e9bd1df4c1def12750b2ce6dc335c1921a21686 (patch)
tree112cc9b31f108b7ddbe900cf0157f900a374289d /src/comp.c
parente642113184136a66fee782c3cdec832ec2ba4c0b (diff)
downloademacs-1e9bd1df4c1def12750b2ce6dc335c1921a21686.tar.gz
emacs-1e9bd1df4c1def12750b2ce6dc335c1921a21686.zip
adding sub1
Diffstat (limited to 'src/comp.c')
-rw-r--r--src/comp.c116
1 files changed, 81 insertions, 35 deletions
diff --git a/src/comp.c b/src/comp.c
index c675095cece..e46cd5cfecf 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -475,7 +475,7 @@ compute_bblocks (ptrdiff_t bytestr_length, unsigned char *bytestr_data)
475 bb_start_pc[bb_n++] = op; 475 bb_start_pc[bb_n++] = op;
476 new_bb = true; 476 new_bb = true;
477 break; 477 break;
478 /* Return */ 478 case Bsub1:
479 case Breturn: 479 case Breturn:
480 new_bb = true; 480 new_bb = true;
481 break; 481 break;
@@ -517,21 +517,32 @@ compute_bblocks (ptrdiff_t bytestr_length, unsigned char *bytestr_data)
517 517
518/* Close current basic block emitting a conditional. */ 518/* Close current basic block emitting a conditional. */
519 519
520static gcc_jit_rvalue * 520static void
521comp_emit_conditional (enum gcc_jit_comparison op, 521comp_emit_conditional (enum gcc_jit_comparison op,
522 gcc_jit_rvalue *a, gcc_jit_rvalue *b, 522 gcc_jit_rvalue *test,
523 gcc_jit_block *then_target, gcc_jit_block *else_target) 523 gcc_jit_block *then_target, gcc_jit_block *else_target)
524{ 524{
525 gcc_jit_rvalue *test = gcc_jit_context_new_comparison (comp.ctxt,
526 NULL,
527 op,
528 a, b);
529 gcc_jit_block_end_with_conditional (comp.bblock->gcc_bb, 525 gcc_jit_block_end_with_conditional (comp.bblock->gcc_bb,
530 NULL, 526 NULL,
531 test, 527 test,
532 then_target, 528 then_target,
533 else_target); 529 else_target);
534 comp.bblock->terminated = true; 530 comp.bblock->terminated = true;
531}
532
533/* Close current basic block emitting a comparison between two rval. */
534
535static gcc_jit_rvalue *
536comp_emit_comparison (enum gcc_jit_comparison op,
537 gcc_jit_rvalue *a, gcc_jit_rvalue *b,
538 gcc_jit_block *then_target, gcc_jit_block *else_target)
539{
540 gcc_jit_rvalue *test = gcc_jit_context_new_comparison (comp.ctxt,
541 NULL,
542 op,
543 a, b);
544
545 comp_emit_conditional (op, test, then_target, else_target);
535 546
536 return test; 547 return test;
537} 548}
@@ -830,7 +841,42 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
830 break; 841 break;
831 842
832 case Bsub1: 843 case Bsub1:
833 error ("Bsub1 unsupported bytecode\n"); 844 {
845 gcc_jit_block *sub1_inline =
846 gcc_jit_function_new_block (comp.func, "-1 inline");
847 gcc_jit_block *sub1_fcall =
848 gcc_jit_function_new_block (comp.func, "-1 fcall");
849
850 gcc_jit_rvalue *tos_as_num =
851 gcc_jit_rvalue_access_field (gcc_jit_lvalue_as_rvalue (TOS),
852 NULL,
853 comp.lisp_obj_as_num);
854 comp_emit_comparison (GCC_JIT_COMPARISON_NE,
855 tos_as_num,
856 comp.most_negative_fixnum,
857 sub1_inline, sub1_fcall);
858 gcc_jit_rvalue *sub1_inline_res =
859 gcc_jit_context_new_binary_op (comp.ctxt,
860 NULL,
861 GCC_JIT_BINARY_OP_MINUS,
862 comp.lisp_obj_type,
863 tos_as_num,
864 comp.one);
865 gcc_jit_block_add_assignment (sub1_inline,
866 NULL,
867 TOS,
868 sub1_inline_res);
869
870 /* TODO fill sub1_fcall */
871 /* comp.bblock->gcc_bb = sub1_fcall; */
872 /* comp.bblock->terminated = false; */
873
874 gcc_jit_block_end_with_jump (sub1_inline, NULL,
875 bb_map[pc].gcc_bb);
876 gcc_jit_block_end_with_jump (sub1_fcall, NULL,
877 bb_map[pc].gcc_bb);
878 }
879
834 break; 880 break;
835 case Badd1: 881 case Badd1:
836 error ("Badd1 unsupported bytecode\n"); 882 error ("Badd1 unsupported bytecode\n");
@@ -957,32 +1003,32 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
957 case Bgotoifnil: 1003 case Bgotoifnil:
958 op = FETCH2; 1004 op = FETCH2;
959 POP1; 1005 POP1;
960 comp_emit_conditional (GCC_JIT_COMPARISON_EQ, args[0], nil, 1006 comp_emit_comparison (GCC_JIT_COMPARISON_EQ, args[0], nil,
961 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1007 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
962 break; 1008 break;
963 1009
964 case Bgotoifnonnil: 1010 case Bgotoifnonnil:
965 op = FETCH2; 1011 op = FETCH2;
966 POP1; 1012 POP1;
967 comp_emit_conditional (GCC_JIT_COMPARISON_NE, args[0], nil, 1013 comp_emit_comparison (GCC_JIT_COMPARISON_NE, args[0], nil,
968 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1014 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
969 break; 1015 break;
970 1016
971 case Bgotoifnilelsepop: 1017 case Bgotoifnilelsepop:
972 op = FETCH2; 1018 op = FETCH2;
973 comp_emit_conditional (GCC_JIT_COMPARISON_EQ, 1019 comp_emit_comparison (GCC_JIT_COMPARISON_EQ,
974 gcc_jit_lvalue_as_rvalue (TOS), 1020 gcc_jit_lvalue_as_rvalue (TOS),
975 nil, 1021 nil,
976 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1022 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
977 POP1; 1023 POP1;
978 break; 1024 break;
979 1025
980 case Bgotoifnonnilelsepop: 1026 case Bgotoifnonnilelsepop:
981 op = FETCH2; 1027 op = FETCH2;
982 comp_emit_conditional (GCC_JIT_COMPARISON_NE, 1028 comp_emit_comparison (GCC_JIT_COMPARISON_NE,
983 gcc_jit_lvalue_as_rvalue (TOS), 1029 gcc_jit_lvalue_as_rvalue (TOS),
984 nil, 1030 nil,
985 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1031 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
986 POP1; 1032 POP1;
987 break; 1033 break;
988 1034
@@ -1143,35 +1189,35 @@ compile_f (const char *f_name, ptrdiff_t bytestr_length,
1143 op = FETCH - 128; 1189 op = FETCH - 128;
1144 op += pc; 1190 op += pc;
1145 POP1; 1191 POP1;
1146 comp_emit_conditional (GCC_JIT_COMPARISON_EQ, args[0], nil, 1192 comp_emit_comparison (GCC_JIT_COMPARISON_EQ, args[0], nil,
1147 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1193 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1148 break; 1194 break;
1149 1195
1150 case BRgotoifnonnil: 1196 case BRgotoifnonnil:
1151 op = FETCH - 128; 1197 op = FETCH - 128;
1152 op += pc; 1198 op += pc;
1153 POP1; 1199 POP1;
1154 comp_emit_conditional (GCC_JIT_COMPARISON_NE, args[0], nil, 1200 comp_emit_comparison (GCC_JIT_COMPARISON_NE, args[0], nil,
1155 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1201 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1156 break; 1202 break;
1157 1203
1158 case BRgotoifnilelsepop: 1204 case BRgotoifnilelsepop:
1159 op = FETCH - 128; 1205 op = FETCH - 128;
1160 op += pc; 1206 op += pc;
1161 comp_emit_conditional (GCC_JIT_COMPARISON_EQ, 1207 comp_emit_comparison (GCC_JIT_COMPARISON_EQ,
1162 gcc_jit_lvalue_as_rvalue (TOS), 1208 gcc_jit_lvalue_as_rvalue (TOS),
1163 nil, 1209 nil,
1164 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1210 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1165 POP1; 1211 POP1;
1166 break; 1212 break;
1167 1213
1168 case BRgotoifnonnilelsepop: 1214 case BRgotoifnonnilelsepop:
1169 op = FETCH - 128; 1215 op = FETCH - 128;
1170 op += pc; 1216 op += pc;
1171 comp_emit_conditional (GCC_JIT_COMPARISON_NE, 1217 comp_emit_comparison (GCC_JIT_COMPARISON_NE,
1172 gcc_jit_lvalue_as_rvalue (TOS), 1218 gcc_jit_lvalue_as_rvalue (TOS),
1173 nil, 1219 nil,
1174 bb_map[op].gcc_bb, bb_map[pc].gcc_bb); 1220 bb_map[op].gcc_bb, bb_map[pc].gcc_bb);
1175 POP1; 1221 POP1;
1176 break; 1222 break;
1177 1223
@@ -1397,15 +1443,15 @@ init_comp (void)
1397 lisp_obj_fields); 1443 lisp_obj_fields);
1398 comp.most_positive_fixnum = 1444 comp.most_positive_fixnum =
1399 gcc_jit_context_new_rvalue_from_long (comp.ctxt, 1445 gcc_jit_context_new_rvalue_from_long (comp.ctxt,
1400 comp.long_type, /* FIXME? */ 1446 comp.long_long_type, /* FIXME? */
1401 MOST_POSITIVE_FIXNUM); 1447 MOST_POSITIVE_FIXNUM);
1402 comp.most_negative_fixnum = 1448 comp.most_negative_fixnum =
1403 gcc_jit_context_new_rvalue_from_long (comp.ctxt, 1449 gcc_jit_context_new_rvalue_from_long (comp.ctxt,
1404 comp.long_type, /* FIXME? */ 1450 comp.long_long_type, /* FIXME? */
1405 MOST_NEGATIVE_FIXNUM); 1451 MOST_NEGATIVE_FIXNUM);
1406 comp.one = 1452 comp.one =
1407 gcc_jit_context_new_rvalue_from_int (comp.ctxt, 1453 gcc_jit_context_new_rvalue_from_int (comp.ctxt,
1408 comp.int_type, 1454 comp.long_long_type, /* FIXME? */
1409 1); 1455 1);
1410 1456
1411 enum gcc_jit_types ptrdiff_t_gcc; 1457 enum gcc_jit_types ptrdiff_t_gcc;