Commit 1697599e authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

bitfield.h: add FIELD_FIT() helper

Add a helper for checking at runtime that a value will fit inside
a specified field/mask.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4f2bd6b3
...@@ -39,8 +39,6 @@ ...@@ -39,8 +39,6 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/types.h> #include <linux/types.h>
#define FIELD_FIT(mask, val) (!((((u64)val) << __bf_shf(mask)) & ~(mask)))
/* For branch fixup logic use up-most byte of branch instruction as scratch /* For branch fixup logic use up-most byte of branch instruction as scratch
* area. Remember to clear this before sending instructions to HW! * area. Remember to clear this before sending instructions to HW!
*/ */
......
...@@ -62,6 +62,19 @@ ...@@ -62,6 +62,19 @@
(1ULL << __bf_shf(_mask))); \ (1ULL << __bf_shf(_mask))); \
}) })
/**
* FIELD_FIT() - check if value fits in the field
* @_mask: shifted mask defining the field's length and position
* @_val: value to test against the field
*
* Return: true if @_val can fit inside @_mask, false if @_val is too big.
*/
#define FIELD_FIT(_mask, _val) \
({ \
__BF_FIELD_CHECK(_mask, 0ULL, _val, "FIELD_FIT: "); \
!((((typeof(_mask))_val) << __bf_shf(_mask)) & ~(_mask)); \
})
/** /**
* FIELD_PREP() - prepare a bitfield element * FIELD_PREP() - prepare a bitfield element
* @_mask: shifted mask defining the field's length and position * @_mask: shifted mask defining the field's length and position
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment