YAP 7.1.0
cp_absmi_insts.h
1#ifdef INDENT_CODE
2{
3 {
4 {
5#endif /* INDENT_CODE */
6
7 /*****************************************************************
8 * Plain try - retry - trust instructions *
9 *****************************************************************/
10 /* try_me Label,NArgs */
11 Op(try_me, Otapl);
12 /* check if enough space between trail and codespace */
13 check_trail(TR);
14 /* I use YREG to go through the choicepoint. Usually YREG is in a
15 * register, but sometimes (X86) not. In this case, have a
16 * new register to point at YREG =*/
17 CACHE_Y(YREG);
18 /* store arguments for procedure */
19 store_at_least_one_arg(PREG->y_u.Otapl.s);
20 /* store abstract machine registers */
21 store_yaam_regs(PREG->y_u.Otapl.d, 0);
22 /* On a try_me, set cut to point at previous choicepoint,
23 * that is, to the B before the cut.
24 */
25 set_cut(S_YREG, B);
26 /* now, install the new YREG =*/
27 B = B_YREG;
28#ifdef YAPOR
29 SCH_set_load(B_YREG);
30#endif /* YAPOR */
31 PREG = NEXTOP(PREG, Otapl);
32 SET_BB(B_YREG);
33 ENDCACHE_Y();
34 GONext();
35 ENDOp();
36
37 /* retry_me Label,NArgs */
38 Op(retry_me, Otapl);
39 CACHE_Y(B);
40 /* After retry, cut should be pointing at the parent
41 * choicepoint for the current B */
42 restore_yaam_regs(PREG->y_u.Otapl.d);
43 restore_at_least_one_arg(PREG->y_u.Otapl.s);
44#ifdef FROZEN_STACKS
45 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
46 set_cut(S_YREG, B->cp_b);
47#else
48 set_cut(S_YREG, B_YREG->cp_b);
49#endif /* FROZEN_STACKS */
50 SET_BB(B_YREG);
51 ENDCACHE_Y();
52 PREG = NEXTOP(PREG, Otapl);
53 GONext();
54 ENDOp();
55
56 /* trust_me UnusedLabel,NArgs */
57 Op(trust_me, Otapl);
58 CACHE_Y(B);
59#ifdef YAPOR
60 if (SCH_top_shared_cp(B)) {
61 SCH_last_alternative(PREG, B_YREG);
62 restore_at_least_one_arg(PREG->y_u.Otapl.s);
63#ifdef FROZEN_STACKS
64 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
65#endif /* FROZEN_STACKS */
66 set_cut(S_YREG, B->cp_b);
67 } else
68#endif /* YAPOR */
69 {
70 pop_yaam_regs();
71 pop_at_least_one_arg(PREG->y_u.Otapl.s);
72/* After trust, cut should be pointing at the new top
73 * choicepoint */
74#ifdef FROZEN_STACKS
75 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
76#endif /* FROZEN_STACKS */
77 set_cut(S_YREG, B);
78 }
79 PREG = NEXTOP(PREG, Otapl);
80 SET_BB(B_YREG);
81 ENDCACHE_Y();
82 GONext();
83 ENDOp();
84
85 /*****************************************************************
86 * EXO try - retry instructions *
87 *****************************************************************/
88 /* enter_exo Pred,Label */
89 BOp(enter_exo, e);
90 {
91 yamop *pt;
92 saveregs();
93 pt = Yap_ExoLookup(PredFromDefCode(PREG) PASS_REGS);
94 setregs();
95#ifdef SHADOW_S
96 SREG = S;
97#endif
98 PREG = pt;
99 }
100 JMPNext();
101 ENDBOp();
102
103 /* check if enough space between trail and codespace */
104 /* try_exo Pred,Label */
105 Op(try_exo, lp);
106 /* check if enough space between trail and codespace */
107 check_trail(TR);
108 /* I use YREG to go through the choicepoint. Usually YREG is in a
109 * register, but sometimes (X86) not. In this case, have a
110 * new register to point at YREG =*/
111 CACHE_Y(YREG);
112 {
113 struct index_t *i = (struct index_t *)(PREG->y_u.lp.l);
114 S_YREG[-1] =
115 (CELL)LINK_TO_ADDRESS(i, i->links[EXO_ADDRESS_TO_OFFSET(i, SREG)]);
116 }
117 S_YREG--;
118 /* store arguments for procedure */
119 store_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
120 /* store abstract machine registers */
121 store_yaam_regs(NEXTOP(PREG, lp), 0);
122 /* On a try_me, set cut to point at previous choicepoint,
123 * that is, to the B before the cut.
124 */
125 set_cut(S_YREG, B);
126 /* now, install the new YREG =*/
127 B = B_YREG;
128#ifdef YAPOR
129 SCH_set_load(B_YREG);
130#endif /* YAPOR */
131 PREG = NEXTOP(NEXTOP(PREG, lp), lp);
132 SET_BB(B_YREG);
133 ENDCACHE_Y();
134 GONext();
135 ENDOp();
136
137 /* check if enough space between trail and codespace */
138 /* try_exo_udi Pred,Label */
139 Op(try_exo_udi, lp);
140 /* check if enough space between trail and codespace */
141 check_trail(TR);
142 /* I use YREG =to go through the choicepoint. Usually YREG =is in a
143 * register, but sometimes (X86) not. In this case, have a
144 * new register to point at YREG =*/
145 CACHE_Y(YREG);
146 S_YREG--;
147 /* store arguments for procedure */
148 store_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
149 /* store abstract machine registers */
150 store_yaam_regs(NEXTOP(PREG, lp), 0);
151 /* On a try_me, set cut to point at previous choicepoint,
152 * that is, to the B before the cut.
153 */
154 set_cut(S_YREG, B);
155 /* now, install the new YREG =*/
156 B = B_YREG;
157#ifdef YAPOR
158 SCH_set_load(B_YREG);
159#endif /* YAPOR */
160 PREG = NEXTOP(NEXTOP(PREG, lp), lp);
161 SET_BB(B_YREG);
162 ENDCACHE_Y();
163 GONext();
164 ENDOp();
165
166 /* try_udi Pred,Label */
167 Op(try_udi, p);
168 /* check if enough space between trail and codespace */
169 check_trail(TR);
170 /* I use YREG =to go through the choicepoint. Usually YREG =is in a
171 * register, but sometimes (X86) not. In this case, have a
172 * new register to point at YREG =*/
173 CACHE_Y(YREG);
174 { S_YREG[-1] = (CELL)SREG; /* the udi code did S = (CELL*)judyp; */ }
175 S_YREG--;
176 /* store arguments for procedure */
177 store_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
178 /* store abstract machine registers */
179 store_yaam_regs(NEXTOP(PREG, lp), 0);
180 /* On a try_me, set cut to point at previous choicepoint,
181 * that is, to the B before the cut.
182 */
183 set_cut(S_YREG, B);
184 /* now, install the new YREG =*/
185 B = B_YREG;
186#ifdef YAPOR
187 SCH_set_load(B_YREG);
188#endif /* YAPOR */
189 PREG = NEXTOP(NEXTOP(PREG, lp), lp);
190 SET_BB(B_YREG);
191 ENDCACHE_Y();
192 GONext();
193 ENDOp();
194
195 /* check if enough space between trail and codespace */
196 /* try_exo Pred,Label */
197 Op(try_all_exo, lp);
198 /* check if enough space between trail and codespace */
199 check_trail(TR);
200 /* I use YREG =to go through the choicepoint. Usually YREG =is in a
201 * register, but sometimes (X86) not. In this case, have a
202 * new register to point at YREG =*/
203 CACHE_Y(YREG);
204 {
205 struct index_t *i = (struct index_t *)(PREG->y_u.lp.l);
206 SREG = i->cls;
207 S_YREG[-2] = (CELL)(SREG + i->arity);
208 S_YREG[-1] = (CELL)(SREG + i->arity * i->nels);
209 }
210 S_YREG -= 2;
211 /* store arguments for procedure */
212 store_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
213 /* store abstract machine registers */
214 store_yaam_regs(NEXTOP(PREG, lp), 0);
215 /* On a try_me, set cut to point at previous choicepoint,
216 * that is, to the B before the cut.
217 */
218 set_cut(S_YREG, B);
219 /* now, install the new YREG =*/
220 B = B_YREG;
221#ifdef YAPOR
222 SCH_set_load(B_YREG);
223#endif /* YAPOR */
224 PREG = NEXTOP(NEXTOP(PREG, lp), lp);
225 SET_BB(B_YREG);
226 ENDCACHE_Y();
227 GONext();
228 ENDOp();
229
230 /* retry_exo Pred */
231 Op(retry_exo, lp);
232 BEGD(d0);
233 CACHE_Y(B);
234 {
235 struct index_t *it = (struct index_t *)(PREG->y_u.lp.l);
236 BITS32 offset =
237 ADDRESS_TO_LINK(it, (BITS32 *)((CELL *)(B + 1))[it->arity]);
238 d0 = it->links[offset];
239 ((CELL *)(B + 1))[it->arity] = (CELL)LINK_TO_ADDRESS(it, d0);
240 SREG = EXO_OFFSET_TO_ADDRESS(it, offset);
241 }
242 if (d0) {
243 /* After retry, cut should be pointing at the parent
244 * choicepoint for the current B */
245 restore_yaam_regs(PREG);
246 restore_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
247#ifdef FROZEN_STACKS
248 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
249 set_cut(S_YREG, B->cp_b);
250#else
251 set_cut(S_YREG, B_YREG->cp_b);
252#endif /* FROZEN_STACKS */
253 SET_BB(B_YREG);
254 } else {
255#ifdef YAPOR
256 if (SCH_top_shared_cp(B)) {
257 SCH_last_alternative(PREG, B_YREG);
258 restore_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
259#ifdef FROZEN_STACKS
260 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
261#endif /* FROZEN_STACKS */
262 set_cut(S_YREG, B->cp_b);
263 } else
264#endif /* YAPOR */
265 {
266 pop_yaam_regs();
267 pop_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
268/* After trust, cut should be pointing at the new top
269 * choicepoint */
270#ifdef FROZEN_STACKS
271 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
272#endif /* FROZEN_STACKS */
273 set_cut(S_YREG, B);
274 }
275 }
276 PREG = NEXTOP(PREG, lp);
277 ENDCACHE_Y();
278 ENDD(D0);
279 GONext();
280 ENDOp();
281
282 /* retry_exo_udi Pred */
283 Op(retry_exo_udi, lp);
284 BEGD(d0);
285 CACHE_Y(B);
286 {
287 struct index_t *it = (struct index_t *)(PREG->y_u.lp.l);
288 saveregs();
289 d0 = ((CRetryExoIndex)it->udi_next)(it PASS_REGS);
290 setregs();
291#ifdef SHADOW_S
292 SREG = S;
293#endif
294 }
295 if (d0) {
296 /* After retry, cut should be pointing at the parent
297 * choicepoint for the current B */
298 restore_yaam_regs(PREG);
299 restore_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
300#ifdef FROZEN_STACKS
301 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
302 set_cut(S_YREG, B->cp_b);
303#else
304 set_cut(S_YREG, B_YREG->cp_b);
305#endif /* FROZEN_STACKS */
306 SET_BB(B_YREG);
307 } else {
308#ifdef YAPOR
309 if (SCH_top_shared_cp(B)) {
310 SCH_last_alternative(PREG, B_YREG);
311 restore_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
312#ifdef FROZEN_STACKS
313 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
314#endif /* FROZEN_STACKS */
315 set_cut(S_YREG, B->cp_b);
316 } else
317#endif /* YAPOR */
318 {
319 pop_yaam_regs();
320 pop_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
321/* After trust, cut should be pointing at the new top
322 * choicepoint */
323#ifdef FROZEN_STACKS
324 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
325#endif /* FROZEN_STACKS */
326 set_cut(S_YREG, B);
327 }
328 }
329 PREG = NEXTOP(PREG, lp);
330 ENDCACHE_Y();
331 ENDD(D0);
332 GONext();
333 ENDOp();
334
335 /* retry_exo Pred */
336 Op(retry_udi, p);
337 BEGD(d0);
338 CACHE_Y(B);
339 {
340 // struct udi_index_t *jp = (struct udi_index_t *)((CELL
341 // *)(B+1))[it->arity];
342 /* operation has a side-effect: S = (CELL*)NextClause */
343 saveregs();
344 d0 = 0L; // Yap_UDI_NextAlt(jp);
345 setregs();
346#ifdef SHADOW_S
347 SREG = S;
348#endif
349 /* d0 says if we're last */
350 }
351 if (d0) {
352 /* After retry, cut should be pointing at the parent
353 * choicepoint for the current B */
354 restore_yaam_regs(PREG);
355 restore_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
356#ifdef FROZEN_STACKS
357 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
358 set_cut(S_YREG, B->cp_b);
359#else
360 set_cut(S_YREG, B_YREG->cp_b);
361#endif /* FROZEN_STACKS */
362 SET_BB(B_YREG);
363 } else {
364#ifdef YAPOR
365 if (SCH_top_shared_cp(B)) {
366 SCH_last_alternative(PREG, B_YREG);
367 restore_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
368#ifdef FROZEN_STACKS
369 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
370#endif /* FROZEN_STACKS */
371 set_cut(S_YREG, B->cp_b);
372 } else
373#endif /* YAPOR */
374 {
375 pop_yaam_regs();
376 pop_at_least_one_arg(PREG->y_u.lp.p->ArityOfPE);
377/* After trust, cut should be pointing at the new top
378 * choicepoint */
379#ifdef FROZEN_STACKS
380 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
381#endif /* FROZEN_STACKS */
382 set_cut(S_YREG, B);
383 }
384 }
385 PREG = (yamop *)SREG;
386 ENDCACHE_Y();
387 ENDD(D0);
388 GONext();
389 ENDOp();
390
391 /* retry_exo Pred */
392 Op(retry_all_exo, lp);
393 BEGD(d0);
394 CACHE_Y(B);
395 {
396 UInt arity = ((struct index_t *)PREG->y_u.lp.l)->arity;
397 CELL *extras = (CELL *)(B + 1);
398 SREG = (CELL *)extras[arity];
399 d0 = (SREG + arity != (CELL *)extras[arity + 1]);
400 if (d0) {
401 extras[arity] = (CELL)(SREG + arity);
402 /* After retry, cut should be pointing at the parent
403 * choicepoint for the current B */
404 restore_yaam_regs(PREG);
405 restore_at_least_one_arg(arity);
406#ifdef FROZEN_STACKS
407 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
408 set_cut(S_YREG, B->cp_b);
409#else
410 set_cut(S_YREG, B_YREG->cp_b);
411#endif /* FROZEN_STACKS */
412 SET_BB(B_YREG);
413 } else {
414#ifdef YAPOR
415 if (SCH_top_shared_cp(B)) {
416 SCH_last_alternative(PREG, B_YREG);
417 restore_at_least_one_arg(arity);
418#ifdef FROZEN_STACKS
419 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
420#endif /* FROZEN_STACKS */
421 set_cut(S_YREG, B->cp_b);
422 } else
423#endif /* YAPOR */
424 {
425 pop_yaam_regs();
426 pop_at_least_one_arg(arity);
427/* After trust, cut should be pointing at the new top
428 * choicepoint */
429#ifdef FROZEN_STACKS
430 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
431#endif /* FROZEN_STACKS */
432 set_cut(S_YREG, B);
433 }
434 }
435 }
436 PREG = NEXTOP(PREG, lp);
437 ENDCACHE_Y();
438 ENDD(D0);
439 GONext();
440 ENDOp();
441
442 /*****************************************************************
443 * Profiled try - retry - trust instructions *
444 *****************************************************************/
445
446 /* profiled_enter_me Pred */
447 Op(enter_profiling, p);
448 LOCK(PREG->y_u.p.p->StatisticsForPred->lock);
449 PREG->y_u.p.p->StatisticsForPred->NOfEntries++;
450 UNLOCK(PREG->y_u.p.p->StatisticsForPred->lock);
451 PREG = NEXTOP(PREG, p);
452 GONext();
453 ENDOp();
454
455 /* profiled_retry Label,NArgs */
456 Op(retry_profiled, p);
457 LOCK(PREG->y_u.p.p->StatisticsForPred->lock);
458 PREG->y_u.p.p->StatisticsForPred->NOfRetries++;
459 UNLOCK(PREG->y_u.p.p->StatisticsForPred->lock);
460 PREG = NEXTOP(PREG, p);
461 GONext();
462 ENDOp();
463
464 /* profiled_retry_me Label,NArgs */
465 Op(profiled_retry_me, Otapl);
466 CACHE_Y(B);
467 /* After retry, cut should be pointing at the parent
468 * choicepoint for the current B */
469 LOCK(PREG->y_u.Otapl.p->StatisticsForPred->lock);
470 PREG->y_u.Otapl.p->StatisticsForPred->NOfRetries++;
471 UNLOCK(PREG->y_u.Otapl.p->StatisticsForPred->lock);
472 restore_yaam_regs(PREG->y_u.Otapl.d);
473 restore_args(PREG->y_u.Otapl.s);
474#ifdef FROZEN_STACKS
475 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
476 set_cut(S_YREG, B->cp_b);
477#else
478 set_cut(S_YREG, B_YREG->cp_b);
479#endif /* FROZEN_STACKS */
480 SET_BB(B_YREG);
481 ENDCACHE_Y();
482 PREG = NEXTOP(PREG, Otapl);
483 GONext();
484 ENDOp();
485
486 /* profiled_trust_me UnusedLabel,NArgs */
487 Op(profiled_trust_me, Otapl);
488 CACHE_Y(B);
489#ifdef YAPOR
490 if (SCH_top_shared_cp(B)) {
491 SCH_last_alternative(PREG, B_YREG);
492 restore_args(PREG->y_u.Otapl.s);
493#ifdef FROZEN_STACKS
494 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
495#endif /* FROZEN_STACKS */
496 set_cut(S_YREG, B->cp_b);
497 } else
498#endif /* YAPOR */
499 {
500 pop_yaam_regs();
501 pop_args(PREG->y_u.Otapl.s);
502/* After trust, cut should be pointing at the new top
503 * choicepoint */
504#ifdef FROZEN_STACKS
505 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
506#endif /* FROZEN_STACKS */
507 set_cut(S_YREG, B);
508 }
509 SET_BB(B_YREG);
510 ENDCACHE_Y();
511 LOCK(PREG->y_u.Otapl.p->StatisticsForPred->lock);
512 PREG->y_u.Otapl.p->StatisticsForPred->NOfRetries++;
513 UNLOCK(PREG->y_u.Otapl.p->StatisticsForPred->lock);
514 PREG = NEXTOP(PREG, Otapl);
515 GONext();
516 ENDOp();
517
518 /*****************************************************************
519 * Call count instructions *
520 *****************************************************************/
521
522 /* count_enter_me Label,NArgs */
523 Op(count_call, p);
524 LOCK(PREG->y_u.p.p->StatisticsForPred->lock);
525 PREG->y_u.p.p->StatisticsForPred->NOfEntries++;
526 UNLOCK(PREG->y_u.p.p->StatisticsForPred->lock);
527 LOCAL_ReductionsCounter--;
528 if (LOCAL_ReductionsCounter == 0 && LOCAL_ReductionsCounterOn) {
529 saveregs();
530 Yap_NilError(CALL_COUNTER_UNDERFLOW_EVENT, "");
531 setregs();
532 JMPNext();
533 }
534 LOCAL_PredEntriesCounter--;
535 if (LOCAL_PredEntriesCounter == 0 && LOCAL_PredEntriesCounterOn) {
536 saveregs();
537 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, "");
538 setregs();
539 JMPNext();
540 }
541 PREG = NEXTOP(PREG, p);
542 GONext();
543 ENDOp();
544
545 /* count_retry Label,NArgs */
546 Op(count_retry, p);
547 LOCK(PREG->y_u.p.p->StatisticsForPred->lock);
548 PREG->y_u.p.p->StatisticsForPred->NOfRetries++;
549 UNLOCK(PREG->y_u.p.p->StatisticsForPred->lock);
550 LOCAL_RetriesCounter--;
551 if (LOCAL_RetriesCounter == 0 && LOCAL_RetriesCounterOn) {
552 /* act as if we had backtracked */
553 ENV = B->cp_env;
554 saveregs();
555 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT, "");
556 setregs();
557 JMPNext();
558 }
559 LOCAL_PredEntriesCounter--;
560 if (LOCAL_PredEntriesCounter == 0 && LOCAL_PredEntriesCounterOn) {
561 ENV = B->cp_env;
562 saveregs();
563 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, "");
564 setregs();
565 JMPNext();
566 }
567 PREG = NEXTOP(PREG, p);
568 GONext();
569 ENDOp();
570
571 /* count_retry_me Label,NArgs */
572 Op(count_retry_me, Otapl);
573 CACHE_Y(B);
574 restore_yaam_regs(PREG->y_u.Otapl.d);
575 restore_args(PREG->y_u.Otapl.s);
576/* After retry, cut should be pointing at the parent
577 * choicepoint for the current B */
578#ifdef FROZEN_STACKS
579 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
580 set_cut(S_YREG, B->cp_b);
581#else
582 set_cut(S_YREG, B_YREG->cp_b);
583#endif /* FROZEN_STACKS */
584 SET_BB(B_YREG);
585 ENDCACHE_Y();
586 LOCK(((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->lock);
587 ((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->NOfRetries++;
588 UNLOCK(((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->lock);
589 LOCAL_RetriesCounter--;
590 if (LOCAL_RetriesCounter == 0 && LOCAL_RetriesCounterOn) {
591 saveregs();
592 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT, "");
593 setregs();
594 JMPNext();
595 }
596 LOCAL_PredEntriesCounter--;
597 if (LOCAL_PredEntriesCounter == 0 && LOCAL_PredEntriesCounterOn) {
598 saveregs();
599 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, "");
600 setregs();
601 JMPNext();
602 }
603 PREG = NEXTOP(PREG, Otapl);
604 GONext();
605 ENDOp();
606
607 /* count_trust_me UnusedLabel,NArgs */
608 Op(count_trust_me, Otapl);
609 CACHE_Y(B);
610#ifdef YAPOR
611 if (SCH_top_shared_cp(B)) {
612 SCH_last_alternative(PREG, B_YREG);
613 restore_args(PREG->y_u.Otapl.s);
614#ifdef FROZEN_STACKS
615 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
616#endif /* FROZEN_STACKS */
617 set_cut(S_YREG, B->cp_b);
618 } else
619#endif /* YAPOR */
620 {
621 pop_yaam_regs();
622 pop_args(PREG->y_u.Otapl.s);
623/* After trust, cut should be pointing at the new top
624 * choicepoint */
625#ifdef FROZEN_STACKS
626 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
627#endif /* FROZEN_STACKS */
628 set_cut(S_YREG, B);
629 }
630 SET_BB(B_YREG);
631 ENDCACHE_Y();
632 LOCAL_RetriesCounter--;
633 if (LOCAL_RetriesCounter == 0) {
634 saveregs();
635 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT, "");
636 setregs();
637 JMPNext();
638 }
639 LOCAL_PredEntriesCounter--;
640 if (LOCAL_PredEntriesCounter == 0) {
641 saveregs();
642 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, "");
643 setregs();
644 JMPNext();
645 }
646 LOCK(((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->lock);
647 ((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->NOfRetries++;
648 UNLOCK(((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->lock);
649 PREG = NEXTOP(PREG, Otapl);
650 GONext();
651 ENDOp();
652
653 /*****************************************************************
654 * check for enough room *
655 *****************************************************************/
656
657 /* ensure_space */
658 BOp(ensure_space, Osbpa);
659 {
660 Int sz = PREG->y_u.Osbpa.i;
661
662 if (Unsigned(HR) + sz > Unsigned(YREG) - StackGap(PASS_REGS1)) {
663 YENV[E_CP] = (CELL)CPREG;
664 YENV[E_E] = (CELL)ENV;
665#ifdef DEPTH_LIMIT
666 YENV[E_DEPTH] = DEPTH;
667#endif /* DEPTH_LIMIT */
668 SET_ASP(YREG, AS_CELLS(PREG->y_u.Osbpa.s));
669 PREG = NEXTOP(PREG, Osbpa);
670 saveregs();
671 if (!Yap_dogcl(sz PASS_REGS1 )) {
672 Yap_NilError(RESOURCE_ERROR_STACK, LOCAL_ErrorMessage);
673 setregs();
674 FAIL();
675 } else {
676 setregs();
677 }
678 } else {
679 PREG = NEXTOP(PREG, Osbpa);
680 }
681 }
682 JMPNext();
683 ENDBOp();
684
685 /*****************************************************************
686 * try and retry of dynamic predicates *
687 *****************************************************************/
688
689 /* spy_or_trymark */
690 BOp(spy_or_trymark, Otapl);
691 PELOCK(5, ((PredEntry *)(PREG->y_u.Otapl.p)));
692 PREG = (yamop *)(&(((PredEntry *)(PREG->y_u.Otapl.p))->OpcodeOfPred));
693 UNLOCKPE(11, (PredEntry *)(PREG->y_u.Otapl.p));
694 saveregs();
695 spy_goal(PASS_REGS1);
696 setregs();
697 ENDBOp();
698
699 /* try_and_mark Label,NArgs */
700 BOp(try_and_mark, Otapl);
701 check_trail(TR);
702#if defined(YAPOR) || defined(THREADS)
703#ifdef YAPOR
704 /* The flags I check here should never change during execution */
705 CUT_wait_leftmost();
706#endif /* YAPOR */
707 if (PREG->y_u.Otapl.p->PredFlags & LogUpdatePredFlag) {
708 PELOCK(6, PREG->y_u.Otapl.p);
709 PP = PREG->y_u.Otapl.p;
710 }
711 if (PREG->y_u.Otapl.p->CodeOfPred != PREG) {
712 /* oops, someone changed the procedure under our feet,
713 fortunately this is no big deal because we haven't done
714 anything yet */
715 PP = NULL;
716 PREG = PREG->y_u.Otapl.p->CodeOfPred;
717 UNLOCKPE(12, PREG->y_u.Otapl.p);
718 /* for profiler */
719 save_pc();
720 JMPNext();
721 }
722#endif
723 CACHE_Y(YREG);
724 PREG = PREG->y_u.Otapl.d;
725 /*
726 I've got a read lock on the DB, so I don't need to care...
727 niaaahh.... niahhhh...
728 */
729 LOCK(DynamicLock(PREG));
730 /* one can now mess around with the predicate */
731 UNLOCKPE(13, ((PredEntry *)(PREG->y_u.Otapl.p)));
732 BEGD(d1);
733 d1 = PREG->y_u.Otapl.s;
734 store_args(d1);
735 store_yaam_regs(PREG, 0);
736 ENDD(d1);
737 set_cut(S_YREG, B);
738 B = B_YREG;
739#ifdef YAPOR
740 SCH_set_load(B_YREG);
741#endif /* YAPOR */
742 SET_BB(B_YREG);
743 ENDCACHE_Y();
744#if MULTIPLE_STACKS
745 INC_CLREF_COUNT(ClauseCodeToDynamicClause(PREG));
746 UNLOCK(DynamicLock(PREG));
747 TRAIL_CLREF(ClauseCodeToDynamicClause(PREG));
748#else
749 if (FlagOff(InUseMask, DynamicFlags(PREG))) {
750
751 SetFlag(InUseMask, DynamicFlags(PREG));
752 TRAIL_CLREF(ClauseCodeToDynamicClause(PREG));
753 }
754#endif
755 PREG = NEXTOP(PREG, Otapl);
756 JMPNext();
757
758 ENDBOp();
759
760 BOp(count_retry_and_mark, Otapl);
761 LOCAL_RetriesCounter--;
762 if (LOCAL_RetriesCounter == 0) {
763 saveregs();
764 Yap_NilError(RETRY_COUNTER_UNDERFLOW_EVENT, "");
765 setregs();
766 JMPNext();
767 }
768 LOCAL_PredEntriesCounter--;
769 if (LOCAL_PredEntriesCounter == 0) {
770 saveregs();
771 Yap_NilError(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, "");
772 setregs();
773 JMPNext();
774 }
775 /* enter a retry dynamic */
776 ENDBOp();
777
778 BOp(profiled_retry_and_mark, Otapl);
779 LOCK(((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->lock);
780 ((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->NOfRetries++;
781 UNLOCK(((PredEntry *)(PREG->y_u.Otapl.p))->StatisticsForPred->lock);
782 /* enter a retry dynamic */
783 ENDBOp();
784
785 /* retry_and_mark Label,NArgs */
786 BOp(retry_and_mark, Otapl);
787#ifdef YAPOR
788 CUT_wait_leftmost();
789#endif /* YAPOR */
790 /* need to make the DB stable until I get the new clause */
791 PELOCK(7, PREG->y_u.Otapl.p);
792 CACHE_Y(B);
793 PREG = PREG->y_u.Otapl.d;
794 LOCK(DynamicLock(PREG));
795 UNLOCK(PREG->y_u.Otapl.p->PELock);
796 restore_yaam_regs(PREG);
797 restore_args(PREG->y_u.Otapl.s);
798#ifdef FROZEN_STACKS
799 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
800 set_cut(S_YREG, B->cp_b);
801#else
802 set_cut(S_YREG, B_YREG->cp_b);
803#endif /* FROZEN_STACKS */
804 SET_BB(B_YREG);
805 ENDCACHE_Y();
806#if MULTIPLE_STACKS
807 INC_CLREF_COUNT(ClauseCodeToDynamicClause(PREG));
808 TRAIL_CLREF(ClauseCodeToDynamicClause(PREG));
809 UNLOCK(DynamicLock(PREG));
810#else
811 if (FlagOff(InUseMask, DynamicFlags(PREG))) {
812
813 SetFlag(InUseMask, DynamicFlags(PREG));
814 TRAIL_CLREF(ClauseCodeToDynamicClause(PREG));
815 }
816#endif
817 PREG = NEXTOP(PREG, Otapl);
818 JMPNext();
819
820 ENDBOp();
821
822 /************************************************************************\
823 * Try / Retry / Trust for main indexing blocks *
824\************************************************************************/
825
826 BOp(try_clause, Otapl);
827 check_trail(TR);
828 CACHE_Y(YREG);
829 /* Point AP to the code that follows this instruction */
830 store_at_least_one_arg(PREG->y_u.Otapl.s);
831 store_yaam_regs(NEXTOP(PREG, Otapl), 0);
832 PREG = PREG->y_u.Otapl.d;
833 set_cut(S_YREG, B);
834 B = B_YREG;
835#ifdef YAPOR
836 SCH_set_load(B_YREG);
837#endif /* YAPOR */
838 SET_BB(B_YREG);
839 ENDCACHE_Y();
840 JMPNext();
841 ENDBOp();
842
843 BOp(try_clause2, l);
844 check_trail(TR);
845 CACHE_Y(YREG);
846 /* Point AP to the code that follows this instruction */
847 {
848 register CELL x2 = ARG2;
849 register CELL x1 = ARG1;
850
851 store_yaam_regs(NEXTOP(PREG, l), 2);
852 B_YREG->cp_a1 = x1;
853 B_YREG->cp_a2 = x2;
854 }
855 PREG = PREG->y_u.l.l;
856 set_cut(S_YREG, B);
857 B = B_YREG;
858#ifdef YAPOR
859 SCH_set_load(B_YREG);
860#endif /* YAPOR */
861 SET_BB(B_YREG);
862 ENDCACHE_Y();
863 JMPNext();
864 ENDBOp();
865
866 BOp(try_clause3, l);
867 check_trail(TR);
868 CACHE_Y(YREG);
869 /* Point AP to the code that follows this instruction */
870 {
871 store_yaam_regs(NEXTOP(PREG, l), 3);
872 B_YREG->cp_a1 = ARG1;
873 B_YREG->cp_a2 = ARG2;
874 B_YREG->cp_a3 = ARG3;
875 }
876 PREG = PREG->y_u.l.l;
877 set_cut(S_YREG, B);
878 B = B_YREG;
879#ifdef YAPOR
880 SCH_set_load(B_YREG);
881#endif /* YAPOR */
882 SET_BB(B_YREG);
883 ENDCACHE_Y();
884 JMPNext();
885 ENDBOp();
886
887 BOp(try_clause4, l);
888 check_trail(TR);
889 CACHE_Y(YREG);
890 /* Point AP to the code that follows this instruction */
891 {
892 store_yaam_regs(NEXTOP(PREG, l), 4);
893 B_YREG->cp_a1 = ARG1;
894 B_YREG->cp_a2 = ARG2;
895 B_YREG->cp_a3 = ARG3;
896 B_YREG->cp_a4 = ARG4;
897 }
898 PREG = PREG->y_u.l.l;
899 set_cut(S_YREG, B);
900 B = B_YREG;
901#ifdef YAPOR
902 SCH_set_load(B_YREG);
903#endif /* YAPOR */
904 SET_BB(B_YREG);
905 ENDCACHE_Y();
906 JMPNext();
907 ENDBOp();
908
909 BOp(retry, Otapl);
910 CACHE_Y(B);
911 restore_yaam_regs(NEXTOP(PREG, Otapl));
912 restore_at_least_one_arg(PREG->y_u.Otapl.s);
913#ifdef FROZEN_STACKS
914 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
915 set_cut(S_YREG, B->cp_b);
916#else
917 set_cut(S_YREG, B_YREG->cp_b);
918#endif /* FROZEN_STACKS */
919 SET_BB(B_YREG);
920 ENDCACHE_Y();
921 PREG = PREG->y_u.Otapl.d;
922 JMPNext();
923 ENDBOp();
924
925 BOp(retry2, l);
926 CACHE_Y(B);
927 restore_yaam_regs(NEXTOP(PREG, l));
928 PREG = PREG->y_u.l.l;
929 ARG1 = B_YREG->cp_a1;
930 ARG2 = B_YREG->cp_a2;
931#ifdef FROZEN_STACKS
932 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
933 set_cut(S_YREG, B->cp_b);
934#else
935 set_cut(S_YREG, B_YREG->cp_b);
936#endif /* FROZEN_STACKS */
937 SET_BB(B_YREG);
938 ENDCACHE_Y();
939 JMPNext();
940 ENDBOp();
941
942 BOp(retry3, l);
943 CACHE_Y(B);
944 restore_yaam_regs(NEXTOP(PREG, l));
945 PREG = PREG->y_u.l.l;
946 ARG1 = B_YREG->cp_a1;
947 ARG2 = B_YREG->cp_a2;
948 ARG3 = B_YREG->cp_a3;
949#ifdef FROZEN_STACKS
950 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
951 set_cut(S_YREG, B->cp_b);
952#else
953 set_cut(S_YREG, B_YREG->cp_b);
954#endif /* FROZEN_STACKS */
955 SET_BB(B_YREG);
956 ENDCACHE_Y();
957 JMPNext();
958 ENDBOp();
959
960 BOp(retry4, l);
961 CACHE_Y(B);
962 restore_yaam_regs(NEXTOP(PREG, l));
963 PREG = PREG->y_u.l.l;
964 ARG1 = B_YREG->cp_a1;
965 ARG2 = B_YREG->cp_a2;
966 ARG3 = B_YREG->cp_a3;
967 ARG4 = B_YREG->cp_a4;
968#ifdef FROZEN_STACKS
969 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
970 set_cut(S_YREG, B->cp_b);
971#else
972 set_cut(S_YREG, B_YREG->cp_b);
973#endif /* FROZEN_STACKS */
974 SET_BB(B_YREG);
975 ENDCACHE_Y();
976 JMPNext();
977 ENDBOp();
978
979 BOp(trust, Otapl);
980 CACHE_Y(B);
981#ifdef YAPOR
982 if (SCH_top_shared_cp(B)) {
983 SCH_last_alternative(PREG, B_YREG);
984 restore_at_least_one_arg(PREG->y_u.Otapl.s);
985#ifdef FROZEN_STACKS
986 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
987#endif /* FROZEN_STACKS */
988 set_cut(S_YREG, B->cp_b);
989 } else
990#endif /* YAPOR */
991 {
992 pop_yaam_regs();
993 pop_at_least_one_arg(PREG->y_u.Otapl.s);
994#ifdef FROZEN_STACKS
995 S_YREG = (CELL *)PROTECT_FROZEN_B(B_YREG);
996#endif /* FROZEN_STACKS */
997 set_cut(S_YREG, B);
998 }
999 SET_BB(B_YREG);
1000 ENDCACHE_Y();
1001 PREG = PREG->y_u.Otapl.d;
1002 JMPNext();
1003 ENDBOp();
1004
1005 BOp(try_in, l);
1006 B->cp_ap = NEXTOP(PREG, l);
1007 PREG = PREG->y_u.l.l;
1008 JMPNext();
1009 ENDBOp();
Definition: Yatom.h:544
Definition: amidefs.h:264