summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/types.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/types.h b/drivers/gpu/nvgpu/include/nvgpu/types.h
index 1e243e53..dfa95557 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/types.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/types.h
@@ -30,4 +30,32 @@
30#include <nvgpu_rmos/include/types.h> 30#include <nvgpu_rmos/include/types.h>
31#endif 31#endif
32 32
33/*
34 * These macros exist to make integer literals used in certain arithmetic
35 * operations explicitly large enough to hold the results of that operation.
36 * The following is an example of this.
37 *
38 * In MISRA the destination for a bitwise shift must be able to hold the number
39 * of bits shifted. Otherwise the results are undefined. For example:
40 *
41 * 256U << 20U
42 *
43 * This is valid C code but the results of this _may_ be undefined if the size
44 * of an unsigned by default is less than 24 bits (i.e 16 bits). The MISRA
45 * checker sees the 256U and determines that the 256U fits in a 16 bit data type
46 * (i.e a u16). Since a u16 has 16 bits, which is less than 20, this is an
47 * issue.
48 *
49 * Of course most compilers these days use 32 bits for the default unsigned type
50 * this is not a requirement. Moreover this same problem could exist like so:
51 *
52 * 0xfffffU << 40U
53 *
54 * The 0xfffffU is a 32 bit unsigned type; but we are shifting 40 bits which
55 * overflows the 32 bit data type. So in this case we need an explicit cast to
56 * 64 bits in order to prevent undefined behavior.
57 */
58#define U32(x) ((u32)(x))
59#define U64(x) ((u64)(x))
60
33#endif 61#endif