source: src/libcfa/libhdr/libalign.h @ 4aa2fb2

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 4aa2fb2 was 78b3f52, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Ugly but working coroutines

  • 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
36// Minimum size used to align memory boundaries for memory allocations.
37#define libAlign() (sizeof(double))
38
39// Check for power of 2
40static inline bool libPow2( unsigned long int value ) {
41    // clears all bits below value, rounding value down to the next lower multiple of value
42    return (value & (value - 1ul)) == 0ul;
43} // libPow2
44
45
46// Returns value aligned at the floor of align.
47static inline unsigned long int libFloor( unsigned long int value, unsigned long int align ) {
48    assert( libPow2( align ) );
49    // clears all bits above or equal to align, getting (value % align), the phase of value with regards to align
50    return value & -align;
51} // libFloor
52
53
54// Returns value aligned at the ceiling of align.
55
56static inline unsigned long int libCeiling( unsigned long int value, unsigned long int align ) {
57    assert( libPow2( align ) );
58    // "negate, round down, negate" is the same as round up
59    return -libFloor( -value, align );
60} // uCeiling
61
62
63#endif // __LIB_ALIGN_H__
64
65
66// Local Variables: //
67// compile-command: "make install" //
68// End: //
Note: See TracBrowser for help on using the repository browser.