bitfield.hh (3386:6094e8865bb8) bitfield.hh (3422:426a8ebd677c)
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;

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

64inline
65int64_t
66sext(uint64_t val)
67{
68 int sign_bit = bits(val, N-1, N-1);
69 return sign_bit ? (val | ~mask(N)) : val;
70}
71
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;

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

64inline
65int64_t
66sext(uint64_t val)
67{
68 int sign_bit = bits(val, N-1, N-1);
69 return sign_bit ? (val | ~mask(N)) : val;
70}
71
72/**
73 * Return val with bits first to last set to bit_val
74 */
75template <class T, class B>
76inline
77T
78insertBits(T val, int first, int last, B bit_val)
79{
80 T bmask = mask(first - last + 1) << last;
81 return ((bit_val << last) & bmask) | (val & ~bmask);
82}
83
84/**
85 * A convenience function to replace bits first to last of val with bit_val
86 * in place.
87 */
88template <class T, class B>
89inline
90void
91replaceBits(T& val, int first, int last, B bit_val)
92{
93 val = insertBits(val, first, last, bit_val);
94}
95
72#endif // __BASE_BITFIELD_HH__
96#endif // __BASE_BITFIELD_HH__