Software APIs
Macros
macros.h File Reference

(5e04ded)

Generic preprocessor macros that don't really fit anywhere else. More...

#include <assert.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define FALLTHROUGH_INTENDED   __attribute__((fallthrough))
 An annotation that a switch/case fallthrough is the intended behavior.
 
#define ALWAYS_INLINE   __attribute__((always_inline)) inline
 A directive to force the compiler to inline a function.
 
#define GET_NUM_VARIABLE_ARGS(dummy, ...)
 A variable-argument macro that expands to the number of arguments passed into it, between 0 and 31 arguments. More...
 
#define SHIFT_N_VARIABLE_ARGS_(...)   GET_NTH_VARIABLE_ARG_(__VA_ARGS__)
 
#define GET_NTH_VARIABLE_ARG_(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, n, ...)   n
 
#define OT_ASSERT_MEMBER_OFFSET(type, member, offset)
 A macro that expands to an assertion for the offset of a struct member. More...
 
#define OT_ASSERT_SIZE(type, size)   static_assert(sizeof(type) == UINT32_C(size), "Unexpected size for " #type)
 A macro that expands to an assertion for the size of a type. More...
 
#define OT_WARN_UNUSED_RESULT   __attribute__((warn_unused_result))
 A macro representing the OpenTitan execution platform. More...
 
#define OT_ATTR_WEAK   __attribute__((weak))
 Attribute for weak functions that can be overridden, e.g., ISRs.
 

Detailed Description

Generic preprocessor macros that don't really fit anywhere else.

Definition in file macros.h.

Macro Definition Documentation

◆ GET_NUM_VARIABLE_ARGS

#define GET_NUM_VARIABLE_ARGS (   dummy,
  ... 
)
Value:
SHIFT_N_VARIABLE_ARGS_(dummy, ##__VA_ARGS__, 31, 30, 29, 28, 27, 26, 25, 24, \
23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

A variable-argument macro that expands to the number of arguments passed into it, between 0 and 31 arguments.

This macro is based off of a well-known preprocessor trick. This StackOverflow post expains the trick in detail: https://stackoverflow.com/questions/2308243/macro-returning-the-number-of-arguments-it-is-given-in-c TODO #2026: a dummy token is required for this to work correctly.

Parameters
dummya dummy token that is required to be passed for the calculation to work correctly.
...the variable args list.

Definition at line 42 of file macros.h.

◆ OT_ASSERT_MEMBER_OFFSET

#define OT_ASSERT_MEMBER_OFFSET (   type,
  member,
  offset 
)
Value:
static_assert(offsetof(type, member) == UINT32_C(offset), \
"Unexpected offset for " #type "." #member)

A macro that expands to an assertion for the offset of a struct member.

Parameters
typeA struct type.
memberA member of the struct.
offsetExpected offset of the member.

Definition at line 60 of file macros.h.

◆ OT_ASSERT_SIZE

#define OT_ASSERT_SIZE (   type,
  size 
)    static_assert(sizeof(type) == UINT32_C(size), "Unexpected size for " #type)

A macro that expands to an assertion for the size of a type.

Parameters
typeA type.
sizeExpected size of the type.

Definition at line 70 of file macros.h.

◆ OT_WARN_UNUSED_RESULT

#define OT_WARN_UNUSED_RESULT   __attribute__((warn_unused_result))

A macro representing the OpenTitan execution platform.

Attribute for functions which return errors that must be acknowledged.

This attribute must be used to mark all DIFs which return an error value of some kind, to ensure that callers do not accidentally drop the error on the ground.

Normally, the standard way to drop such a value on the ground explicitly is with the syntax (void)expr;, in analogy with the behavior of C++'s [[nodiscard]] attribute. However, GCC does not implement this, so the idiom if (expr) {} should be used instead, for the time being. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.

Definition at line 94 of file macros.h.