source: src/libcfa/libhdr/libalign.h@ 83a071f9

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 83a071f9 was 2ac095d, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Added macros for parameters only present in debug

  • Property mode set to 100644
File size: 2.2 KB
Line 
1// -*- Mode: C++ -*-
2//
3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
7//
8// libdebug.h --
9//
10// Author : Thierry Delisle
11// Created On : Mon Nov 28 12:27:26 2016
12// Last Modified By : Thierry Delisle
13// Last Modified On : Mon Nov 28 12:27:26 2016
14// Update Count : 0
15//
16// This library is free software; you can redistribute it and/or modify it
17// under the terms of the GNU Lesser General Public License as published by the
18// Free Software Foundation; either version 2.1 of the License, or (at your
19// option) any later version.
20//
21// This library is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
24// for more details.
25//
26// You should have received a copy of the GNU Lesser General Public License
27// along with this library.
28//
29
30
31#ifndef __LIB_ALIGN_H__
32#define __LIB_ALIGN_H__
33
34#include "assert"
35#include <stdbool.h>
36
37// Minimum size used to align memory boundaries for memory allocations.
38#define libAlign() (sizeof(double))
39
40// Check for power of 2
41static inline bool libPow2( unsigned long int value ) {
42 // clears all bits below value, rounding value down to the next lower multiple of value
43 return (value & (value - 1ul)) == 0ul;
44} // libPow2
45
46
47// Returns value aligned at the floor of align.
48static inline unsigned long int libFloor( unsigned long int value, unsigned long int align ) {
49 assert( libPow2( align ) );
50 // clears all bits above or equal to align, getting (value % align), the phase of value with regards to align
51 return value & -align;
52} // libFloor
53
54
55// Returns value aligned at the ceiling of align.
56
57static inline unsigned long int libCeiling( unsigned long int value, unsigned long int align ) {
58 assert( libPow2( align ) );
59 // "negate, round down, negate" is the same as round up
60 return -libFloor( -value, align );
61} // uCeiling
62
63
64#endif // __LIB_ALIGN_H__
65
66
67// Local Variables: //
68// compile-command: "make install" //
69// End: //
Note: See TracBrowser for help on using the repository browser.