File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
nvidia/inc/libraries/utils Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,45 @@ 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
+ // this function is copied from linux kernel source
108
+ static inline int ffs (int x )
109
+ {
110
+ int r = 1 ;
111
+
112
+ if (!x )
113
+ return 0 ;
114
+ if (!(x & 0xffff )) {
115
+ x >>= 16 ;
116
+ r += 16 ;
117
+ }
118
+ if (!(x & 0xff )) {
119
+ x >>= 8 ;
120
+ r += 8 ;
121
+ }
122
+ if (!(x & 0xf )) {
123
+ x >>= 4 ;
124
+ r += 4 ;
125
+ }
126
+ if (!(x & 3 )) {
127
+ x >>= 2 ;
128
+ r += 2 ;
129
+ }
130
+ if (!(x & 1 )) {
131
+ x >>= 1 ;
132
+ r += 1 ;
133
+ }
134
+ return r ;
135
+ }
136
+ #endif
137
+
99
138
/*!
100
139
* DRF MACRO README:
101
140
*
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