From d9f58253e30ea80e57d8f54e41e9cd114cc13973 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 15 Feb 2010 21:27:37 -0800 Subject: Use clamping to more easily normalize input values The kernel has min/max/clamp macros to make range comparisons easier. Clamp is a newer invention, but we can define it for older kernels in terms of min and max. --- runtime/runtime.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/runtime.h') diff --git a/runtime/runtime.h b/runtime/runtime.h index 91c48d57..c51520d0 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -50,6 +50,14 @@ #define stp_for_each_cpu(cpu) for_each_cpu_mask((cpu), cpu_possible_map) #endif +#ifndef clamp +#define clamp(val, low, high) min(max(low, val), high) +#endif + +#ifndef clamp_t +#define clamp_t(type, val, low, high) min_t(type, max_t(type, low, val), high) +#endif + static void _stp_dbug (const char *func, int line, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); static void _stp_error (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); static void _stp_warn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); -- cgit