source: src/libcfa/bits/align.h @ d893266a

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

Removed libhdr, moved its content to bits

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[78b3f52]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//
[c2b9f21]7// align.h --
[78b3f52]8//
9// Author           : Thierry Delisle
10// Created On       : Mon Nov 28 12:27:26 2016
[91c389a]11// Last Modified By : Peter A. Buhr
[6b0b624]12// Last Modified On : Fri Jul 21 23:05:35 2017
13// Update Count     : 2
[78b3f52]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.
[2ac095d]19//
[78b3f52]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.
[2ac095d]24//
[78b3f52]25// You should  have received a  copy of the  GNU Lesser General  Public License
26// along  with this library.
[2ac095d]27//
[78b3f52]28
[6b0b624]29#pragma once
[78b3f52]30
[91c389a]31#include <assert.h>
[2ac095d]32#include <stdbool.h>
[78b3f52]33
[2ac095d]34// Minimum size used to align memory boundaries for memory allocations.
[78b3f52]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.