From d433a3e902116a3dba87d1caa4cf0e059a2ffbe2 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Wed, 28 Jun 2017 18:54:07 +0300 Subject: [PATCH] utils: Introduce SWAP() helper to exchange two variables Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- include/common/compiler.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/common/compiler.h b/include/common/compiler.h index 235413070..ada79f293 100644 --- a/include/common/compiler.h +++ b/include/common/compiler.h @@ -85,6 +85,13 @@ type __max2 = (y); \ __max1 > __max2 ? __max1: __max2; }) +#define SWAP(x, y) \ + do { \ + typeof(x) ____val = x; \ + x = y; \ + y = ____val; \ + } while (0) + #define is_log2(v) (((v) & ((v) - 1)) == 0) #endif /* __CR_COMPILER_H__ */