bitfield.hh (13531:e6f1bf55d038) | bitfield.hh (13824:54e92033cf67) |
---|---|
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 --- 168 unchanged lines hidden (view full) --- 177T 178reverseBits(T val, std::size_t size = sizeof(T)) 179{ 180 static_assert(std::is_integral<T>::value, "Expecting an integer type"); 181 182 assert(size <= sizeof(T)); 183 184 T output = 0; | 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 --- 168 unchanged lines hidden (view full) --- 177T 178reverseBits(T val, std::size_t size = sizeof(T)) 179{ 180 static_assert(std::is_integral<T>::value, "Expecting an integer type"); 181 182 assert(size <= sizeof(T)); 183 184 T output = 0; |
185 for (auto byte = 0; byte < size; byte++, val >>= 8) { | 185 for (auto byte = 0; byte < size; byte++, val = static_cast<T>(val >> 8)) { |
186 output = (output << 8) | reverseLookUpTable[val & 0xFF]; 187 } 188 189 return output; 190} 191 192/** 193 * Returns the bit position of the MSB that is set in the input --- 103 unchanged lines hidden --- | 186 output = (output << 8) | reverseLookUpTable[val & 0xFF]; 187 } 188 189 return output; 190} 191 192/** 193 * Returns the bit position of the MSB that is set in the input --- 103 unchanged lines hidden --- |