feat(lib): add EXTRACT_FIELD macro for field extraction

Introduce a new EXTRACT_FIELD macro to simplify the extraction
of specific fields from a value by shifting the value right
and applying the mask.

Change-Id: Iae9573d6d23067bbde13253e264e4f6f18b806c2
Signed-off-by: Manish V Badarkhe <Manish.Badarkhe@arm.com>
This commit is contained in:
Manish V Badarkhe 2025-03-09 11:51:21 +00:00
parent 7aa73612d7
commit af1dd6e1a5

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2016-2025, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
@ -218,4 +218,17 @@
*/
#define KHZ_TICKS_PER_SEC U(1000)
/**
* EXTRACT_FIELD - Extracts a specific bit field from a value.
*
* @val: The input value containing the field.
* @mask: A bitmask representing the maximum value of the field
* @shift: The starting bit position of the field.
*
* This macro shifts the input value (@val) to the right by @shift bits,
* aligning the target field to the least significant bits (LSB).
* It then applies @mask to extract only the relevant bits.
*/
#define EXTRACT_FIELD(val, mask, shift) (((val) >> (shift)) & (mask))
#endif /* UTILS_DEF_H */