bitfield.hh (4649:899f745b3c21) bitfield.hh (4661:44458219add1)
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 45 unchanged lines hidden (view full) ---

54T
55bits(T val, int first, int last)
56{
57 int nbits = first - last + 1;
58 return (val >> last) & mask(nbits);
59}
60
61/**
1/*
2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 45 unchanged lines hidden (view full) ---

54T
55bits(T val, int first, int last)
56{
57 int nbits = first - last + 1;
58 return (val >> last) & mask(nbits);
59}
60
61/**
62 * Extract the bit from this position from 'val' and right justify it.
63 */
64template <class T>
65inline
66T
67bits(T val, int bit)
68{
69 return bits(val, bit, bit);
70}
71
72/**
62 * Mask off the given bits in place like bits() but without shifting.
63 * msb = 63, lsb = 0
64 */
65template <class T>
66inline
67T
68mbits(T val, int first, int last)
69{

--- 27 unchanged lines hidden (view full) ---

97insertBits(T val, int first, int last, B bit_val)
98{
99 T t_bit_val = bit_val;
100 T bmask = mask(first - last + 1) << last;
101 return ((t_bit_val << last) & bmask) | (val & ~bmask);
102}
103
104/**
73 * Mask off the given bits in place like bits() but without shifting.
74 * msb = 63, lsb = 0
75 */
76template <class T>
77inline
78T
79mbits(T val, int first, int last)
80{

--- 27 unchanged lines hidden (view full) ---

108insertBits(T val, int first, int last, B bit_val)
109{
110 T t_bit_val = bit_val;
111 T bmask = mask(first - last + 1) << last;
112 return ((t_bit_val << last) & bmask) | (val & ~bmask);
113}
114
115/**
116 * Overloaded for access to only one bit in value
117 */
118template <class T, class B>
119inline
120T
121insertBits(T val, int bit, B bit_val)
122{
123 return insertBits(val, bit, bit, bit_val);
124}
125
126/**
105 * A convenience function to replace bits first to last of val with bit_val
106 * in place.
107 */
108template <class T, class B>
109inline
110void
111replaceBits(T& val, int first, int last, B bit_val)
112{
113 val = insertBits(val, first, last, bit_val);
114}
115
127 * A convenience function to replace bits first to last of val with bit_val
128 * in place.
129 */
130template <class T, class B>
131inline
132void
133replaceBits(T& val, int first, int last, B bit_val)
134{
135 val = insertBits(val, first, last, bit_val);
136}
137
138/** Overloaded function to allow to access only 1 bit*/
139template <class T, class B>
140inline
141void
142replaceBits(T& val, int bit, B bit_val)
143{
144 val = insertBits(val, bit, bit, bit_val);
145}
116/**
117 * Returns the bit position of the MSB that is set in the input
118 */
119inline
120int
121findMsbSet(uint64_t val) {
122 int msb = 0;
123 if (!val)

--- 280 unchanged lines hidden ---
146/**
147 * Returns the bit position of the MSB that is set in the input
148 */
149inline
150int
151findMsbSet(uint64_t val) {
152 int msb = 0;
153 if (!val)

--- 280 unchanged lines hidden ---