File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -225,6 +225,16 @@ struct crn_packed_uint {
225225 }
226226
227227 inline operator unsigned int () const {
228+ #if 0
229+ /* Compilers will expand the template with all conditions and generate
230+ the code for all conditions even if only one condition is usable per
231+ template variant.
232+
233+ Compilers like ICC will raise warnings at compile time and code analysers
234+ like CodeQL will raise warnings when analysing the compiled binary.
235+
236+ See: https://github.com/DaemonEngine/crunch/issues/79 */
237+
228238 switch (N) {
229239 case 1:
230240 return m_buf[0];
@@ -235,6 +245,18 @@ struct crn_packed_uint {
235245 default:
236246 return (m_buf[0] << 24U) | (m_buf[1] << 16U) | (m_buf[2] << 8U) | (m_buf[3]);
237247 }
248+ #else
249+ /* We can assume the compiler will unroll that inline function for us,
250+ without any range ambiguity, unlike the above trick. */
251+
252+ unsigned int val = 0U ;
253+
254+ for (unsigned int i = 0U ; i < N; i++) {
255+ val |= m_buf[ i ] << ((N - (i + 1U )) * 8U );
256+ }
257+
258+ return val;
259+ #endif
238260 }
239261
240262 unsigned char m_buf[N];
You can’t perform that action at this time.
0 commit comments