diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-15 23:13:41 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-06-27 00:04:20 +0300 |
commit | ce81312d8a81c7579ecc35ccdc53a49543c0b0d5 (patch) | |
tree | 26c37ec849e00af51f739e126041142d907c14cd /py/misc.h | |
parent | 63143c94cef353d7bae13f7b13650801bb901c94 (diff) |
misc: Add count_lead_ones() function, useful for UTF-8 handling.
Diffstat (limited to 'py/misc.h')
-rw-r--r-- | py/misc.h | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -166,4 +166,17 @@ int DEBUG_printf(const char *fmt, ...); extern uint mp_verbose_flag; +// This is useful for unicode handling. Some CPU archs has +// special instructions for efficient implentation of this +// function (e.g. CLZ on ARM). +#ifndef count_lead_ones +static inline uint count_lead_ones(byte val) { + uint c = 0; + for (byte mask = 0x80; val & mask; mask >>= 1) { + c++; + } + return c; +} +#endif + #endif // _INCLUDED_MINILIB_H |