1/* |
2 * Copyright (c) 2017 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * |
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions are 19 * met: redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer; 21 * redistributions in binary form must reproduce the above copyright --- 196 unchanged lines hidden (view full) --- 218 const uint64_t sum = 0x0101010101010101; 219 220 val -= (val >> 1) & m1; // 2 bits count -> 2 bits 221 val = (val & m2) + ((val >> 2) & m2); // 4 bits count -> 4 bits 222 val = (val + (val >> 4)) & m4; // 8 bits count -> 8 bits 223 return (val * sum) >> 56; // horizontal sum 224#endif // defined(__GNUC__) || (defined(__clang__) && __has_builtin(__builtin_popcountl)) 225} |
226 227/** 228 * Align to the next highest power of two. 229 * 230 * The number passed in is aligned to the next highest power of two, 231 * if it is not already a power of two. Please note that if 0 is 232 * passed in, 0 is returned. 233 * 234 * This code has been modified from the following: 235 * http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 236 */ 237inline uint64_t alignToPowerOfTwo(uint64_t val) 238{ 239 val--; 240 val |= val >> 1; 241 val |= val >> 2; 242 val |= val >> 4; 243 val |= val >> 8; 244 val |= val >> 16; 245 val |= val >> 32; 246 val++; 247 248 return val; 249}; 250 |
251#endif // __BASE_BITFIELD_HH__ |