summaryrefslogtreecommitdiff
path: root/potrace/bitops.h
diff options
context:
space:
mode:
authorsaurabhb172020-02-26 16:37:17 +0530
committerGitHub2020-02-26 16:37:17 +0530
commit07a8c86216b6b1f694b136ec64c281d62941952e (patch)
treead18839d8b4eb1f13419d07878cc4ec4c9b70032 /potrace/bitops.h
parente255d0622297488c1c52755be670733418c994cf (diff)
parent1fa449fed953fa11f6bd0ea82cc2d3b115ee0781 (diff)
downloadKiCad-eSim-07a8c86216b6b1f694b136ec64c281d62941952e.tar.gz
KiCad-eSim-07a8c86216b6b1f694b136ec64c281d62941952e.tar.bz2
KiCad-eSim-07a8c86216b6b1f694b136ec64c281d62941952e.zip
Merge pull request #2 from saurabhb17/develop
Remaining files transfered
Diffstat (limited to 'potrace/bitops.h')
-rw-r--r--potrace/bitops.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/potrace/bitops.h b/potrace/bitops.h
new file mode 100644
index 0000000..89f4cb0
--- /dev/null
+++ b/potrace/bitops.h
@@ -0,0 +1,50 @@
+/* Copyright (C) 2001-2007 Peter Selinger.
+ This file is part of Potrace. It is free software and it is covered
+ by the GNU General Public License. See the file COPYING for details. */
+
+/* $Id: bitops.h 147 2007-04-09 00:44:09Z selinger $ */
+
+/* bits.h: this file defines some macros for bit manipulations. We
+ provide a generic implementation */
+
+/* lobit: return the position of the rightmost "1" bit of an int, or
+ 32 if none. hibit: return 1 + the position of the leftmost "1" bit
+ of an int, or 0 if none. Note: these functions work on 32-bit
+ integers. */
+
+#ifndef BITOPS_H
+#define BITOPS_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* generic macros */
+
+static inline unsigned int lobit(unsigned int x) {
+ unsigned int res = 32;
+ while (x & 0xffffff) {
+ x <<= 8;
+ res -= 8;
+ }
+ while (x) {
+ x <<= 1;
+ res -= 1;
+ }
+ return res;
+}
+
+static inline unsigned int hibit(unsigned int x) {
+ unsigned int res = 0;
+ while (x > 0xff) {
+ x >>= 8;
+ res += 8;
+ }
+ while (x) {
+ x >>= 1;
+ res += 1;
+ }
+ return res;
+}
+
+#endif /* BITOPS_H */