From: Gao Xiang via Linux-erofs <linux-erofs@lists.ozlabs.org>
To: linux-erofs@lists.ozlabs.org
Subject: [WIP] [PATCH v0.0-20200229 01/11] ez: add basic source files
Date: Sat, 29 Feb 2020 12:50:07 +0800 [thread overview]
Message-ID: <20200229045017.12424-2-hsiangkao@aol.com> (raw)
In-Reply-To: <20200229045017.12424-1-hsiangkao@aol.com>
Add common headers to provide basic definitions and
helpers. Open source license is included as well.
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
include/ez/defs.h | 76 +++++++++++++++++++++++++++++++++++++++++++++++
include/ez/util.h | 25 ++++++++++++++++
2 files changed, 101 insertions(+)
create mode 100644 include/ez/defs.h
create mode 100644 include/ez/util.h
diff --git a/include/ez/defs.h b/include/ez/defs.h
new file mode 100644
index 0000000..d5acccf
--- /dev/null
+++ b/include/ez/defs.h
@@ -0,0 +1,76 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * ez/include/ez/defs.h
+ *
+ * Copyright (C) 2019-2020 Gao Xiang <hsiangkao@aol.com>
+ */
+#ifndef __EZ_DEFS_H
+#define __EZ_DEFS_H
+
+#include <stdint.h>
+#include <assert.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <string.h>
+#include <errno.h>
+
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#define min(x, y) ({ \
+ typeof(x) _min1 = (x); \
+ typeof(y) _min2 = (y); \
+ (void) (&_min1 == &_min2); \
+ _min1 < _min2 ? _min1 : _min2; })
+
+#define max(x, y) ({ \
+ typeof(x) _max1 = (x); \
+ typeof(y) _max2 = (y); \
+ (void) (&_max1 == &_max2); \
+ _max1 > _max2 ? _max1 : _max2; })
+
+/*
+ * ..and if you can't take the strict types, you can specify one yourself.
+ * Or don't use min/max at all, of course.
+ */
+#define min_t(type, x, y) ({ \
+ type __min1 = (x); \
+ type __min2 = (y); \
+ __min1 < __min2 ? __min1: __min2; })
+
+#define max_t(type, x, y) ({ \
+ type __max1 = (x); \
+ type __max2 = (y); \
+ __max1 > __max2 ? __max1: __max2; })
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+#ifndef __OPTIMIZE__
+#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2 * !!(condition)]))
+#else
+#define BUILD_BUG_ON(condition) assert(condition)
+#endif
+
+#define BUG_ON(cond) assert(!(cond))
+
+#ifdef NDEBUG
+#define DBG_BUGON(condition) ((void)(condition))
+#else
+#define DBG_BUGON(condition) BUG_ON(condition)
+#endif
+
+#ifndef __maybe_unused
+#define __maybe_unused __attribute__((__unused__))
+#endif
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
+#endif
+
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+
+#endif
+
diff --git a/include/ez/util.h b/include/ez/util.h
new file mode 100644
index 0000000..9cb6e62
--- /dev/null
+++ b/include/ez/util.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+ * ez/include/ez/util.h
+ *
+ * Copyright (C) 2019-2020 Gao Xiang <hsiangkao@aol.com>
+ */
+#ifndef __EZ_UTIL_H
+#define __EZ_UTIL_H
+
+#include "defs.h"
+
+static inline const uint8_t *ez_memcmp(const void *ptr1, const void *ptr2,
+ const void *buf1end)
+{
+ const uint8_t *buf1 = ptr1;
+ const uint8_t *buf2 = ptr2;
+
+ for (; buf1 != buf1end; ++buf1, ++buf2)
+ if (*buf1 != *buf2)
+ break;
+ return buf1;
+}
+
+#endif
+
--
2.20.1
next prev parent reply other threads:[~2020-02-29 4:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200229045017.12424-1-hsiangkao.ref@aol.com>
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 00/11] ez: LZMA fixed-sized output compression Gao Xiang via Linux-erofs
2020-02-29 4:50 ` Gao Xiang via Linux-erofs [this message]
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 02/11] ez: add helpers for unaligned accesses Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 03/11] ez: introduce bitops header file Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 04/11] ez: lzma: add range encoder Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 05/11] ez: lzma: add common header file Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 06/11] ez: lzma: add byte hashtable generated with CRC32 Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 07/11] ez: lzma: add LZMA matchfinder Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 08/11] ez: lzma: add LZMA encoder Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 09/11] ez: lzma: checkpoint feature for range encoder Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 10/11] ez: lzma: add fixed-sized output compression Gao Xiang via Linux-erofs
2020-02-29 4:50 ` [WIP] [PATCH v0.0-20200229 11/11] ez: lzma: add test program Gao Xiang via Linux-erofs
2020-02-29 4:58 ` [WIP] [PATCH v0.0-20200229 00/11] ez: LZMA fixed-sized output compression Eric Biggers
2020-02-29 5:27 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200229045017.12424-2-hsiangkao@aol.com \
--to=linux-erofs@lists.ozlabs.org \
--cc=hsiangkao@aol.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).