File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
nvidia/inc/libraries/utils Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,32 @@ extern "C" {
96
96
((((n) & 0xCCCCCCCCCCCCCCCCULL) != 0U) ? 0x02U: 0U) | \
97
97
((((n) & 0xAAAAAAAAAAAAAAAAULL) != 0U) ? 0x01U: 0U) )
98
98
99
+ #if defined(NVCPU_RISCV64 ) && __riscv_xlen == 64
100
+ // On RISC-V 64-bit platform, GCC would expand __builtin_ffs() to ffs()
101
+ // see: https://github.com/riscv-collab/riscv-newlib/blob/master/newlib/libc/machine/riscv/ffs.c
102
+ // see: https://sourceware.org/pipermail/newlib/2017/014958.html
103
+
104
+ // in case GCC changes the behavior, we force the expansion
105
+ #define __builtin_ffs (x ) ffs(x)
106
+
107
+ static inline int ffs (unsigned int x )
108
+ {
109
+ unsigned int y ;
110
+
111
+ // __builtin_ffs() is undefined at this point
112
+ if (x == 0 ) return 0 ;
113
+
114
+ // count trailing zeros.
115
+ // Copied and adapted from util_generic.h because I cannot
116
+ // include that file directly. This should be refactored out.
117
+ for (y = 0 ; !(x & 0x80000000 ); y ++ )
118
+ x <<= 1 ;
119
+
120
+ // ffs = ctz + 1
121
+ return y + 1 ;
122
+ }
123
+ #endif
124
+
99
125
/*!
100
126
* DRF MACRO README:
101
127
*
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ extern "C" {
65
65
#define NV_PRINTF_LEVEL_ENABLED (level ) ((level) >= NV_PRINTF_LEVEL)
66
66
#endif
67
67
68
- #if defined(GSP_PLUGIN_BUILD ) || (defined(NVRM ) && NVCPU_IS_RISCV64 )
68
+ #if defined(GSP_PLUGIN_BUILD ) || (defined(NVRM ) && NVCPU_IS_RISCV64 && ! NVOS_IS_LINUX )
69
69
70
70
/**
71
71
* GSPRM uses a different system for logging.
You can’t perform that action at this time.
0 commit comments