From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2732 Path: news.gmane.org!not-for-mail From: Nathan McSween Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 1/4] Internal: Add word.h - word-at-a-time fns / macros Date: Mon, 4 Feb 2013 00:12:12 +0000 Message-ID: <1359936735-31915-2-git-send-email-nwmcsween@gmail.com> References: <1359936735-31915-1-git-send-email-nwmcsween@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1359936775 26601 80.91.229.3 (4 Feb 2013 00:12:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 4 Feb 2013 00:12:55 +0000 (UTC) Cc: Nathan McSween To: musl@lists.openwall.com Original-X-From: musl-return-2731-gllmg-musl=m.gmane.org@lists.openwall.com Mon Feb 04 01:13:15 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1U29gK-000725-In for gllmg-musl@plane.gmane.org; Mon, 04 Feb 2013 01:13:08 +0100 Original-Received: (qmail 32500 invoked by uid 550); 4 Feb 2013 00:12:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 32490 invoked from network); 4 Feb 2013 00:12:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=oSf1usGly96yDroifAFimas+EVImonb5SNVTLciNr/U=; b=tyCCyinzGTjVYaHAPqDUSVPK1ePbDVIsT9SCMgU4tJ5I0Y9fNaITed+E4Et/EdGgMk Uj+mkQ0MA/LviqPCq0l1vrNwWPyizOZfoeR0I16lGfpxMRd+r0dD6HkVl+a4JQAHCoDn LCyn7Ctvk/JNNAK30kaE2W3zQaZSlGuFfo95QE+C8F9NiRAr746LYBt5ADt81df0ZGIB c1YvVLPPXIkSB6jN/vB7Ol+megGQwcr/STM11Bjs0o5ngr8ybWFMVWflpvXwVLnsTq+S hgEVmEpwlO1aI3E+AhLhbX7mrqRneq0bLMaTDU5zSmBNOt193jNXXcfQbd4QACJYH7+G obcA== X-Received: by 10.66.76.104 with SMTP id j8mr46945013paw.72.1359936757913; Sun, 03 Feb 2013 16:12:37 -0800 (PST) X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1359936735-31915-1-git-send-email-nwmcsween@gmail.com> Xref: news.gmane.org gmane.linux.lib.musl.general:2732 Archived-At: --- 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 +#include + +/** + * 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