aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/util_macros.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:04:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-17 09:04:38 -0400
commit54e514b91b95d6441c12a7955addfb9f9d2afc65 (patch)
tree8b73d901bd2a6ec5a31f34a8954e5ea92216dd6c /include/linux/util_macros.h
parent4fc8adcfec3da639da76e8314c9ccefe5bf9a045 (diff)
parent6c8c90319c0bb1c9e0b68e721359b89ae4f28465 (diff)
Merge branch 'akpm' (patches from Andrew)
Merge third patchbomb from Andrew Morton: - various misc things - a couple of lib/ optimisations - provide DIV_ROUND_CLOSEST_ULL() - checkpatch updates - rtc tree - befs, nilfs2, hfs, hfsplus, fatfs, adfs, affs, bfs - ptrace fixes - fork() fixes - seccomp cleanups - more mmap_sem hold time reductions from Davidlohr * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (138 commits) proc: show locks in /proc/pid/fdinfo/X docs: add missing and new /proc/PID/status file entries, fix typos drivers/rtc/rtc-at91rm9200.c: make IO endian agnostic Documentation/spi/spidev_test.c: fix warning drivers/rtc/rtc-s5m.c: allow usage on device type different than main MFD type .gitignore: ignore *.tar MAINTAINERS: add Mediatek SoC mailing list tomoyo: reduce mmap_sem hold for mm->exe_file powerpc/oprofile: reduce mmap_sem hold for exe_file oprofile: reduce mmap_sem hold for mm->exe_file mips: ip32: add platform data hooks to use DS1685 driver lib/Kconfig: fix up HAVE_ARCH_BITREVERSE help text x86: switch to using asm-generic for seccomp.h sparc: switch to using asm-generic for seccomp.h powerpc: switch to using asm-generic for seccomp.h parisc: switch to using asm-generic for seccomp.h mips: switch to using asm-generic for seccomp.h microblaze: use asm-generic for seccomp.h arm: use asm-generic for seccomp.h seccomp: allow COMPAT sigreturn overrides ...
Diffstat (limited to 'include/linux/util_macros.h')
-rw-r--r--include/linux/util_macros.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h
new file mode 100644
index 000000000000..d5f4fb69dba3
--- /dev/null
+++ b/include/linux/util_macros.h
@@ -0,0 +1,40 @@
1#ifndef _LINUX_HELPER_MACROS_H_
2#define _LINUX_HELPER_MACROS_H_
3
4#define __find_closest(x, a, as, op) \
5({ \
6 typeof(as) __fc_i, __fc_as = (as) - 1; \
7 typeof(x) __fc_x = (x); \
8 typeof(*a) *__fc_a = (a); \
9 for (__fc_i = 0; __fc_i < __fc_as; __fc_i++) { \
10 if (__fc_x op DIV_ROUND_CLOSEST(__fc_a[__fc_i] + \
11 __fc_a[__fc_i + 1], 2)) \
12 break; \
13 } \
14 (__fc_i); \
15})
16
17/**
18 * find_closest - locate the closest element in a sorted array
19 * @x: The reference value.
20 * @a: The array in which to look for the closest element. Must be sorted
21 * in ascending order.
22 * @as: Size of 'a'.
23 *
24 * Returns the index of the element closest to 'x'.
25 */
26#define find_closest(x, a, as) __find_closest(x, a, as, <=)
27
28/**
29 * find_closest_descending - locate the closest element in a sorted array
30 * @x: The reference value.
31 * @a: The array in which to look for the closest element. Must be sorted
32 * in descending order.
33 * @as: Size of 'a'.
34 *
35 * Similar to find_closest() but 'a' is expected to be sorted in descending
36 * order.
37 */
38#define find_closest_descending(x, a, as) __find_closest(x, a, as, >=)
39
40#endif