YAP 7.1.0
Tags_64bits.h
1
2/*************************************************************************
3* *
4* YAP Prolog %W% %G% *
5* Yap Prolog was developed at NCCUP - Universidade do Porto *
6* *
7* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8* *
9**************************************************************************
10* *
11* File: Tags_32Ops.h.m4 *
12* Last rev: December 90 *
13* mods: *
14* comments: Original Tag Scheme for machines with 32 bits adresses *
15* version: $Id: Tags_64bits.h,v 1.3 2008-05-15 13:41:46 vsc Exp $ *
16*************************************************************************/
17
18#if SIZEOF_INT_P==8
19
20#define TAG_64BITS 1
21
22/* Version for 64 bit addresses machines,
23 Each term is represented internally as an unsigned 64 bit integer as
24 follows:
25 tag value
26 ints 0m1....001 numeric value
27 atoms 0m0....001 offset of atom entry
28 pairs 0mr....011 ptr to pair
29 aplied functor 0mr....101 ptr to functor followed by args
30 undefined 0mr....000 address of cell pointing to itself
31
32 functors are represented as ptrs to the functor entry in the atom
33property list
34
35 We rely on the fact that addresses are always multiple of 8.
36
37*/
38
39#define SHIFT_HIGH_TAG 61
40
41#define MKTAG(HI,LO) ((((UInt) (HI))<<SHIFT_HIGH_TAG)|(LO))
42
43#define TagBits /* 0x70000007L */ MKTAG(0x7,7)
44#define LowTagBits /* 0x00000007L */ MKTAG(0x0,7)
45#define HighTagBits /* 0x70000000L */ MKTAG(0x7,0)
46#define AdrHiBit /* 0x08000000L */ (((UInt)1) << (SHIFT_HIGH_TAG-3))
47#define MaskPrim /* 0x0ffffff8L */ (((((UInt)1) << (SHIFT_HIGH_TAG-3))-1)<<3)
48#define NumberTag /* 0x30000001L */ MKTAG(0x1,1)
49#define AtomTag /* 0x10000001L */ MKTAG(0x0,1)
50#define MAX_ABS_INT /* 0xfe00000LL */ ((((Int)1) << (63-(3+3)))<<3)
51
52/* bits that should not be used by anyone but us */
53#define YAP_PROTECTED_MASK 0xe000000000000000L
54
55#define UNIQUE_TAG_FOR_PAIRS 1
56
57#define PrimiBit /* 0x00000001L */ 1
58#define PairBits /* 0x00000003L */ 3
59#define ApplBits /* 0x00000005L */ 5
60#define PrimiBits /* 0x70000004L */ MKTAG(0x7,7)
61#define NumberMask /* 0x20000007L */ MKTAG(0x2,7)
62
63#define TagOf(t) (Unsigned(t)&TagBits)
64#define LowTagOf(t) (Unsigned(t)&LowTagBits)
65#define NonTagPart(X) (Signed(X) & MaskPrim)
66#define TAGGEDA(TAG,V) (Unsigned(TAG) | Unsigned(V))
67#define TAGGED(TAG,V) (Unsigned(TAG) | NonTagPart(Unsigned(V)<<3)) /* SQRT(8) */
68#define NONTAGGED(TAG,V) NonTagPart(Unsigned(V)<<3) /* SQRT(8) */
69#define CHKTAG(t,Tag) ((Unsigned(t)&TagBits)==Tag)
70
71#include "inline-only.h"
72INLINE_ONLY int IsVarTerm (Term);
73
74INLINE_ONLY int
75IsVarTerm (Term t)
76{
77 return (int) ((!((t) & 0x1)));
78}
79
80
81
82INLINE_ONLY int
83IsNonVarTerm (Term t)
84{
85 return (int) (((t) & 0x1));
86}
87
88
89
90INLINE_ONLY Term *RepPair (Term);
91
92INLINE_ONLY Term *
93RepPair (Term t)
94{
95 return (Term *) (((t) - PairBits));
96}
97
98
99
100INLINE_ONLY Term AbsPair (Term *);
101
102INLINE_ONLY Term
103AbsPair (Term * p)
104{
105 return (Term) (((CELL) (p) + PairBits));
106}
107
108
109
110INLINE_ONLY Int IsPairTerm (Term);
111
112INLINE_ONLY Int
113IsPairTerm (Term t)
114{
115 return (Int) (((t) & 0x2));
116}
117
118
119
120INLINE_ONLY Term *RepAppl (Term);
121
122INLINE_ONLY Term *
123RepAppl (Term t)
124{
125 return (Term *) (((t) - ApplBits));
126}
127
128
129
130INLINE_ONLY Term AbsAppl (Term *);
131
132INLINE_ONLY Term
133AbsAppl (Term * p)
134{
135 return (Term) (((CELL) (p) + ApplBits));
136}
137
138
139
140INLINE_ONLY Int IsApplTerm (Term);
141
142INLINE_ONLY Int
143IsApplTerm (Term t)
144{
145 return (Int) ((((t) & 0x4)));
146}
147
148
149
150INLINE_ONLY Int IsAtomOrIntTerm (Term);
151
152INLINE_ONLY Int
153IsAtomOrIntTerm (Term t)
154{
155 return (Int) ((((t) & LowTagBits) == 0x1));
156}
157
158
159
160
161INLINE_ONLY Term AdjustPtr (Term t, Term off);
162
163INLINE_ONLY Term
164AdjustPtr (Term t, Term off)
165{
166 return (Term) (((t) + off));
167}
168
169
170
171INLINE_ONLY Term AdjustIDBPtr (Term t, Term off);
172
173INLINE_ONLY Term
174AdjustIDBPtr (Term t, Term off)
175{
176 return (Term) ((t) + off);
177}
178
179
180
181
182INLINE_ONLY Int IntOfTerm (Term);
183
184INLINE_ONLY Int
185IntOfTerm (Term t)
186{
187 return (Int) ((Int) (Unsigned (t) << 3) >> 6);
188}
189
190#endif /* 64 Bits */
191
192