More compile fixes
[lttng-ust.git] / include / lttng / align.h
CommitLineData
8c4127c5
MD
1#ifndef _UST_ALIGN_H
2#define _UST_ALIGN_H
3
4/*
4318ae1b 5 * lttng/align.h
8c4127c5
MD
6 *
7 * (C) Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
a60d70e6
MD
9 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
10 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
11 *
12 * Permission is hereby granted to use or copy this program
13 * for any purpose, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
8c4127c5
MD
17 */
18
4318ae1b 19#include <lttng/bug.h>
8c4127c5
MD
20
21/*
22 * Align pointer on natural object alignment.
23 */
24#define object_align(obj) PTR_ALIGN(obj, __alignof__(*(obj)))
25#define object_align_floor(obj) PTR_ALIGN_FLOOR(obj, __alignof__(*(obj)))
26
27/**
28 * offset_align - Calculate the offset needed to align an object on its natural
29 * alignment towards higher addresses.
30 * @align_drift: object offset from an "alignment"-aligned address.
31 * @alignment: natural object alignment. Must be non-zero, power of 2.
32 *
33 * Returns the offset that must be added to align towards higher
34 * addresses.
35 */
36#define offset_align(align_drift, alignment) \
37 ({ \
38 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
39 || ((alignment) & ((alignment) - 1))); \
40 (((alignment) - (align_drift)) & ((alignment) - 1)); \
41 })
42
43/**
44 * offset_align_floor - Calculate the offset needed to align an object
45 * on its natural alignment towards lower addresses.
46 * @align_drift: object offset from an "alignment"-aligned address.
47 * @alignment: natural object alignment. Must be non-zero, power of 2.
48 *
49 * Returns the offset that must be substracted to align towards lower addresses.
50 */
51#define offset_align_floor(align_drift, alignment) \
52 ({ \
53 BUILD_RUNTIME_BUG_ON((alignment) == 0 \
54 || ((alignment) & ((alignment) - 1))); \
55 (((align_drift) - (alignment)) & ((alignment) - 1); \
56 })
57
58#endif /* _UST_ALIGN_H */
This page took 0.027413 seconds and 4 git commands to generate.