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
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
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 ---
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
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
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 ---