Generated on for Gecode by doxygen 1.17.0
marked-pointer.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2008
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <cstddef>
35#include <limits>
36
37namespace Gecode { namespace Support {
38
40 bool marked(void* p);
42 void* mark(void* p);
44 void* unmark(void* p);
46 void* fmark(void* p);
48 template<unsigned int bits = 1>
49 void* funmark(void* p);
51 void* ptrsplit(void* p, ptrdiff_t& m);
53 void* ptrjoin(void* p, ptrdiff_t m);
54
55 forceinline bool
56 marked(void* p) {
57 return (reinterpret_cast<uptrint_t>(p) & 0b1) != 0;
58 }
59 forceinline void*
60 mark(void* p) {
61 assert(!marked(p));
62 return reinterpret_cast<void*>(reinterpret_cast<uptrint_t>(p) | 0b1);
63 }
64 forceinline void*
65 unmark(void* p) {
66 assert(marked(p));
67 return funmark(p);
68 }
69 forceinline void*
70 fmark(void* p) {
71 return reinterpret_cast<void*>(reinterpret_cast<uptrint_t>(p) | 0b1);
72 }
73 template<unsigned int bits>
74 forceinline void*
75 funmark(void* p) {
76 static_assert(bits < std::numeric_limits<uptrint_t>::digits,
77 "Too many pointer tag bits");
78 return reinterpret_cast<void*>(reinterpret_cast<uptrint_t>(p)&
79 ~((static_cast<uptrint_t>(1) << bits)-1));
80 }
81 forceinline void*
82 ptrsplit(void* p, ptrdiff_t& m) {
83 uptrint_t mp = reinterpret_cast<uptrint_t>(p);
84 m = static_cast<ptrdiff_t>(mp & 0b1);
85 return funmark(p);
86 }
87 forceinline void*
88 ptrjoin(void* p, ptrdiff_t m) {
89 assert((reinterpret_cast<uptrint_t>(p) & static_cast<uptrint_t>(m)) == 0);
90 return reinterpret_cast<void*>(reinterpret_cast<uptrint_t>(p) |
91 static_cast<uptrint_t>(m));
92 }
93
94}}
95
96// STATISTICS: support-any
Support algorithms and datastructures
void * ptrjoin(void *p, ptrdiff_t m)
Join unmarked pointer p and m into marked pointer.
void * ptrsplit(void *p, ptrdiff_t &m)
Split possibly marked pointer p into mark m and unmarked pointer.
void * unmark(void *p)
Return unmarked pointer for a marked pointer p.
std::make_unsigned_t< ptrdiff_t > uptrint_t
Unsigned integer for pointer encodings.
Definition int-type.hpp:53
void * fmark(void *p)
Return marked pointer for p (possibly already marked).
void * mark(void *p)
Return marked pointer for unmarked pointer p.
void * funmark(void *p)
Clear the lowest bits bits of a possibly marked pointer p.
bool marked(void *p)
Check whether p is marked.
Gecode toplevel namespace
#define forceinline
Definition config.hpp:144