source: src/libcfa/bits/align.h @ 490d9972

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 490d9972 was c2b9f21, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Removed libhdr, moved its content to bits

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