MCUX CLNS
MCUX Crypto Library Normal Secure
 
Loading...
Searching...
No Matches
mcuxClCore_Macros.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/* Copyright 2023 NXP */
3/* */
4/* NXP Confidential. This software is owned or controlled by NXP and may */
5/* only be used strictly in accordance with the applicable license terms. */
6/* By expressly accepting such terms or by downloading, installing, */
7/* activating and/or otherwise using the software, you are agreeing that */
8/* you have read, and that you agree to comply with and are bound by, such */
9/* license terms. If you do not agree to be bound by the applicable license */
10/* terms, then you may not retain, install, activate or otherwise use the */
11/* software. */
12/*--------------------------------------------------------------------------*/
13
20#ifndef MCUXCLCORE_MACROS_H_
21#define MCUXCLCORE_MACROS_H_
22
23/* Macro to calculate the rounded down number of words that fit into the specified size */
24#define MCUXCLCORE_NUM_OF_WORDS_FLOOR(wordsize, size) \
25 ((size) / (wordsize))
26
27/* Macro to calculate the rounded up number of words needed to fit an object of the specified size */
28#define MCUXCLCORE_NUM_OF_WORDS_CEIL(wordsize, size) \
29 (((size) + (wordsize) - 1u) / (wordsize))
30
31/* Macro to calculate the rounded down number of CPU words that fit into the specified size */
32#define MCUXCLCORE_NUM_OF_CPUWORDS_FLOOR(size) \
33 MCUXCLCORE_NUM_OF_WORDS_FLOOR(sizeof(uint32_t), size)
34
35/* Macro to calculate the rounded up number of CPU words needed to fit an object of the specified size */
36#define MCUXCLCORE_NUM_OF_CPUWORDS_CEIL(size) \
37 MCUXCLCORE_NUM_OF_WORDS_CEIL(sizeof(uint32_t), size)
38
39/* Macro to round up a given size to the nearest multiple of a specified word size */
40#define MCUXCLCORE_ALIGN_TO_WORDSIZE(wordsize, size) \
41 (MCUXCLCORE_NUM_OF_WORDS_CEIL(wordsize, size) * (wordsize))
42
43/* Macro to round up a given size to the nearest multiple of the CPU word size */
44#define MCUXCLCORE_ALIGN_TO_CPU_WORDSIZE(size) \
45 MCUXCLCORE_ALIGN_TO_WORDSIZE(sizeof(uint32_t), size)
46
47/* Macro to calculate the maximum of two values */
48#define MCUXCLCORE_MAX(a, b) \
49MCUX_CSSL_ANALYSIS_START_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT("Fixed values are allowed as macro inputs") \
50 (((a) > (b)) ? (a) : (b)) \
51MCUX_CSSL_ANALYSIS_STOP_SUPPRESS_CONTROLLING_EXPRESSION_IS_INVARIANT()
52
53/* Macro to calculate the minimum of two values */
54#define MCUXCLCORE_MIN(a, b) \
55 (((a) < (b)) ? (a) : (b))
56
57#endif /* MCUXCLCORE_MACROS_H_ */