From a00c69b6f765c4c22f00633ad02cb2972b024c5a Mon Sep 17 00:00:00 2001 From: Costa Vitor Date: Mon, 31 Aug 2009 23:56:00 -0500 Subject: [PATCH 1/5] badly initialised memory stream (obs from J Santos). --- C/iopreds.c | 1 + 1 file changed, 1 insertion(+) diff --git a/C/iopreds.c b/C/iopreds.c index 23f084177..39334f565 100755 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -2831,6 +2831,7 @@ open_buf_write_stream(char *nbuf, UInt sz) st->u.mem_string.pos = 0; st->u.mem_string.buf = nbuf; st->u.mem_string.max_size = sz; + st->u.mem_string.src = MEM_BUF_CODE; return sno; } From 443168227678cac555e92fbcffe95ca756661ad3 Mon Sep 17 00:00:00 2001 From: Costa Vitor Date: Mon, 31 Aug 2009 23:58:05 -0500 Subject: [PATCH 2/5] get rid of unused variable. --- C/amasm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/C/amasm.c b/C/amasm.c index 76116aeb1..47aa525da 100644 --- a/C/amasm.c +++ b/C/amasm.c @@ -280,7 +280,7 @@ STATIC_PROTO(yamop *a_bmap, (yamop *, int, struct PSEUDO *)); STATIC_PROTO(void a_fetch_vv, (cmp_op_info *, int, struct intermediates *)); STATIC_PROTO(void a_fetch_cv, (cmp_op_info *, int, struct intermediates *)); STATIC_PROTO(void a_fetch_vc, (cmp_op_info *, int, struct intermediates *)); -STATIC_PROTO(yamop *a_f2, (int, cmp_op_info *, yamop *, int, struct intermediates *)); +STATIC_PROTO(yamop *a_f2, (cmp_op_info *, yamop *, int, struct intermediates *)); #define CELLSIZE sizeof(CELL) @@ -2471,7 +2471,7 @@ a_fetch_cv(cmp_op_info *cmp_info, int pass_no, struct intermediates *cip) } static yamop * -a_f2(int var, cmp_op_info *cmp_info, yamop *code_p, int pass_no, struct intermediates *cip) +a_f2(cmp_op_info *cmp_info, yamop *code_p, int pass_no, struct intermediates *cip) { Int opc = cip->cpc->rnd2; Ventry *ve = (Ventry *)(cip->cpc->rnd1); @@ -3656,13 +3656,13 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp a_fetch_cv(&cmp_info, pass_no, cip); break; case f_val_op: - code_p = a_f2(FALSE, &cmp_info, code_p, pass_no, cip); + code_p = a_f2(&cmp_info, code_p, pass_no, cip); break; case f_var_op: - code_p = a_f2(TRUE, &cmp_info, code_p, pass_no, cip); + code_p = a_f2(&cmp_info, code_p, pass_no, cip); break; case f_0_op: - code_p = a_f2(TRUE, &cmp_info, code_p, pass_no, cip); + code_p = a_f2(&cmp_info, code_p, pass_no, cip); break; case enter_profiling_op: { From d02c9d23c2b99721f82be05d8013d8cd06cb75ae Mon Sep 17 00:00:00 2001 From: Costa Vitor Date: Mon, 31 Aug 2009 23:59:34 -0500 Subject: [PATCH 3/5] handle cases where test is called with unbound variable. --- C/compiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C/compiler.c b/C/compiler.c index f1e2ee611..c0438667a 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -905,7 +905,7 @@ static void c_test(Int Op, Term t1, compiler_struct *cglobs) { Term t = Deref(t1); - if (!IsVarTerm(t)) { + if (!IsVarTerm(t) || IsNewVar(t)) { Term tn = MkVarTerm(); c_eq(t, tn, cglobs); t = tn; From 5fb3ec05155c23722116b8dd83a1903b4d457c0a Mon Sep 17 00:00:00 2001 From: Costa Vitor Date: Tue, 1 Sep 2009 00:00:08 -0500 Subject: [PATCH 4/5] fix repeated definition for halt. --- pl/control.yap | 2 -- 1 file changed, 2 deletions(-) diff --git a/pl/control.yap b/pl/control.yap index 9bcd2af94..d7d5e3259 100644 --- a/pl/control.yap +++ b/pl/control.yap @@ -268,8 +268,6 @@ version(T) :- fail. '$set_toplevel_hook'(_). -halt(X) :- '$halt'(X). - halt :- print_message(informational, halt), '$halt'(0). From 1e16a9c339ebbd20fc9fc7a48d23ea65e70eadaa Mon Sep 17 00:00:00 2001 From: Costa Vitor Date: Mon, 7 Sep 2009 20:42:19 -0500 Subject: [PATCH 5/5] modern machines do not guarantee sequential consistency. --- OPTYap/x86_locks.h | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/OPTYap/x86_locks.h b/OPTYap/x86_locks.h index b077d7bc9..b599f98c6 100644 --- a/OPTYap/x86_locks.h +++ b/OPTYap/x86_locks.h @@ -13,16 +13,41 @@ ** Atomic lock for X86 ** ** ----------------------------- */ -#define swap(reg,adr) \ -({ \ - char _ret; \ - asm volatile ("xchgb %0,%1" \ - : "=q" (_ret), "=m" (*(adr)) /* Output %0,%1 */ \ - : "m" (*(adr)), "0" (reg)); /* Input (%2),%0 */ \ - _ret; \ -}) +typedef struct { + volatile unsigned int lock; +} spinlock_t; -#define TRY_LOCK(LOCK_VAR) (swap(1,(LOCK_VAR))==0) +static inline int +spin_trylock(spinlock_t *lock) +{ + char tmp = 1; + __asm__ __volatile__( + "xchgb %b0, %1" + : "=q"(tmp), "=m"(lock->lock) + : "0"(tmp) : "memory"); + return tmp == 0; +} + +static inline void +spin_unlock(spinlock_t *lock) +{ + /* To unlock we move 0 to the lock. +* On i386 this needs to be a locked operation +* to avoid Pentium Pro errata 66 and 92. +*/ +#if defined(__x86_64__) + __asm__ __volatile__("" : : : "memory"); + *(unsigned char*)&lock->lock = 0; +#else + char tmp = 0; + __asm__ __volatile__( +"xchgb %b0, %1" +: "=q"(tmp), "=m"(lock->lock) +: "0"(tmp) : "memory"); +#endif +} + +#define TRY_LOCK(LOCK_VAR) spin_trylock((spinlock_t *)(LOCK_VAR)) #define INIT_LOCK(LOCK_VAR) ((LOCK_VAR) = 0) #define LOCK(LOCK_VAR) do { \ @@ -31,7 +56,7 @@ } while (1) #define IS_LOCKED(LOCK_VAR) ((LOCK_VAR) != 0) #define IS_UNLOCKED(LOCK_VAR) ((LOCK_VAR) == 0) -#define UNLOCK(LOCK_VAR) ((LOCK_VAR) = 0) +#define UNLOCK(LOCK_VAR) spin_unlock((spinlock_t *)&(LOCK_VAR)) /* This code has been copied from the sources of the Linux kernel */