[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 3/6] include/uk: import bitcount.h


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Fri, 3 Aug 2018 13:58:34 +0300
  • Cc: florian.schmidt@xxxxxxxxx, simon.kuenzer@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Fri, 03 Aug 2018 10:58:54 +0000
  • Ironport-phdr: 9a23:a7/IwxYzCrVAJHGFF/SloAz/LSx+4OfEezUN459isYplN5qZrs++bnLW6fgltlLVR4KTs6sC17KI9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCa8bL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjmk8qxlSgLniD0fOjA57m/Zl8J+gqFcrh2jqRxy2JLYbJ2POfZiZK7RYc8WSGxcVchRTSxBBYa8YpMRAuoGJuZYs4j9p10TphW4GAmsHP7vwSJPi3Dq2q06yPghEQDA3AA6G9IOrWzUrMjuOagOSuC51rHIzSjYYP9Mwzf975HFfxY8qv+PRbJ9adfdxEYyGw/fjVidqZbpMy2L2ukPqWSW4fJsWf+ghmI6sQ18oTiiyt0yhoTHiI8Z0E3I+CpnzIszONa2UlR0YcS+H5tVryyaMox2Td48TGxwoyY6z6EGuYa8fCgX1JQr3x7fZOKDc4iP+h/jSuORLi15hHJhYr6wmw2y/VK4yu3hTca4ykxKri1dntnNsHACyQDT59CaRvZy40utwzWC2gDJ5u1aP0w5l7DXJpA5zr41jJUTsEDDHiHsmEXxia+bblkr+u+z6+T7Y7XmoIWQN4tpigHmL6QjgdCwAf8iPggWQmiU4v6w1Kfk/UHhWrVFkuU2krXFsJDdPckbo6+5AwlU0oYk8BazFiqp38oGnXYZKFJIYxaHj4nyO1HSO/D0F/i+jEqqkDtxwPDGJLLhCI3XLnffiLfhYap960lExQo9ydBf4IhUCrAbL/L1QEPxr8DXDh88Mwy13unnFM5w1oUAVm2TBq+WKrjdvUWW6eIyO+OMfpMauC7hK/g54P7jlWQ5mV4Yfamu25sbcnO4Hul4LEWfYHvjnM0BHHwMvgUgUOPqjEeNXiVJa3msQqI2/is7B56+DYffWoCth6SM3SemHp1MZ2BKEE6MEXDsd4qYW/cMayWSItF6nzwCS7euV4sh2gu1uwPg1bVnM7mcxipNsJPl1d9uouHeixw23Th1FNiGlXGASSdzhGxbaSUx2fVUpldhy1HL9bVgnrQMHttI+/JPFAMnLYP0xPc8E834HBjGKITaAG26S8mrVGliBuk6xMUDNh5w
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

The definitions in this file are currently present in FreeBSD in the
sys/sys/types.h file with a comment stating that the definitions should
be elsewhere. The same definitions can be found in newlib v2.5.0 in
libc/sys/rtems/include/machine/_bitcount.h which we chose to port in
Unikraft. The original file was slightly adapted to use Unikraft include
guards and types.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 include/uk/bitcount.h | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)
 create mode 100644 include/uk/bitcount.h

diff --git a/include/uk/bitcount.h b/include/uk/bitcount.h
new file mode 100644
index 0000000..a84e7f9
--- /dev/null
+++ b/include/uk/bitcount.h
@@ -0,0 +1,91 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*-
+ * Copyright (c) 2015 John Baldwin <jhb@xxxxxxxxxxx>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef __UK_BITCOUNT_H__
+#define __UK_BITCOUNT_H__
+
+#ifdef __POPCNT__
+#define        __bitcount64(x) __builtin_popcountll((__u64)(x))
+#define        __bitcount32(x) __builtin_popcountl((__u32)(x))
+#define        __bitcount16(x) __builtin_popcount((__u16)(x))
+#define        __bitcountl(x)  __builtin_popcountl((unsigned long)(x))
+#define        __bitcount(x)   __builtin_popcount((unsigned int)(x))
+#else /* !__POPCNT__ */
+static inline __u16
+__bitcount16(__u16 _x)
+{
+       _x = (_x & 0x5555u) + ((_x & 0xaaaau) >> 1);
+       _x = (_x & 0x3333u) + ((_x & 0xccccu) >> 2);
+       _x = (_x + (_x >> 4)) & 0x0f0fu;
+       _x = (_x + (_x >> 8)) & 0x00ffu;
+       return _x;
+}
+
+static inline __u32
+__bitcount32(__u32 _x)
+{
+       _x = (_x & 0x55555555u) + ((_x & 0xaaaaaaaau) >> 1);
+       _x = (_x & 0x33333333u) + ((_x & 0xccccccccu) >> 2);
+       _x = (_x + (_x >> 4)) & 0x0f0f0f0fu;
+       _x = (_x + (_x >> 8));
+       _x = (_x + (_x >> 16)) & 0x000000ffu;
+       return _x;
+}
+
+static inline __u64
+__bitcount64(__u64 _x)
+{
+#if __SIZEOF_LONG__ == 8
+       _x = (_x & 0x5555555555555555u) + ((_x & 0xaaaaaaaaaaaaaaaau) >> 1);
+       _x = (_x & 0x3333333333333333u) + ((_x & 0xccccccccccccccccu) >> 2);
+       _x = (_x + (_x >> 4)) & 0x0f0f0f0f0f0f0f0fu;
+       _x = (_x + (_x >> 8));
+       _x = (_x + (_x >> 16));
+       _x = (_x + (_x >> 32)) & 0x000000ffu;
+       return _x;
+#else
+       return (__bitcount32(_x >> 32) + __bitcount32(_x));
+#endif
+}
+
+#if __SIZEOF_LONG__ == 8
+#define        __bitcountl(x)  __bitcount64((unsigned long)(x))
+#else
+#define        __bitcountl(x)  __bitcount32((unsigned long)(x))
+#endif
+
+#if __SIZEOF_INT__ == 8
+#define        __bitcount(x)   __bitcount64((unsigned int)(x))
+#else
+#define        __bitcount(x)   __bitcount32((unsigned int)(x))
+#endif
+#endif /* __POPCNT__ */
+
+#endif /* __UK_BITCOUNT_H__ */
-- 
2.11.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.