|
Message-Id: <1359936735-31915-2-git-send-email-nwmcsween@gmail.com> Date: Mon, 4 Feb 2013 00:12:12 +0000 From: Nathan McSween <nwmcsween@...il.com> To: musl@...ts.openwall.com Cc: Nathan McSween <nwmcsween@...il.com> Subject: [PATCH 1/4] Internal: Add word.h - word-at-a-time fns / macros --- src/internal/word.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/internal/word.h diff --git a/src/internal/word.h b/src/internal/word.h new file mode 100644 index 0000000..395f802 --- /dev/null +++ b/src/internal/word.h @@ -0,0 +1,39 @@ +/** + * _INTERNAL_WORD_H - various word size functions / macros + */ +#ifndef _MYOSIN_WORD_H +#define _MYOSIN_WORD_H + +#include <stddef.h> +#include <stdint.h> + +/** + * WORD_LSB_ONE - Set low bit of each byte on arch word size to one. + */ +#define WORD_LSB_ONE ((size_t)-1 / (unsigned char)-1) + +/** + * WORD_MSB_ONE - Set high bit of each byte on arch word size to one. + */ +#define WORD_MSB_ONE (WORD_LSB_ONE * ((unsigned char)-1 / 2 + 1)) + +/** + * word_has_zero - Word has a zero character + * @w: Word + */ +static inline char word_has_zero(size_t w) +{ + return !!((w - WORD_LSB_ONE) & (~w & WORD_MSB_ONE)); +} + +/** + * word_has_char - Word has a character + * @w: Word + */ +static inline char word_has_char(size_t w, char c) +{ + return !!((w - WORD_LSB_ONE) + & ((~w & WORD_MSB_ONE)^(WORD_LSB_ONE * c))); +} + +#endif /* !_INTERNAL_WORD_H */ -- 1.7.11.4
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.