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