add type to BIG NUMs, so that we can easily know what it is all about.

This commit is contained in:
Vítor Santos Costa 2008-11-28 15:54:46 +00:00
parent e8cbc5034e
commit 13dd600f88
14 changed files with 71 additions and 100 deletions

View File

@ -312,9 +312,9 @@ mark_global_cell(CELL *pt)
#endif
case (CELL)FunctorBigInt:
{
Int sz = 2 +
Int sz = 3 +
(sizeof(MP_INT)+
(((MP_INT *)(pt+1))->_mp_alloc*sizeof(mp_limb_t)))/sizeof(CELL);
(((MP_INT *)(pt+2))->_mp_alloc*sizeof(mp_limb_t)))/sizeof(CELL);
return pt + sz;
}
case (CELL)FunctorLongInt:

View File

@ -34,7 +34,7 @@ Term
Yap_MkBigIntTerm(MP_INT *big)
{
Int nlimbs;
MP_INT *dst = (MP_INT *)(H+1);
MP_INT *dst = (MP_INT *)(H+2);
CELL *ret = H;
if (mpz_fits_slong_p(big)) {
@ -46,6 +46,7 @@ Yap_MkBigIntTerm(MP_INT *big)
return TermNil;
}
H[0] = (CELL)FunctorBigInt;
H[1] = BIG_INT;
dst->_mp_size = big->_mp_size;
dst->_mp_alloc = big->_mp_alloc;
@ -59,7 +60,7 @@ Yap_MkBigIntTerm(MP_INT *big)
MP_INT *
Yap_BigIntOfTerm(Term t)
{
MP_INT *new = (MP_INT *)(RepAppl(t)+1);
MP_INT *new = (MP_INT *)(RepAppl(t)+2);
new->_mp_d = (mp_limb_t *)(new+1);
return(new);
@ -98,7 +99,8 @@ p_is_bignum(void)
{
#ifdef USE_GMP
Term t = Deref(ARG1);
return(IsNonVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) == FunctorBigInt);
return(
IsNonVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) == FunctorBigInt);
#else
return FALSE;
#endif

View File

@ -676,7 +676,8 @@ YAP_MkBlobTerm(unsigned int sz)
}
I = AbsAppl(H);
H[0] = (CELL)FunctorBigInt;
dst = (MP_INT *)(H+1);
H[1] = BIG_INT;
dst = (MP_INT *)(H+2);
dst->_mp_size = 0L;
dst->_mp_alloc = sz;
H += (1+sizeof(MP_INT)/sizeof(CELL));

View File

@ -602,13 +602,14 @@ copy_big_int(CELL *st, CELL *pt)
{
Int sz =
sizeof(MP_INT)+
(((MP_INT *)(pt+1))->_mp_alloc*sizeof(mp_limb_t));
(((MP_INT *)(pt+2))->_mp_alloc*sizeof(mp_limb_t));
/* first functor */
st[0] = (CELL)FunctorBigInt;
st[1] = pt[1];
/* then the actual number */
memcpy((void *)(st+1), (void *)(pt+1), sz);
st = st+1+sz/CellSize;
memcpy((void *)(st+2), (void *)(pt+2), sz);
st = st+2+sz/CellSize;
/* then the tail for gc */
st[0] = EndSpecials;
return st+1;
@ -703,7 +704,7 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
continue;
#ifdef USE_GMP
case (CELL)FunctorBigInt:
CheckDBOverflow(2+Yap_SizeOfBigInt(d0));
CheckDBOverflow(3+Yap_SizeOfBigInt(d0));
/* first thing, store a link to the list before we move on */
*StoPoint++ = AbsAppl(CodeMax);
CodeMax = copy_big_int(CodeMax, ap2);

View File

@ -89,7 +89,8 @@ CreateNewArena(CELL *ptr, UInt size)
MP_INT *dst;
ptr[0] = (CELL)FunctorBigInt;
dst = (MP_INT *)(ptr+1);
ptr[1] = EMPTY_ARENA;
dst = (MP_INT *)(ptr+2);
dst->_mp_size = 0L;
dst->_mp_alloc = arena2big_sz(size);
ptr[size-1] = EndSpecials;

View File

@ -467,9 +467,9 @@ AdjustGlobal(long sz)
#if USE_GMP
case (CELL)FunctorBigInt:
{
Int sz = 1+
Int sz = 2+
(sizeof(MP_INT)+
(((MP_INT *)(pt+1))->_mp_alloc*sizeof(mp_limb_t)))/CellSize;
(((MP_INT *)(pt+2))->_mp_alloc*sizeof(mp_limb_t)))/CellSize;
pt += sz;
}
break;

View File

@ -1346,8 +1346,8 @@ mark_variable(CELL_PTR current)
POP_CONTINUATION();
case (CELL)FunctorBigInt:
{
UInt sz = (sizeof(MP_INT)+
((MP_INT *)(next+1))->_mp_alloc*sizeof(mp_limb_t))/CellSize;
UInt sz = (sizeof(MP_INT)+1+
((MP_INT *)(next+2))->_mp_alloc*sizeof(mp_limb_t))/CellSize;
MARK(next);
/* size is given by functor + friends */
if (next < HGEN)

View File

@ -1164,8 +1164,8 @@ SizeOfExtension(Term t)
return 0;
}
if (f== FunctorBigInt) {
CELL *pt = RepAppl(t)+1;
return 2+sizeof(MP_INT)+(((MP_INT *)(pt+1))->_mp_alloc*sizeof(mp_limb_t));
CELL *pt = RepAppl(t)+2;
return 3+sizeof(MP_INT)+(((MP_INT *)(pt))->_mp_alloc*sizeof(mp_limb_t));
}
return 0;
}
@ -1634,8 +1634,8 @@ hash_complex_term(register CELL *pt0,
{
CELL *pt = RepAppl(d0);
Int sz =
sizeof(MP_INT)+
(((MP_INT *)(pt+1))->_mp_alloc*sizeof(mp_limb_t));
sizeof(MP_INT)+1+
(((MP_INT *)(pt+2))->_mp_alloc*sizeof(mp_limb_t));
if (st + (1024 + sz/CellSize) >= ASP) {
goto global_overflow;

View File

@ -537,9 +537,9 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb)
{
MP_INT *big = Yap_BigIntOfTerm(t);
char *s = (char *)TR;
if (s+2+mpz_sizeinbase(big, 10) >= Yap_TrailTop) {
if (s+3+mpz_sizeinbase(big, 10) >= Yap_TrailTop) {
s = (char *)H;
if (s+2+mpz_sizeinbase(big, 10) >= (char *)ASP) {
if (s+3+mpz_sizeinbase(big, 10) >= (char *)ASP) {
return;
}
}

View File

@ -56,6 +56,16 @@ blob_type;
#define FunctorDouble ((Functor)(double_e))
#define EndSpecials (double_e+sizeof(Functor *))
typedef enum
{
BIG_INT = 0x01,
BIG_RATIONAL = 0x02,
BIG_FLOAT = 0x04,
EMPTY_ARENA = 0x10,
ARRAY_INT = 0x21,
ARRAY_FLOAT = 0x22
}
big_blob_type;
inline EXTERN blob_type BlobOfFunctor (Functor f);
@ -87,7 +97,7 @@ typedef struct
/* what to do if someone wants to copy our constraint */
int (*copy_term_op) (CELL *, struct cp_frame **, CELL *);
/* copy the constraint into a term and back */
Term (*to_term_op) (CELL *);
Term (*to_term_op) (CELL *);
int (*term_to_op) (Term, Term);
/* op called to do marking in GC */
void (*mark_op) (CELL *);

View File

@ -1374,7 +1374,7 @@ loop:
return (FALSE);
#ifdef USE_GMP
case (CELL)FunctorBigInt:
if (IsBigIntTerm(d1) && mpz_cmp((MP_INT *)(ap2+1),Yap_BigIntOfTerm(d1)) == 0) continue;
if (IsBigIntTerm(d1) && mpz_cmp((MP_INT *)(ap2+2),Yap_BigIntOfTerm(d1)) == 0) continue;
UNWIND_CUNIF();
return (FALSE);
#endif /* USE_GMP */

@ -1 +1 @@
Subproject commit 293457c65497bf63027c24cf954e6b4965f70df3
Subproject commit 6f4f1a9f182a6ea62de4683ea9f5923ccf20257f

View File

@ -149,7 +149,8 @@ C_SOURCES= \
$(srcdir)/C/corout.c $(srcdir)/C/dbase.c $(srcdir)/C/dlmalloc.c \
$(srcdir)/C/errors.c \
$(srcdir)/C/eval.c $(srcdir)/C/exec.c \
$(srcdir)/C/globals.c $(srcdir)/C/gprof.c $(srcdir)/C/grow.c \
$(srcdir)/C/globals.c $(srcdir)/C/gmp_support.c \
$(srcdir)/C/gprof.c $(srcdir)/C/grow.c \
$(srcdir)/C/heapgc.c $(srcdir)/C/index.c \
$(srcdir)/C/init.c $(srcdir)/C/inlines.c \
$(srcdir)/C/iopreds.c $(srcdir)/C/depth_bound.c \
@ -223,7 +224,7 @@ ENGINE_OBJECTS = \
bignum.o bb.o \
cdmgr.o cmppreds.o compiler.o computils.o \
corout.o cut_c.o dbase.o dlmalloc.o errors.o eval.o \
exec.o globals.o gprof.o grow.o \
exec.o globals.o gmp_support.o gprof.o grow.o \
heapgc.o index.o init.o inlines.o \
iopreds.o depth_bound.o mavar.o \
myddas_mysql.o myddas_odbc.o myddas_shared.o myddas_initialization.o \
@ -343,6 +344,9 @@ exec.o: $(srcdir)/C/exec.c
globals.o: $(srcdir)/C/globals.c
$(CC) -c $(CFLAGS) $(srcdir)/C/globals.c -o $@
gmp_support.o: $(srcdir)/C/gmp_support.c
$(CC) -c $(CFLAGS) $(srcdir)/C/gmp_support.c -o $@
gprof.o: $(srcdir)/C/gprof.c
$(CC) -c $(CFLAGS) $(srcdir)/C/gprof.c -o $@

100
README
View File

@ -1,9 +1,9 @@
README for Yap 5.1
README for Yap6
This directory contains a release of the Yap 5.1.* Prolog system,
This directory contains a release of the Yap 6.0.* Prolog system,
originally developed at the Universidade do Porto by Luis Damas and
Vitor Santos Costa, with contributions from the Edinburgh Prolog
library, the C-Prolog manual authors, Ricardo Lopes, Ricardo Rocha,
@ -12,17 +12,14 @@ Jan Wielemaker, Paul Singleton, Fred Dushin, Jan Wielemaker, Markus
Triska, and many others. You should read the rest of this file for
information on what Yap is and for instructions on how to build it.
YAP 52 is known to build with many versions of gcc (<= gcc-2.7.2, >=
gcc-2.8.1, >= egcs-1.0.1, gcc-2.95.*) and on a variety of Linux,
MacOSX, and Unix'es: SunOS 4.1, Solaris 2.*, Irix 5.2, HP-UX 10.20,
Dec Alpha Unix, Linux 1.2 and Linux 2.* (RedHat 4.0 through 5.2,
Debian 2.*) in both the x86 and alpha platforms. It has been built on
Windows XP using cygwin/mingw from Cygnus Solutions. and on MaxO
YAP 6 has been built with several versions on GCC on a variety of
Linux, MacOSX. It has been built on Windows XP and VISTA using
cygwin/mingw from Cygnus Solutions.
The main core of the YAP distribution is distributed under a dual
license: the Perl Artistic license 2 and the FSF's LGPL. The YAP
distribution also contains files distributed under the LGPL
exclusively, and under the GPL.
exclusively, and under the GPL.
The YAP distribution includes several packages ported to Yap, such as
Pillow, JPL, CLP(R) and CHR. We would like to take the opportunity to
@ -69,7 +66,20 @@ full compatibility, and the manual describes what is still
missing. The manual also includes a (largely incomplete) comparison
with SICStus Prolog.
2. How to compile YAP
2. Obtaining YAP's development sources.
YAP is now being maintained using the git source management system. A
public repository is available at
http://gitorious.org/projects/yap-git
Please use
git clone git://gitorious.org/yap-git/mainline.git
to obtain a copy of the current YAP tree.
3. How to compile YAP
To compile YAP just do:
@ -96,7 +106,7 @@ To compile YAP just do:
In most systems you will need to be superuser in order to do "make
install" and "make info" on the standard directories.
2.1 Where to install Yap
3.1 Where to install Yap
YAP uses autoconf. Recent versions of Yap try to follow GNU
conventions on where to place software. You can use the --prefix
@ -125,7 +135,7 @@ binary Prolog libraries.
o INFODIR is where the info help files will be stored. It defaults
to $(SHAREDIR)/info.
2.2 Which Yap to compile
3.2 Which Yap to compile
Compiling Yap with the standard options give you a plain vanilla
Prolog. You can tune Yap to use extra functionality by using the
@ -155,70 +165,12 @@ supported by one of these three forms. This is still highly experimental.
o --enable-tabling=yes allows tabling support. This is still experimental.
2.3 Porting Yap
3.3 Porting Yap
The system has been mainly tested with GCC, but we have been able to
compile versions of Yap under lcc in Linux, Sun's cc compiler, IBM's
xlc, SGI's cc, HP's cc, and Microsoft's Visual C++ 6.0.
compile older versions of Yap under lcc in Linux, Sun's cc compiler,
IBM's xlc, SGI's cc, HP's cc, and Microsoft's Visual C++ 6.0. Recent
versions of YAP have also been compiled using Intel's lcc.
2.3.1 Yap and GCC
Yap has been developed to take advantage of GCC (but not to depend on
it). The major advantage of GCC is threaded code and register
reservation.
YAP is set by default to compile with the best compilation flags we
know. Even so, a few specific options can be used depending on the
architecture:
2.3.1.1 x86
The flag:
YAP_EXTRAS= ... -DBP_FREE=1
tells us to use the %bp register (frame-pointer) as the emulator's
program counter. This seems to be stable and should become default
real soon now.
2.3.1.2 Sparc/Solaris2
Use:
YAP_EXTRAS= ... -mno-app-regs -DOPTIMISE_ALL_REGS_FOR_SPARC=1
and YAP will get two extra registers! This trick does not work on
SunOS 4 machines.
2.3.1.3 Tuning GCC/Yap for your machine model
Versions of GCC can be tweaked for different processors, eg, 486,
Pentium, PentiumPro, Ultrasparc, Supersparc. Unfortunately, some of
these tweaks do may make Yap run slower or not at all in other machines
with the same instruction set, so they cannot be made default.
The best options also depends on the version of GCC you are using, and
it is a good idea to consult the GCC manual under the menus "Invoking
GCC"/"Submodel Options". We next describe a few:
(a) GCC up to 2.7.*:
o 486:
YAP_EXTRAS= ... -m486 -DBP_FREE=1
to take advantage of 486 specific optimisations in GCC 2.7.*.
o Pentium:
YAP_EXTRAS= ... -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2
o PentiumPros are known not to require alignment.
o Super and UltraSparcs:
YAP_EXTRAS= ... -msupersparc
(b) GCC 2.8.*, EGCS, GCC 2.95.*
o Check -march=XXX for fun.