bitfield.hh (3814:33bd4ec9d66a) bitfield.hh (4070:74449a198a44)
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;

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

39 */
40inline uint64_t
41mask(int nbits)
42{
43 return (nbits == 64) ? (uint64_t)-1LL : (1ULL << nbits) - 1;
44}
45
46
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;

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

39 */
40inline uint64_t
41mask(int nbits)
42{
43 return (nbits == 64) ? (uint64_t)-1LL : (1ULL << nbits) - 1;
44}
45
46
47
47/**
48 * Extract the bitfield from position 'first' to 'last' (inclusive)
49 * from 'val' and right justify it. MSB is numbered 63, LSB is 0.
50 */
51template <class T>
52inline
53T
54bits(T val, int first, int last)

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

64template <class T>
65inline
66T
67mbits(T val, int first, int last)
68{
69 return val & (mask(first+1) & ~mask(last));
70}
71
48/**
49 * Extract the bitfield from position 'first' to 'last' (inclusive)
50 * from 'val' and right justify it. MSB is numbered 63, LSB is 0.
51 */
52template <class T>
53inline
54T
55bits(T val, int first, int last)

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

65template <class T>
66inline
67T
68mbits(T val, int first, int last)
69{
70 return val & (mask(first+1) & ~mask(last));
71}
72
73inline uint64_t
74mask(int first, int last)
75{
76 return mbits((uint64_t)-1LL, first, last);
77}
78
72/**
73 * Sign-extend an N-bit value to 64 bits.
74 */
75template <int N>
76inline
77int64_t
78sext(uint64_t val)
79{

--- 29 unchanged lines hidden ---
79/**
80 * Sign-extend an N-bit value to 64 bits.
81 */
82template <int N>
83inline
84int64_t
85sext(uint64_t val)
86{

--- 29 unchanged lines hidden ---