/* * Explicitly unroll a loop, for use in cases where doing so is performance * critical. * * Ideally we'd rely upon the compiler to provide this but there's no commonly * available means to do so. For example GCC's "#pragma GCC unroll" * functionality would be ideal but is only available from GCC 8 onwards. Using * -funroll-loops is an option but GCC tends to make poor choices when * compiling our string functions. -funroll-all-loops leads to massive code * bloat, even if only applied to the string functions.
*/ #define unroll(times, fn, ...) do { \ externvoid bad_unroll(void) \
__compiletime_error("Unsupported unroll"); \
\ /* \ * We can't unroll if the number of iterations isn't \ * compile-time constant. Unfortunately clang versions \ * up until 8.0 tend to miss obvious constants & cause \ * this check to fail, even though they go on to \ * generate reasonable code for the switch statement, \ * so we skip the sanity check for those compilers. \
*/
BUILD_BUG_ON(!__builtin_constant_p(times)); \
\ switch (times) { \ case32: fn(__VA_ARGS__); fallthrough; \ case31: fn(__VA_ARGS__); fallthrough; \ case30: fn(__VA_ARGS__); fallthrough; \ case29: fn(__VA_ARGS__); fallthrough; \ case28: fn(__VA_ARGS__); fallthrough; \ case27: fn(__VA_ARGS__); fallthrough; \ case26: fn(__VA_ARGS__); fallthrough; \ case25: fn(__VA_ARGS__); fallthrough; \ case24: fn(__VA_ARGS__); fallthrough; \ case23: fn(__VA_ARGS__); fallthrough; \ case22: fn(__VA_ARGS__); fallthrough; \ case21: fn(__VA_ARGS__); fallthrough; \ case20: fn(__VA_ARGS__); fallthrough; \ case19: fn(__VA_ARGS__); fallthrough; \ case18: fn(__VA_ARGS__); fallthrough; \ case17: fn(__VA_ARGS__); fallthrough; \ case16: fn(__VA_ARGS__); fallthrough; \ case15: fn(__VA_ARGS__); fallthrough; \ case14: fn(__VA_ARGS__); fallthrough; \ case13: fn(__VA_ARGS__); fallthrough; \ case12: fn(__VA_ARGS__); fallthrough; \ case11: fn(__VA_ARGS__); fallthrough; \ case10: fn(__VA_ARGS__); fallthrough; \ case9: fn(__VA_ARGS__); fallthrough; \ case8: fn(__VA_ARGS__); fallthrough; \ case7: fn(__VA_ARGS__); fallthrough; \ case6: fn(__VA_ARGS__); fallthrough; \ case5: fn(__VA_ARGS__); fallthrough; \ case4: fn(__VA_ARGS__); fallthrough; \ case3: fn(__VA_ARGS__); fallthrough; \ case2: fn(__VA_ARGS__); fallthrough; \ case1: fn(__VA_ARGS__); fallthrough; \ case0: break; \
\ default: \ /* \ * Either the iteration count is unreasonable \ * or we need to add more cases above. \
*/
bad_unroll(); \ break; \
} \
} while (0)
#endif/* __ASM_UNROLL_H__ */
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-05)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.