27#define MAX_INVOCATION 1024
28#define Yapc_Compile(P) 0
37#define FROZEN_STACKS 1
61#elif defined(_POWER) || defined(__POWERPC__)
65#elif defined(__x86_64__)
75#define LIMITED_PREFETCH 1
77#elif defined(__i386__)
83#define HAVE_FEW_REGS 1
84#define LIMITED_PREFETCH 1
90#if defined(IN_ABSMI_C)
91register struct yami *P1REG
asm(
"bp");
94#define NEEDS_TO_SET_PC 1
109#if defined(__arm__) || defined(__thumb__) || defined(mips) || \
110 defined(__mips64) || defined(__arch64__)
115#define HAVE_FEW_REGS 1
129#if defined(__x86_64__)
135#define HAVE_FEW_REGS 1
144#define USE_PREFETCH 1
160#include "or.macros.h"
162#ifdef USE_SYSTEM_MALLOC
166#include "tab.macros.h"
168#ifdef LOW_LEVEL_TRACER
186INLINE_ONLY
void init_absmi_regs(
REGSTORE *absmi_regs);
190INLINE_ONLY
void init_absmi_regs(
REGSTORE *absmi_regs) {
192 memmove(absmi_regs, &Yap_REGS,
sizeof(
REGSTORE));
195INLINE_ONLY
void restore_absmi_regs(
REGSTORE *old_regs);
197INLINE_ONLY
void restore_absmi_regs(
REGSTORE *old_regs) {
199 memmove(old_regs, Yap_regp,
sizeof(
REGSTORE));
201 pthread_setspecific(Yap_yaamregs_key, (
void *)old_regs);
202 LOCAL_ThreadHandle.current_yaam_regs = old_regs;
215#ifdef LONG_LIVED_REGISTERS
243 register choiceptr TMP
256 register CELL *S_YREG = ((CELL *)(A))
258#define ENDCACHE_Y() \
262#define B_YREG ((choiceptr)(S_YREG))
268#define B_YREG ((choiceptr)(YREG))
274#define ENDCACHE_Y() }
280#define CACHE_Y_AS_ENV(A) \
282 register CELL *ENV_YREG = (A)
284#define FETCH_Y_FROM_ENV(A) ENV_YREG = (A)
286#define WRITEBACK_Y_AS_ENV() YREG = ENV_YREG
288#define ENDCACHE_Y_AS_ENV() }
290#define saveregs_and_ycache() \
294 #define setregs_and_ycache() \
300#define ENV_YREG (YREG)
302#define WRITEBACK_Y_AS_ENV()
304#define CACHE_Y_AS_ENV(A) \
308#define FETCH_Y_FROM_ENV(A) ((YENV) = (A))
310#define ENDCACHE_Y_AS_ENV() }
312#define saveregs_and_ycache() saveregs()
314#define setregs_and_ycache() setregs()
325#define CACHE_TR(A) register tr_fr_ptr S_TR = (A)
327#define RESTORE_TR() TR = S_TR
335 register tr_fr_ptr S_TR = (A)
337#define RESTORE_TR() TR = S_TR
339#define ENDCACHE_TR() }
359 register CELL *S_SREG;
361#define ENDCACHE_S() }
365#define READ_IN_S() S_SREG = SREG
367#define CACHE_A1() {SREG = (CELL *)ARG1; }
369#define CACHED_A1() ((CELL)SREG)
373#define READ_IN_S() S_SREG = *_SREG
375#define CACHE_A1() {(*_SREG) = (CELL *)ARG1; }
377#define CACHED_A1() ((CELL)(*_SREG))
387#define ENDCACHE_S() }
393#define CACHED_A1() (ARG1)
401#define WRITEBACK_S(X) SREG = (X)
405#define WRITEBACK_S(X) *_SREG = (X)
425#define DO_PREFETCH(TYPE)
427#define DO_PREFETCH_W(TYPE)
429#elif USE_THREADED_CODE
435#define DO_PREFETCH(TYPE) \
436 if (ExpEnv.config_struc.current_displacement) \
437 to_go = (void *)OpAddress[Yap_op_from_opcode(NEXTOP(PREG, TYPE)->opc) + \
438 ExpEnv.config_struc.current_displacement]; \
440 to_go = (void *)(NEXTOP(PREG, TYPE)->opc);
442#define DO_PREFETCH_W(TYPE) \
443 if (ExpEnv.config_struc.current_displacement) \
445 (void *)OpAddress[Yap_op_from_opcode(NEXTOP(PREG, TYPE)->y_u.o.opcw) + \
446 ExpEnv.config_struc.current_displacement]; \
448 to_go = (void *)(NEXTOP(PREG, TYPE)->y_u.o.opcw);
452#define DO_PREFETCH(TYPE) to_go = (void *)(NEXTOP(PREG, TYPE)->opc)
454#define DO_PREFETCH_W(TYPE) to_go = (void *)(NEXTOP(PREG, TYPE)->y_u.o.opcw)
460#define DO_PREFETCH(TYPE)
462#define DO_PREFETCH_W(TYPE)
468#if LIMITED_PREFETCH || USE_PREFETCH
470#define ALWAYS_START_PREFETCH(TYPE) \
472 register void *to_go; \
476#define ALWAYS_LOOKAHEAD(WHAT) \
478 register void *to_go; \
479 if (ExpEnv.config_struc.current_displacement) \
480 to_go = (void *)OpAddress[Yap_op_from_opcode(WHAT) + \
481 ExpEnv.config_struc.current_displacement]; \
483 to_go = (void *)(WHAT);
485#define ALWAYS_LOOKAHEAD(WHAT) \
487 register void *to_go = (void *)(WHAT);
490#define ALWAYS_START_PREFETCH_W(TYPE) \
492 register void *to_go; \
497#define ALWAYS_START_PREFETCH(TYPE) {
499#define ALWAYS_START_PREFETCH_W(TYPE) {
501#define ALWAYS_LOOKAHEAD(WHERE) {
507#if LIMITED_PREFETCH || USE_PREFETCH
509#define ALWAYS_START_PREFETCH(TYPE)
511#define ALWAYS_LOOKAHEAD(WHAT)
513#define ALWAYS_START_PREFETCH_W(TYPE)
517#define ALWAYS_START_PREFETCH(TYPE)
519#define ALWAYS_START_PREFETCH_W(TYPE)
521#define ALWAYS_LOOKAHEAD(WHERE)
531#define START_PREFETCH(TYPE) ALWAYS_START_PREFETCH(TYPE)
533#define START_PREFETCH_W(TYPE) ALWAYS_START_PREFETCH_W(TYPE)
535#define INIT_PREFETCH() \
537 register void *to_go;
539#define PREFETCH_OP(X) \
540 if (ExpEnv.config_struc.current_displacement) \
541 to_go = (void *)OpAddress[Yap_op_from_opcode((X)->opc) + \
542 ExpEnv.config_struc.current_displacement]; \
544 to_go = (void *)((X)->opc);
548#define START_PREFETCH(TYPE) {
550#define START_PREFETCH_W(TYPE) {
552#define INIT_PREFETCH() {
554#define PREFETCH_OP(X)
562#define START_PREFETCH(TYPE) ALWAYS_START_PREFETCH(TYPE)
564#define START_PREFETCH_W(TYPE) ALWAYS_START_PREFETCH_W(TYPE)
566#define INIT_PREFETCH()
568#define PREFETCH_OP(X)
572#define START_PREFETCH(TYPE)
574#define START_PREFETCH_W(TYPE)
576#define INIT_PREFETCH()
578#define PREFETCH_OP(X)
588#define ALWAYS_START_PREFETCH(TYPE) {
590#define ALWAYS_START_PREFETCH_W(TYPE) {
592#define ALWAYS_LOOKAHEAD(WHERE) {
594#define START_PREFETCH(TYPE) {
596#define START_PREFETCH_W(TYPE) {
598#define INIT_PREFETCH() {
600#define PREFETCH_OP(X)
604#define ALWAYS_START_PREFETCH(TYPE)
606#define ALWAYS_START_PREFETCH_W(TYPE)
608#define ALWAYS_LOOKAHEAD(WHERE)
610#define START_PREFETCH(TYPE)
612#define START_PREFETCH_W(TYPE)
614#define INIT_PREFETCH()
616#define PREFETCH_OP(X)
624#define ALWAYS_END_PREFETCH() }
626#define ALWAYS_END_PREFETCH_W() }
628#define END_PREFETCH() }
630#define END_PREFETCH_W() }
634#define ALWAYS_END_PREFETCH()
636#define ALWAYS_END_PREFETCH_W()
638#define END_PREFETCH()
640#define END_PREFETCH_W()
654 opcode = Yap_op_from_opcode(goto * Lab); \
658#define JMPNext(Lab) \
660 opcode = Yap_op_from_opcode(PREG->opc) + \
661 ExpEnv.config_struc.current_displacement; \
665#define JMPNextW(Lab) \
667 opcode = Yap_op_from_opcode(PREG->opcw) + \
668 ExpEnv.config_struc.current_displacement; \
672#elif USE_THREADED_CODE
676#define JMP(Lab) goto *Lab
681 if (ExpEnv.config_struc.current_displacement) \
682 JMP((void *)OpAddress[Yap_op_from_opcode(PREG->opc) + \
683 ExpEnv.config_struc.current_displacement]); \
684 JMP((void *)(PREG->opc))
687 if (ExpEnv.config_struc.current_displacement) \
688 JMP((void *)OpAddress[Yap_op_from_opcode(PREG->y_u.o.opcw) + \
689 ExpEnv.config_struc.current_displacement]); \
690 JMP((void *)(PREG->y_u.o.opcw))
694#define JMPNext() JMP((void *)(PREG->opc));
696#define JMPNextW() JMP((void *)(PREG->y_u.o.opcw));
706#define SUCCESSBACK() \
708 if (Yap_op_from_opcode((*_PREG)->opc) == _jit_handler) { \
709 if ((*_PREG)->y_u.jhc.jh->caa.naddress != -1 && \
710 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress] && \
711 NativeArea->area.ok[(*_PREG)->y_u.jhc.jh->caa.naddress]) { \
712 void *(*callee)(yamop **, yamop **, CELL **, void *[], void *[]); \
714 callee = (void *(*)(yamop **, yamop **, CELL **, void *[], void *[])) \
715 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress]; \
716 go = (*callee)(&(*_PREG), &(*_CPREG), &(*_SREG), external_labels, \
721 if ((char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_success != 0 && \
722 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_success != \
724 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
725 fprintf(stderr, "%s", \
726 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_success); \
728 HEADPREG->y_u.jhc.jh->jitman.torecomp = ExpEnv.config_struc.torecompile; \
729 NativeArea->success[HEADPREG->y_u.jhc.jh->caa.naddress] += 1; \
730 (ExpEnv.config_struc.torecompile) \
731 ? (ExpEnv.config_struc.current_displacement = \
732 ExpEnv.config_struc.TOTAL_OF_OPCODES) \
733 : (ExpEnv.config_struc.current_displacement = 0); \
734 if (ExpEnv.config_struc.current_displacement) \
735 return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc) + \
736 ExpEnv.config_struc.current_displacement]); \
737 return ((void *)((*_PREG)->opc)); \
742 if ((char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_fail != 0 && \
743 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_fail != \
745 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
746 fprintf(stderr, "%s", \
747 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_fail); \
749 return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc)]); \
754#define SUCCESSBACK() \
756 if (Yap_op_from_opcode((*_PREG)->opc) == _jit_handler) { \
757 if ((*_PREG)->y_u.jhc.jh->caa.naddress != -1 && \
758 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress] && \
759 NativeArea->area.ok[(*_PREG)->y_u.jhc.jh->caa.naddress]) { \
760 void *(*callee)(yamop **, yamop **, CELL **, void *[], void *[]); \
762 callee = (void *(*)(yamop **, yamop **, CELL **, void *[], void *[])) \
763 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress]; \
764 go = (*callee)(&(*_PREG), &(*_CPREG), &(*_SREG), external_labels, \
769 HEADPREG->y_u.jhc.jh->jitman.torecomp = ExpEnv.config_struc.torecompile; \
770 NativeArea->success[HEADPREG->y_u.jhc.jh->caa.naddress] += 1; \
771 (ExpEnv.config_struc.torecompile) \
772 ? (ExpEnv.config_struc.current_displacement = \
773 ExpEnv.config_struc.TOTAL_OF_OPCODES) \
774 : (ExpEnv.config_struc.current_displacement = 0); \
775 if (ExpEnv.config_struc.current_displacement) \
776 return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc) + \
777 ExpEnv.config_struc.current_displacement]); \
778 return ((void *)((*_PREG)->opc)); \
782 { return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc)]); }
790#define SUCCESSBACK() \
792 if (Yap_op_from_opcode((*_PREG)->opc) == _jit_handler) { \
793 if ((*_PREG)->y_u.jhc.jh->caa.naddress != -1 && \
794 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress] && \
795 NativeArea->area.ok[(*_PREG)->y_u.jhc.jh->caa.naddress]) { \
796 void *(*callee)(yamop **, yamop **, CELL **, void *[], void *[]); \
798 callee = (void *(*)(yamop **, yamop **, CELL **, void *[], void *[])) \
799 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress]; \
800 go = (*callee)(&(*_PREG), &(*_CPREG), &(*_SREG), external_labels, \
805 if ((char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_success != 0 && \
806 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_success != \
808 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
809 fprintf(stderr, "%s", \
810 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_success); \
812 HEADPREG->y_u.jhc.jh->jitman.torecomp = ExpEnv.config_struc.torecompile; \
813 (ExpEnv.config_struc.torecompile) \
814 ? (ExpEnv.config_struc.current_displacement = \
815 ExpEnv.config_struc.TOTAL_OF_OPCODES) \
816 : (ExpEnv.config_struc.current_displacement = 0); \
817 if (ExpEnv.config_struc.current_displacement) \
818 return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc) + \
819 ExpEnv.config_struc.current_displacement]); \
820 return ((void *)((*_PREG)->opc)); \
825 if ((char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_fail != 0 && \
826 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_fail != \
828 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
829 fprintf(stderr, "%s", \
830 (char *)ExpEnv.debug_struc.pprint_me.nativerun_exit_by_fail); \
832 return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc)]); \
837#define SUCCESSBACK() \
839 if (Yap_op_from_opcode((*_PREG)->opc) == _jit_handler) { \
840 if ((*_PREG)->y_u.jhc.jh->caa.naddress != -1 && \
841 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress] && \
842 NativeArea->area.ok[(*_PREG)->y_u.jhc.jh->caa.naddress]) { \
843 void *(*callee)(yamop **, yamop **, CELL **, void *[], void *[]); \
845 callee = (void *(*)(yamop **, yamop **, CELL **, void *[], void *[])) \
846 NativeArea->area.p[(*_PREG)->y_u.jhc.jh->caa.naddress]; \
847 go = (*callee)(&(*_PREG), &(*_CPREG), &(*_SREG), external_labels, \
852 HEADPREG->y_u.jhc.jh->jitman.torecomp = ExpEnv.config_struc.torecompile; \
853 (ExpEnv.config_struc.torecompile) \
854 ? (ExpEnv.config_struc.current_displacement = \
855 ExpEnv.config_struc.TOTAL_OF_OPCODES) \
856 : (ExpEnv.config_struc.current_displacement = 0); \
857 if (ExpEnv.config_struc.current_displacement) \
858 return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc) + \
859 ExpEnv.config_struc.current_displacement]); \
860 return ((void *)((*_PREG)->opc)); \
864 { return ((void *)OpAddress[Yap_op_from_opcode((*_PREG)->opc)]); }
878#if USE_THREADED_CODE && (LIMITED_PREFETCH || USE_PREFETCH)
880#define ALWAYS_GONext() JMP(to_go)
882#define ALWAYS_GONextW() JMP(to_go)
886#define ALWAYS_GONext() JMPNext()
888#define ALWAYS_GONextW() JMPNextW()
894#define GONext() ALWAYS_GONext()
896#define GONextW() ALWAYS_GONextW()
900#define GONext() JMPNext()
902#define GONextW() JMPNextW()
910#define Op(Label, Type) \
912 (ExpEnv.config_struc.current_displacement) \
913 ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \
914 : print_instruction(PREG, ON_INTERPRETER); \
917#define OpW(Label, Type) \
919 (ExpEnv.config_struc.current_displacement) \
920 ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \
921 : print_instruction(PREG, ON_INTERPRETER); \
922 START_PREFETCH_W(Type)
924#define BOp(Label, Type) \
926 (ExpEnv.config_struc.current_displacement) \
927 ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \
928 : print_instruction(PREG, ON_INTERPRETER);
930#define PBOp(Label, Type) \
932 (ExpEnv.config_struc.current_displacement) \
933 ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \
934 : print_instruction(PREG, ON_INTERPRETER); \
937#define OpRW(Label, Type) \
939 (ExpEnv.config_struc.current_displacement) \
940 ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \
941 : print_instruction(PREG, ON_INTERPRETER);
945#define Op(Label, Type) \
947 print_instruction(PREG, ON_INTERPRETER); \
950#define OpW(Label, Type) \
952 print_instruction(PREG, ON_INTERPRETER); \
953 START_PREFETCH_W(Type)
955#define BOp(Label, Type) \
957 print_instruction(PREG, ON_INTERPRETER);
959#define PBOp(Label, Type) \
961 print_instruction(PREG, ON_INTERPRETER); \
964#define OpRW(Label, Type) \
966 print_instruction(PREG, ON_INTERPRETER);
972#define Op(Label, Type) \
976#define OpW(Label, Type) \
978 START_PREFETCH_W(Type)
980#define BOp(Label, Type) \
983#define PBOp(Label, Type) \
987#define OpRW(Label, Type) _##Label : {
993#define JMPNext() goto nextop
995#define JMPNextW() goto nextop_write
997#define GONext() JMPNext()
999#define GONextW() JMPNextW()
1001#define ALWAYS_GONext() GONext()
1003#define ALWAYS_GONextW() GONextW()
1005#define Op(Label, Type) \
1007 START_PREFETCH(Type)
1009#define OpW(Label, Type) \
1011 START_PREFETCH_W(Type)
1013#define BOp(Label, Type) case _##Label: {
1015#define PBOp(Label, Type) \
1019#define OpRW(Label, Type) case _##Label: {
1054#define ADJ(P, x) (P) + ADJUST(sizeof(x))
1061#define pred_entry(X) \
1062 ((PredEntry *)(Unsigned(X) - (CELL)(&(((PredEntry *)NULL)->StateOfPred))))
1063#define pred_entry_from_code(X) \
1064 ((PredEntry *)(Unsigned(X) - (CELL)(&(((PredEntry *)NULL)->CodeOfPred))))
1065#define PredFromDefCode(X) \
1066 ((PredEntry *)(Unsigned(X) - (CELL)(&(((PredEntry *)NULL)->OpcodeOfPred))))
1067#define PredFromExpandCode(X) \
1068 ((PredEntry *)(Unsigned(X) - \
1069 (CELL)(&(((PredEntry *)NULL)->cs.p_code.ExpandCode))))
1070#define PredCode(X) pred_entry(X)->CodeOfPred
1071#define PredOpCode(X) pred_entry(X)->OpcodeOfPred
1072#define TruePredCode(X) pred_entry(X)->TrueCodeOfPred
1073#define PredFunctor(X) pred_entry(X)->FunctorOfPred
1074#define PredArity(X) pred_entry(X)->ArityOfPE
1076#define FlagOff(Mask, w) !(Mask & w)
1077#define FlagOn(Mask, w) (Mask & w)
1078#define ResetFlag(Mask, w) w &= ~Mask
1079#define SetFlag(Mask, w) w |= Mask
1087#if PRECOMPUTE_REGADDRESS
1089#define XREG(I) (*(CELL *)(I))
1093#define XREG(I) XREGS[I]
1099#define SP0 ((CELL *)AuxTop)
1118#define NEEDS_TO_SET_PC 1
1124#ifdef NEEDS_TO_SET_PC
1126#define set_pc() PREG = P
1127#define save_pc() P = PREG
1129#define set_pc() (*_PREG) = P
1130#define save_pc() P = (*_PREG)
1142#define set_y() YREG = YENV
1143#define save_y() YENV = YREG
1155#define set_cp() CPREG = CP
1156#define save_cp() CP = CPREG
1158#define set_cp() (*_CPREG) = CP
1159#define save_cp() CP = (*_CPREG)
1169#define setregs() { \
1175#define saveregs() { \
1184#define always_save_pc() save_pc()
1185#define always_set_pc() set_pc()
1187#define always_save_pc()
1188#define always_set_pc()
1201#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(THREADS) && \
1202 !defined(YAPOR) && !defined(USE_SYSTEM_MALLOC) && !USE_DL_MALLOC
1203#define OS_HANDLES_TR_OVERFLOW 1
1207#ifdef OS_HANDLES_TR_OVERFLOW
1209#define check_trail(x)
1211#define check_trail_in_indexing(x)
1219#define check_trail(x) \
1220 if (__builtin_expect((Unsigned(CurrentTrailTop) < Unsigned(x)), 0)) { \
1221 if ((char *)ExpEnv.debug_struc.pprint_me.native_treat_trail != 0 && \
1222 (char *)ExpEnv.debug_struc.pprint_me.native_treat_trail != \
1224 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
1225 fprintf(stderr, "%s", \
1226 (char *)ExpEnv.debug_struc.pprint_me.native_treat_trail); \
1228 return external_labels[9]; \
1233#define check_trail(x) \
1234 if (__builtin_expect((Unsigned(CurrentTrailTop) < Unsigned(x)), 0)) { \
1235 return external_labels[9]; \
1240#define check_trail_in_indexing(x) \
1241 if (__builtin_expect((Unsigned(CurrentTrailTop) < Unsigned(x)), 0)) \
1242 goto notrailleft_from_index
1248#define check_trail(x) \
1249 if (__builtin_expect((Unsigned(CurrentTrailTop) < Unsigned(x)), 0)) { \
1250 if ((char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_trail != 0 && \
1251 (char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_trail != \
1253 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
1254 fprintf(stderr, "%s", \
1255 (char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_trail); \
1262#define check_trail(x) \
1263 if (__builtin_expect((Unsigned(CurrentTrailTop) < Unsigned(x)), 0)) { \
1269#define check_trail_in_indexing(x) \
1270 if (__builtin_expect((Unsigned(CurrentTrailTop) < Unsigned(x)), 0)) \
1271 goto notrailleft_from_index
1278#if (defined(YAPOR_SBA) && defined(YAPOR)) || defined(TABLING)
1279#define check_stack(Label, GLOB) \
1280 if (__builtin_expect( \
1281 ((Int)(Unsigned(YOUNGEST_CP((choiceptr)ENV_YREG, B_FZ)) - \
1282 Unsigned(YOUNGEST_H(H_FZ, GLOB))) < CreepFlag), \
1284 if ((char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_heap != 0 && \
1285 (char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_heap != \
1287 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
1288 fprintf(stderr, "%s", \
1289 (char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_heap); \
1294#define check_stack(Label, GLOB) \
1295 if (__builtin_expect( \
1296 ((Int)(Unsigned(ENV_YREG) - Unsigned(GLOB)) < CreepFlag), 0)) { \
1297 if ((char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_heap != 0 && \
1298 (char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_heap != \
1300 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
1301 fprintf(stderr, "%s", \
1302 (char *)ExpEnv.debug_struc.pprint_me.interpreted_treat_heap); \
1308#if (defined(YAPOR_SBA) && defined(YAPOR)) || defined(TABLING)
1309#define check_stack(Label, GLOB) \
1310 if (__builtin_expect( \
1311 ((Int)(Unsigned(YOUNGEST_CP((choiceptr)ENV_YREG, B_FZ)) - \
1312 Unsigned(YOUNGEST_H(H_FZ, GLOB))) < CreepFlag), \
1317#define check_stack(Label, GLOB) \
1318 if (__builtin_expect( \
1319 ((Int)(Unsigned(ENV_YREG) - Unsigned(GLOB)) < CreepFlag), 0)) { \
1338#define store_args(arity) \
1340 pt0 = XREGS + (arity); \
1341 while (pt0 > XREGS) { \
1342 register CELL x = pt0[0]; \
1343 S_YREG = S_YREG - 1; \
1349#define store_at_least_one_arg(arity) \
1351 pt0 = XREGS + (arity); \
1354 S_YREG = (S_YREG)-1; \
1357 } while (pt0 > XREGS); \
1360#if LOW_LEVEL_TRACER && 0
1361#define COUNT_CPS() LOCAL_total_choicepoints++
1375#define store_yaam_reg_cpdepth(CPTR) (CPTR)->cp_depth = DEPTH
1377#define store_yaam_reg_cpdepth(CPTR)
1381#define store_yaam_regs(AP, I) \
1384 S_YREG = (CELL *)((choiceptr)((S_YREG) - (I)) - 1); \
1387 B_YREG->cp_tr = TR; \
1388 B_YREG->cp_h = HR; \
1390 store_yaam_reg_cpdepth(B_YREG); \
1391 B_YREG->cp_cp = CPREG; \
1392 B_YREG->cp_ap = AP; \
1393 B_YREG->cp_env = ENV; \
1396#define store_yaam_regs(AP, I) \
1399 S_YREG = (CELL *)((choiceptr)((S_YREG) - (I)) - 1); \
1402 B_YREG->cp_tr = TR; \
1403 B_YREG->cp_h = HR; \
1405 store_yaam_reg_cpdepth(B_YREG); \
1406 B_YREG->cp_cp = (*_CPREG); \
1407 B_YREG->cp_ap = AP; \
1408 B_YREG->cp_env = ENV; \
1412#define store_yaam_regs_for_either(AP, d0) \
1420 store_yaam_reg_cpdepth(pt1); \
1428#define set_cut(E, B) (E)[E_CB] = (CELL)(B)
1435#define restore_yaam_reg_cpdepth(CPTR) DEPTH = (CPTR)->cp_depth
1437#define restore_yaam_reg_cpdepth(CPTR)
1441#define YAPOR_update_alternative(CUR_ALT, NEW_ALT) \
1442 if (SCH_top_shared_cp(B)) { \
1443 SCH_new_alternative(CUR_ALT, NEW_ALT); \
1446#define YAPOR_update_alternative(CUR_ALT, NEW_ALT)
1449#if defined(FROZEN_STACKS) && !defined(BFZ_TRAIL_SCHEME)
1450#define SET_BB(V) BBREG = (V)
1457#define PROTECT_FROZEN_H(CPTR) \
1458 ((Unsigned((Int)((CPTR)->cp_h) - (Int)(H_FZ)) < \
1459 Unsigned((Int)(B_FZ) - (Int)(H_FZ))) \
1462#define PROTECT_FROZEN_B(CPTR) \
1463 ((Unsigned((Int)(CPTR) - (Int)(H_FZ)) < Unsigned((Int)(B_FZ) - (Int)(H_FZ))) \
1474#define PROTECT_FROZEN_B(CPTR) (YOUNGER_CP(CPTR, B_FZ) ? CPTR : B_FZ)
1475#define PROTECT_FROZEN_H(CPTR) (((CPTR)->cp_h > H_FZ) ? (CPTR)->cp_h : H_FZ)
1478#define PROTECT_FROZEN_B(CPTR) (CPTR)
1479#define PROTECT_FROZEN_H(CPTR) (CPTR)->cp_h
1483#define restore_yaam_regs(AP) \
1485 register CELL *x1 = B_YREG->cp_env; \
1486 register yamop *x2; \
1487 HR = HBREG = PROTECT_FROZEN_H(B_YREG); \
1488 restore_yaam_reg_cpdepth(B_YREG); \
1489 CPREG = B_YREG->cp_cp; \
1493 YAPOR_update_alternative(PREG, x2) B_YREG->cp_ap = x2; \
1496#define restore_yaam_regs(AP) \
1498 register CELL *x1 = B_YREG->cp_env; \
1499 register yamop *x2; \
1500 H = HBREG = PROTECT_FROZEN_H(B_YREG); \
1501 restore_yaam_reg_cpdepth(B_YREG); \
1502 (*_CPREG) = B_YREG->cp_cp; \
1506 YAPOR_update_alternative((*_PREG), x2) B_YREG->cp_ap = x2; \
1513#define restore_args(Nargs) \
1518 pt1 = (CELL *)(B_YREG + 1) + d0; \
1519 pt0 = XREGS + 1 + d0; \
1520 while (pt0 > XREGS + 1) { \
1521 register CELL x = pt1[-1]; \
1530#define restore_at_least_one_arg(Nargs) \
1535 pt1 = (CELL *)(B_YREG + 1) + d0; \
1536 pt0 = XREGS + 1 + d0; \
1538 register CELL x = pt1[-1]; \
1542 } while (pt0 > XREGS + 1); \
1551#define pop_yaam_reg_cpdepth(CPTR) DEPTH = (CPTR)->cp_depth
1553#define pop_yaam_reg_cpdepth(CPTR)
1557#define TABLING_close_alt(CPTR) (CPTR)->cp_ap = NULL
1559#define TABLING_close_alt(CPTR)
1563#define pop_yaam_regs() \
1565 HR = PROTECT_FROZEN_H(B_YREG); \
1567 pop_yaam_reg_cpdepth(B_YREG); \
1568 CPREG = B_YREG->cp_cp; \
1569 ENV = B_YREG->cp_env; \
1570 TABLING_close_alt(B_YREG); \
1571 HBREG = PROTECT_FROZEN_H(B); \
1574#define pop_yaam_regs() \
1576 HR = PROTECT_FROZEN_H(B_YREG); \
1578 pop_yaam_reg_cpdepth(B_YREG); \
1579 (*_CPREG) = B_YREG->cp_cp; \
1580 ENV = B_YREG->cp_env; \
1581 TABLING_close_alt(B_YREG); \
1582 HBREG = PROTECT_FROZEN_H(B); \
1586#define pop_args(NArgs) \
1591 S_YREG = (CELL *)(B_YREG + 1); \
1594 while (pt0 < XREGS + 1 + d0) { \
1595 register CELL x = pt1[0]; \
1605#define pop_at_least_one_arg(NArgs) \
1610 pt1 = (CELL *)(B_YREG + 1); \
1613 register CELL x = pt1[0]; \
1617 } while (pt0 < XREGS + 1 + d0); \
1644 if ((char *)ExpEnv.debug_struc.pprint_me.interpreted_backtrack != 0 && \
1645 (char *)ExpEnv.debug_struc.pprint_me.interpreted_backtrack != \
1647 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
1648 fprintf(stderr, "%s", \
1649 (char *)ExpEnv.debug_struc.pprint_me.interpreted_backtrack); \
1654#define TRACED_FAIL() \
1656 if ((char *)ExpEnv.debug_struc.pprint_me.profiled_interpreted_backtrack != \
1658 (char *)ExpEnv.debug_struc.pprint_me.profiled_interpreted_backtrack != \
1660 fprintf(stderr, "%s:%d\n", __FILE__, __LINE__); \
1661 fprintf(stderr, "%s", (char *)ExpEnv.debug_struc.pprint_me \
1662 .profiled_interpreted_backtrack); \
1672#define TRACED_FAIL() \
1673 { goto traced_fail; }
1680 { return external_labels[0]; }
1690#define UnifyGlobalCells(a, b) \
1692 if (GlobalIsAttVar(b) && !GlobalIsAttVar(a)) { \
1693 Bind_Global((a), (CELL)(b)); \
1695 Bind_Global((b), (CELL)(a)); \
1697 } else if ((b) < (a)) { \
1698 if (GlobalIsAttVar(a) && !GlobalIsAttVar(b)) { \
1699 Bind_Global((b), (CELL)(a)); \
1701 Bind_Global((a), (CELL)(b)); \
1705#define UnifyGlobalCellToCell(b, a) \
1707 UnifyGlobalCells(a, b); \
1709 Bind_Local((a), (CELL)(b)); \
1712#define UnifyCells(a, b) \
1715 Bind_Local((b), (CELL)(a)); \
1717 UnifyGlobalCells(a, b); \
1721 Bind_Local((a), (CELL)(b)); \
1722 } else if ((a) > (b)) { \
1724 Bind_Local((a), (CELL)(b)); \
1726 Bind_Local((b), (CELL)(a)); \
1742#ifdef RATIONAL_TREES
1744#define UNWIND_CUNIF() \
1745 while (visited < AuxSp) { \
1746 pt1 = (CELL *)visited[0]; \
1747 *pt1 = visited[1]; \
1752#define UNWIND_CUNIF()
1755#define UnifyBound_TEST_ATTACHED(f, d0, pt0, d1) \
1756 if (IsExtensionFunctor(f)) { \
1757 if (unify_extension(f, d0, RepAppl(d0), d1)) { \
1764#define UnifyBound(d0, d1) \
1768 if (IsPairTerm(d0)) { \
1769 register CELL *ipt0, *ipt1; \
1770 if (!IsPairTerm(d1)) { \
1773 ipt0 = RepPair(d0); \
1774 ipt1 = RepPair(d1); \
1777 if (IUnify_complex(ipt0 - 1, ipt0 + 1, ipt1 - 1)) { \
1783 } else if (IsApplTerm(d0)) { \
1784 register CELL *ipt0, *ipt1; \
1785 register Functor f; \
1786 if (!IsApplTerm(d1)) { \
1789 ipt0 = RepAppl(d0); \
1790 ipt1 = RepAppl(d1); \
1791 f = (Functor)*ipt0; \
1792 if (f != (Functor)*ipt1) { \
1795 UnifyBound_TEST_ATTACHED(f, d0, ipt0, d1); \
1796 d0 = ArityOfFunctor(f); \
1799 if (IUnify_complex(ipt0, ipt0 + d0, ipt1)) { \
1809#define traced_UnifyBound_TEST_ATTACHED(f, d0, pt0, d1) \
1810 if (IsExtensionFunctor(f)) { \
1811 if (unify_extension(f, d0, RepAppl(d0), d1)) { \
1818#define traced_UnifyBound(d0, d1) \
1822 if (IsPairTerm(d0)) { \
1823 register CELL *ipt0, *ipt1; \
1824 if (!IsPairTerm(d1)) { \
1827 ipt0 = RepPair(d0); \
1828 ipt1 = RepPair(d1); \
1831 if (IUnify_complex(ipt0 - 1, ipt0 + 1, ipt1 - 1)) { \
1837 } else if (IsApplTerm(d0)) { \
1838 register CELL *ipt0, *ipt1; \
1839 register Functor f; \
1840 if (!IsApplTerm(d1)) { \
1843 ipt0 = RepAppl(d0); \
1844 ipt1 = RepAppl(d1); \
1845 f = (Functor)*ipt0; \
1846 if (f != (Functor)*ipt1) { \
1849 traced_UnifyBound_TEST_ATTACHED(f, d0, ipt0, d1); \
1850 d0 = ArityOfFunctor(f); \
1853 if (IUnify_complex(ipt0, ipt0 + d0, ipt1)) { \
1868#define set_hb() HBREG = HB
1869#define save_hb() HB = HBREG
1887#if defined(IN_ABSMI_C) || defined(IN_UNIFY_C) || defined(IN_TRACED_ABSMI_C)
1889static int IUnify_complex(CELL *pt0, CELL *pt0_end, CELL *pt1) {
1893 register REGSTORE *regp = Yap_regp;
1894#define Yap_REGS (*regp)
1895#elif defined(SHADOW_REGS)
1896#if defined(B) || defined(TR)
1897 register REGSTORE *regp = &Yap_REGS;
1899#define Yap_REGS (*regp)
1904 register CELL *HBREG = HB;
1909#define unif_base ((struct unif_record *)AuxBase)
1910#define tovisit_base ((struct v_record *)AuxSp)
1913 while (pt0 < pt0_end) {
1914 register CELL *ptd0 = pt0 + 1;
1920 deref_head(d0, unify_comp_unk);
1922 register CELL *ptd1 = pt1;
1923 register CELL d1 = *ptd1;
1925 deref_head(d1, unify_comp_nvar_unk);
1926 unify_comp_nvar_nvar:
1929 if (IsPairTerm(d0)) {
1930 if (!IsPairTerm(d1)) {
1936 if (RATIONAL_TREES || pt0 < pt0_end) {
1938#ifdef RATIONAL_TREES
1941 if ((
void *)tovisit < (
void *)unif) {
1942 CELL **urec = (CELL **)unif;
1943 tovisit = (
struct v_record *)Yap_shift_visit((CELL **)tovisit,
1947 tovisit->start0 = pt0;
1948 tovisit->end0 = pt0_end;
1949 tovisit->start1 = pt1;
1950#ifdef RATIONAL_TREES
1951 unif[-1].old = *pt0;
1956 pt0_end = (pt0 = RepPair(d0) - 1) + 2;
1957 pt1 = RepPair(d1) - 1;
1960 if (IsApplTerm(d0)) {
1962 register CELL *ap2, *ap3;
1964 if (!IsApplTerm(d1)) {
1974 if (IsExtensionFunctor(f)) {
1975 if (unify_extension(f, d0, ap2, d1))
1982 if (RATIONAL_TREES || pt0 < pt0_end) {
1984#ifdef RATIONAL_TREES
1987 if ((
void *)tovisit < (
void *)unif) {
1988 CELL **urec = (CELL **)unif;
1989 tovisit = (
struct v_record *)Yap_shift_visit((CELL **)tovisit,
1993 tovisit->start0 = pt0;
1994 tovisit->end0 = pt0_end;
1995 tovisit->start1 = pt1;
1996#ifdef RATIONAL_TREES
1997 unif[-1].old = *pt0;
2002 d0 = ArityOfFunctor(f);
2010 derefa_body(d1, ptd1, unify_comp_nvar_unk, unify_comp_nvar_nvar);
2012 Bind_Global(ptd1, d0);
2016 derefa_body(d0, ptd0, unify_comp_unk, unify_comp_nvar);
2020 register CELL *ptd1;
2025 deref_head(d1, unify_comp_var_unk);
2026 unify_comp_var_nvar:
2028 Bind_Global(ptd0, d1);
2031 derefa_body(d1, ptd1, unify_comp_var_unk, unify_comp_var_nvar);
2033 UnifyGlobalCells(ptd0, ptd1);
2037 if (tovisit < tovisit_base) {
2038 pt0 = tovisit->start0;
2039 pt0_end = tovisit->end0;
2040 pt1 = tovisit->start1;
2044#ifdef RATIONAL_TREES
2046 while (unif-- != unif_base) {
2056#ifdef RATIONAL_TREES
2058 while (unif-- != unif_base) {
2068#define Yap_REGS (*Yap_regp)
2069#elif defined(SHADOW_REGS)
2070#if defined(B) || defined(TR)
2085static int iequ_complex(
register CELL *pt0,
register CELL *pt0_end,
2086 register CELL *pt1) {
2090 register REGSTORE *regp = Yap_regp;
2091#define Yap_REGS (*regp)
2092#elif defined(SHADOW_REGS)
2093#if defined(B) || defined(TR)
2094 register REGSTORE *regp = &Yap_REGS;
2096#define Yap_REGS (*regp)
2101 register CELL *HBREG = HB;
2106#define unif_base ((struct unif_record *)AuxBase)
2107#define tovisit_base ((struct v_record *)AuxSp)
2110 while (pt0 < pt0_end) {
2111 register CELL *ptd0 = pt0 + 1;
2117 deref_head(d0, iequ_comp_unk);
2119 register CELL *ptd1 = pt1;
2120 register CELL d1 = *ptd1;
2122 deref_head(d1, iequ_comp_nvar_unk);
2123 iequ_comp_nvar_nvar:
2126 if (IsPairTerm(d0)) {
2127 if (!IsPairTerm(d1)) {
2135 if ((
void *)tovisit < (
void *)unif) {
2136 CELL **urec = (CELL **)unif;
2137 tovisit = (
struct v_record *)Yap_shift_visit((CELL **)tovisit,
2141 tovisit->start0 = pt0;
2142 tovisit->end0 = pt0_end;
2143 tovisit->start1 = pt1;
2146 unif[-1].old = *pt0;
2150 pt0_end = (pt0 = RepPair(d0) - 1) + 2;
2151 pt1 = RepPair(d1) - 1;
2154 if (IsApplTerm(d0)) {
2156 register CELL *ap2, *ap3;
2158 if (!IsApplTerm(d1)) {
2168 if (IsExtensionFunctor(f)) {
2169 if (unify_extension(f, d0, ap2, d1))
2178 if ((
void *)tovisit < (
void *)unif) {
2179 CELL **urec = (CELL **)unif;
2180 tovisit = (
struct v_record *)Yap_shift_visit((CELL **)tovisit,
2184 tovisit->start0 = pt0;
2185 tovisit->end0 = pt0_end;
2186 tovisit->start1 = pt1;
2187 unif[-1].old = *pt0;
2190 d0 = ArityOfFunctor(f);
2198 derefa_body(d1, ptd1, iequ_comp_nvar_unk, iequ_comp_nvar_nvar);
2201 derefa_body(d0, ptd0, iequ_comp_unk, iequ_comp_nvar);
2205 register CELL *ptd1;
2210 deref_head(d1, iequ_comp_var_unk);
2215 derefa_body(d1, ptd1, iequ_comp_var_unk, iequ_comp_var_nvar);
2225 if (tovisit < tovisit_base) {
2226 pt0 = tovisit->start0;
2227 pt0_end = tovisit->end0;
2228 pt1 = tovisit->start1;
2234 while (unif-- != unif_base) {
2243#ifdef RATIONAL_TREES
2245 while (unif-- != unif_base) {
2255#define Yap_REGS (*Yap_regp)
2256#elif defined(SHADOW_REGS)
2257#if defined(B) || defined(TR)
2265static inline wamreg Yap_regnotoreg(UInt regnbr) {
2266#if PRECOMPUTE_REGADDRESS
2267 return (wamreg)(XREGS + regnbr);
2272 return CELLSIZE * regnbr;
2277static inline UInt Yap_regtoregno(wamreg reg) {
2278#if PRECOMPUTE_REGADDRESS
2279 return ((CELL *)reg) - XREGS;
2284 return reg / CELLSIZE;
2290#define check_depth(DEPTH, ap) \
2291 if ((DEPTH) <= MkIntTerm(1)) { \
2292 if ((ap)->ModuleOfPred) { \
2293 if ((DEPTH) == MkIntTerm(0)) { \
2296 (DEPTH) = RESET_DEPTH(); \
2298 } else if ((ap)->ModuleOfPred) \
2299 (DEPTH) -= MkIntConstant(2);
2301#define check_depth(DEPTH, ap)
2304#if defined(THREADS) || defined(YAPOR)
2305#define copy_jmp_address(X) (PREG_ADDR = &(X))
2306#define copy_jmp_addressa(X) (PREG_ADDR = (yamop **)(X))
2308#define copy_jmp_address(X)
2309#define copy_jmp_addressa(X)
2312static inline void prune(
choiceptr cp USES_REGS) {
2318 if (SHOULD_CUT_UP_TO(B, cp)) {
2319 if (ASP > (CELL *)PROTECT_FROZEN_B(B))
2320 ASP = (CELL *)PROTECT_FROZEN_B(B);
2321 while (B->cp_b < cp) {
2322 if (B->cp_b == NULL)
2328 abolish_incomplete_subgoals(B);
2330 HB = PROTECT_FROZEN_H(B->cp_b);
2331#include "trim_trail.h"
2333 SET_BB(PROTECT_FROZEN_B(B));
2338#define INITIALIZE_PERMVAR(PTR, V) Bind_Local((PTR), (V))
2340#define INITIALIZE_PERMVAR(PTR, V) *(PTR) = (V)
2344#define UnifyAndTrailCells(a, b) \
2348 DO_TRAIL((a), (CELL)(b)); \
2349 } else if ((b) <= HR) { \
2351 DO_TRAIL((a), (CELL)(b)); \
2354 DO_TRAIL((b), (CELL)(a)); \
2356 } else if ((a) < (b)) { \
2359 DO_TRAIL((b), (CELL)(a)); \
2360 } else if ((a) <= HR) { \
2362 DO_TRAIL((b), (CELL)(a)); \
2365 DO_TRAIL((a), (CELL)(b)); \
2369#define CHECK_ALARM(CONT)
2372#include <sys/time.h>
2374#if HAVE_SYS_RESOURCE_H
2375#include <sys/resource.h>
2380extern Environment ExpEnv;
2381extern char fin[1024];
2388#include "JIT_Compiler.hpp"
2390void *(*Yap_JitCall)(JIT_Compiler *jc,
yamop *p);
2391void (*Yap_llvmShutdown)(void);
2392Int (*Yap_traced_absmi)(void);
2393extern JIT_Compiler *J;
2397extern NativeContext *NativeArea;
2398extern IntermediatecodeContext *IntermediatecodeArea;
2403extern yamop *HEADPREG;
2405extern CELL BLOCKADDRESS;
2408extern TraceContext **curtrace;
2409extern yamop *curpreg;
2410extern BlocksContext **globalcurblock;
2411extern COUNT ineedredefinedest;
2412extern yamop *headoftrace;
2418#define PROCESS_INT(F, C) \
2420 Yap_REGS.S_ = SREG; \
2422 d0 = F(PASS_REGS1); \
2424 SREG = Yap_REGS.S_; \
2432#define PROCESS_INT(F, C) \
2435 int rc= F(PASS_REGS1); \
2447#define INT_HANDLER_GO_ON -1
2448#define INT_HANDLER_FAIL 0
2449#define INT_HANDLER_RET_NEXT 1
2450#define INT_HANDLER_RET_JMP 2
2451#define HAS_INT(D) (D>=0)
2454#define PROCESS_INTERRUPTED_PRUNE(F) \
2457 PREG = P = F(PASS_REGS1); \
2464#define Yap_AsmError(e, d) \
2467 Yap_ThrowError(e, d, "while executing inlined built-in"); \