2d55abbbcc19839bf2e6348f6a683ffd6c5c123a
[mono.git] / mono / sgen / sgen-tagged-pointer.h
1 /*
2  * sgen-tagged-pointer.h: Macros for tagging and untagging pointers.
3  *
4  * Copyright (C) 2014 Xamarin Inc
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License 2.0 as published by the Free Software Foundation;
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License 2.0 along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #ifndef __MONO_SGEN_TAGGED_POINTER_H__
21 #define __MONO_SGEN_TAGGED_POINTER_H__
22
23 #define SGEN_TAGGED_POINTER_MASK        7
24
25 #define SGEN_POINTER_IS_TAGGED_1(p)     ((mword)(p) & 1)
26 #define SGEN_POINTER_TAG_1(p)           ((void*)((mword)(p) | 1))
27 #define SGEN_POINTER_UNTAG_1(p)         ((void*)((mword)(p) & ~1))
28
29 #define SGEN_POINTER_IS_TAGGED_2(p)     ((mword)(p) & 2)
30 #define SGEN_POINTER_TAG_2(p)           ((void*)((mword)(p) | 2))
31 #define SGEN_POINTER_UNTAG_2(p)         ((void*)((mword)(p) & ~2))
32
33 #define SGEN_POINTER_TAG_12(p)          ((mword)(p) & 3)
34 #define SGEN_POINTER_SET_TAG_12(p,t)    ((void*)(((mword)(p) & ~3) | (t)))
35
36 #define SGEN_POINTER_IS_TAGGED_4(p)     ((mword)(p) & 4)
37 #define SGEN_POINTER_TAG_4(p)           ((void*)((mword)(p) | 4))
38 #define SGEN_POINTER_UNTAG_4(p)         ((void*)((mword)(p) & ~4))
39
40 #define SGEN_POINTER_UNTAG_12(p)        ((void*)((mword)(p) & ~3))
41 #define SGEN_POINTER_UNTAG_24(p)        ((void*)((mword)(p) & ~6))
42
43 #define SGEN_POINTER_IS_TAGGED_ANY(p)   ((mword)(p) & SGEN_TAGGED_POINTER_MASK)
44 #define SGEN_POINTER_UNTAG_ALL(p)       ((void*)((mword)(p) & ~SGEN_TAGGED_POINTER_MASK))
45
46 #endif