The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/contrib/openzfs/include/sys/bitops.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * CDDL HEADER START
    3  *
    4  * The contents of this file are subject to the terms of the
    5  * Common Development and Distribution License (the "License").
    6  * You may not use this file except in compliance with the License.
    7  *
    8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
    9  * or https://opensource.org/licenses/CDDL-1.0.
   10  * See the License for the specific language governing permissions
   11  * and limitations under the License.
   12  *
   13  * When distributing Covered Code, include this CDDL HEADER in each
   14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
   15  * If applicable, add the following below this CDDL HEADER, with the
   16  * fields enclosed by brackets "[]" replaced with your own identifying
   17  * information: Portions Copyright [yyyy] [name of copyright owner]
   18  *
   19  * CDDL HEADER END
   20  */
   21 /*
   22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   23  * Copyright (c) 2011, 2019 by Delphix. All rights reserved.
   24  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
   25  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
   26  * Copyright 2013 Saso Kiselkov. All rights reserved.
   27  * Copyright (c) 2014 Integros [integros.com]
   28  * Copyright 2017 Joyent, Inc.
   29  * Copyright (c) 2017 Datto Inc.
   30  */
   31 
   32 #ifndef _SYS_BITOPS_H
   33 #define _SYS_BITOPS_H
   34 
   35 #include <sys/zfs_context.h>
   36 
   37 #ifdef  __cplusplus
   38 extern "C" {
   39 #endif
   40 
   41 /*
   42  * General-purpose 32-bit and 64-bit bitfield encodings.
   43  */
   44 #define BF32_DECODE(x, low, len)        P2PHASE((x) >> (low), 1U << (len))
   45 #define BF64_DECODE(x, low, len)        P2PHASE((x) >> (low), 1ULL << (len))
   46 #define BF32_ENCODE(x, low, len)        (P2PHASE((x), 1U << (len)) << (low))
   47 #define BF64_ENCODE(x, low, len)        (P2PHASE((x), 1ULL << (len)) << (low))
   48 
   49 #define BF32_GET(x, low, len)           BF32_DECODE(x, low, len)
   50 #define BF64_GET(x, low, len)           BF64_DECODE(x, low, len)
   51 
   52 #define BF32_SET(x, low, len, val) do { \
   53         ASSERT3U(val, <, 1U << (len)); \
   54         ASSERT3U(low + len, <=, 32); \
   55         (x) ^= BF32_ENCODE((x >> low) ^ (val), low, len); \
   56 } while (0)
   57 
   58 #define BF64_SET(x, low, len, val) do { \
   59         ASSERT3U(val, <, 1ULL << (len)); \
   60         ASSERT3U(low + len, <=, 64); \
   61         ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)); \
   62 } while (0)
   63 
   64 #define BF32_GET_SB(x, low, len, shift, bias)   \
   65         ((BF32_GET(x, low, len) + (bias)) << (shift))
   66 #define BF64_GET_SB(x, low, len, shift, bias)   \
   67         ((BF64_GET(x, low, len) + (bias)) << (shift))
   68 
   69 /*
   70  * We use ASSERT3U instead of ASSERT in these macros to prevent a lint error in
   71  * the case where val is a constant.  We can't fix ASSERT because it's used as
   72  * an expression in several places in the kernel.
   73  */
   74 #define BF32_SET_SB(x, low, len, shift, bias, val) do { \
   75         ASSERT3U(IS_P2ALIGNED(val, 1U << shift), !=, B_FALSE); \
   76         ASSERT3S((val) >> (shift), >=, bias); \
   77         BF32_SET(x, low, len, ((val) >> (shift)) - (bias)); \
   78 } while (0)
   79 #define BF64_SET_SB(x, low, len, shift, bias, val) do { \
   80         ASSERT3U(IS_P2ALIGNED(val, 1ULL << shift), !=, B_FALSE); \
   81         ASSERT3S((val) >> (shift), >=, bias); \
   82         BF64_SET(x, low, len, ((val) >> (shift)) - (bias)); \
   83 } while (0)
   84 
   85 #ifdef  __cplusplus
   86 }
   87 #endif
   88 
   89 #endif /* _SYS_BITOPS_H */

Cache object: 55a6880ef80ce57db00b8e6748eedc1c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.