xref: /freebsd/sys/powerpc/include/_align.h (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
1a254d1f1SPoul-Henning Kamp /*-
2*df57947fSPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3*df57947fSPedro F. Giffuni  *
4a254d1f1SPoul-Henning Kamp  * Copyright (c) 2001 David E. O'Brien
5a254d1f1SPoul-Henning Kamp  * Copyright (c) 1990 The Regents of the University of California.
6a254d1f1SPoul-Henning Kamp  * All rights reserved.
7a254d1f1SPoul-Henning Kamp  *
8a254d1f1SPoul-Henning Kamp  * This code is derived from software contributed to Berkeley by
9a254d1f1SPoul-Henning Kamp  * William Jolitz.
10a254d1f1SPoul-Henning Kamp  *
11a254d1f1SPoul-Henning Kamp  * Redistribution and use in source and binary forms, with or without
12a254d1f1SPoul-Henning Kamp  * modification, are permitted provided that the following conditions
13a254d1f1SPoul-Henning Kamp  * are met:
14a254d1f1SPoul-Henning Kamp  * 1. Redistributions of source code must retain the above copyright
15a254d1f1SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer.
16a254d1f1SPoul-Henning Kamp  * 2. Redistributions in binary form must reproduce the above copyright
17a254d1f1SPoul-Henning Kamp  *    notice, this list of conditions and the following disclaimer in the
18a254d1f1SPoul-Henning Kamp  *    documentation and/or other materials provided with the distribution.
19a254d1f1SPoul-Henning Kamp  * 3. All advertising materials mentioning features or use of this software
20a254d1f1SPoul-Henning Kamp  *    must display the following acknowledgement:
21a254d1f1SPoul-Henning Kamp  *	This product includes software developed by the University of
22a254d1f1SPoul-Henning Kamp  *	California, Berkeley and its contributors.
23a254d1f1SPoul-Henning Kamp  * 4. Neither the name of the University nor the names of its contributors
24a254d1f1SPoul-Henning Kamp  *    may be used to endorse or promote products derived from this software
25a254d1f1SPoul-Henning Kamp  *    without specific prior written permission.
26a254d1f1SPoul-Henning Kamp  *
27a254d1f1SPoul-Henning Kamp  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28a254d1f1SPoul-Henning Kamp  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29a254d1f1SPoul-Henning Kamp  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30a254d1f1SPoul-Henning Kamp  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31a254d1f1SPoul-Henning Kamp  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32a254d1f1SPoul-Henning Kamp  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33a254d1f1SPoul-Henning Kamp  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34a254d1f1SPoul-Henning Kamp  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35a254d1f1SPoul-Henning Kamp  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36a254d1f1SPoul-Henning Kamp  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37a254d1f1SPoul-Henning Kamp  * SUCH DAMAGE.
38a254d1f1SPoul-Henning Kamp  */
39a254d1f1SPoul-Henning Kamp 
40a254d1f1SPoul-Henning Kamp #ifndef _POWERPC_INCLUDE__ALIGN_H_
41a254d1f1SPoul-Henning Kamp #define	_POWERPC_INCLUDE__ALIGN_H_
42a254d1f1SPoul-Henning Kamp 
43a254d1f1SPoul-Henning Kamp /*
44a254d1f1SPoul-Henning Kamp  * Round p (pointer or byte index) up to a correctly-aligned value
45a254d1f1SPoul-Henning Kamp  * for all data types (int, long, ...).   The result is unsigned int
46a254d1f1SPoul-Henning Kamp  * and must be cast to any desired pointer type.
47a254d1f1SPoul-Henning Kamp  */
48c3e289e1SNathan Whitehorn #define	_ALIGNBYTES	(sizeof(register_t) - 1)
49c3e289e1SNathan Whitehorn #define	_ALIGN(p)	(((uintptr_t)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
50a254d1f1SPoul-Henning Kamp 
51a254d1f1SPoul-Henning Kamp #endif /* !_POWERPC_INCLUDE__ALIGN_H_ */
52