summaryrefslogtreecommitdiffstats
path: root/tools/include/asm-generic/unaligned.h
blob: 47387c607035e4f46c11470b696768caadc30234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copied from the kernel sources to tools/perf/:
 */

#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H

#define __get_unaligned_t(type, ptr) ({						\
	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
	__pptr->x;								\
})

#define __put_unaligned_t(type, val, ptr) do {					\
	struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);		\
	__pptr->x = (val);							\
} while (0)

#define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
#define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))

#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */