1 1.1 christos /* This file is part of the program psim. 2 1.1 christos 3 1.1 christos Copyright (C) 1994-1995, Andrew Cagney <cagney (at) highland.com.au> 4 1.1 christos 5 1.1 christos This program is free software; you can redistribute it and/or modify 6 1.1 christos it under the terms of the GNU General Public License as published by 7 1.1 christos the Free Software Foundation; either version 3 of the License, or 8 1.1 christos (at your option) any later version. 9 1.1 christos 10 1.1 christos This program is distributed in the hope that it will be useful, 11 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 12 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 1.1 christos GNU General Public License for more details. 14 1.1 christos 15 1.1 christos You should have received a copy of the GNU General Public License 16 1.1 christos along with this program; if not, see <http://www.gnu.org/licenses/>. 17 1.1 christos 18 1.1 christos */ 19 1.1 christos 20 1.1 christos 21 1.1 christos #ifndef _BITS_C_ 22 1.1 christos #define _BITS_C_ 23 1.1 christos 24 1.1 christos #include "basics.h" 25 1.1 christos 26 1.1 christos INLINE_BITS\ 27 1.6 christos (uint64_t) 28 1.6 christos LSMASKED64 (uint64_t word, 29 1.1 christos int start, 30 1.1 christos int stop) 31 1.1 christos { 32 1.1 christos word &= LSMASK64 (start, stop); 33 1.1 christos return word; 34 1.1 christos } 35 1.1 christos 36 1.1 christos INLINE_BITS\ 37 1.6 christos (uint64_t) 38 1.6 christos LSEXTRACTED64 (uint64_t val, 39 1.1 christos int start, 40 1.1 christos int stop) 41 1.1 christos { 42 1.1 christos val <<= (64 - 1 - start); /* drop high bits */ 43 1.1 christos val >>= (64 - 1 - start) + (stop); /* drop low bits */ 44 1.1 christos return val; 45 1.1 christos } 46 1.1 christos 47 1.1 christos INLINE_BITS\ 48 1.6 christos (uint32_t) 49 1.6 christos MASKED32(uint32_t word, 50 1.1 christos unsigned start, 51 1.1 christos unsigned stop) 52 1.1 christos { 53 1.1 christos return (word & MASK32(start, stop)); 54 1.1 christos } 55 1.1 christos 56 1.1 christos INLINE_BITS\ 57 1.6 christos (uint64_t) 58 1.6 christos MASKED64(uint64_t word, 59 1.1 christos unsigned start, 60 1.1 christos unsigned stop) 61 1.1 christos { 62 1.1 christos return (word & MASK64(start, stop)); 63 1.1 christos } 64 1.1 christos 65 1.1 christos INLINE_BITS\ 66 1.1 christos (unsigned_word) 67 1.1 christos MASKED(unsigned_word word, 68 1.1 christos unsigned start, 69 1.1 christos unsigned stop) 70 1.1 christos { 71 1.1 christos return ((word) & MASK(start, stop)); 72 1.1 christos } 73 1.1 christos 74 1.1 christos 75 1.1 christos 76 1.1 christos INLINE_BITS\ 77 1.1 christos (unsigned_word) 78 1.1 christos EXTRACTED(unsigned_word word, 79 1.1 christos unsigned start, 80 1.1 christos unsigned stop) 81 1.1 christos { 82 1.1 christos ASSERT(start <= stop); 83 1.1 christos #if (WITH_TARGET_WORD_BITSIZE == 64) 84 1.1 christos return _EXTRACTEDn(64, word, start, stop); 85 1.1 christos #else 86 1.1 christos if (stop < 32) 87 1.1 christos return 0; 88 1.1 christos else 89 1.1 christos return ((word >> (63 - stop)) 90 1.1 christos & MASK(start+(63-stop), 63)); 91 1.1 christos #endif 92 1.1 christos } 93 1.1 christos 94 1.1 christos 95 1.1 christos INLINE_BITS\ 96 1.1 christos (unsigned_word) 97 1.1 christos INSERTED(unsigned_word word, 98 1.1 christos unsigned start, 99 1.1 christos unsigned stop) 100 1.1 christos { 101 1.1 christos ASSERT(start <= stop); 102 1.1 christos #if (WITH_TARGET_WORD_BITSIZE == 64) 103 1.1 christos return _INSERTEDn(64, word, start, stop); 104 1.1 christos #else 105 1.1 christos if (stop < 32) 106 1.1 christos return 0; 107 1.1 christos else 108 1.1 christos return ((word & MASK(start+(63-stop), 63)) 109 1.1 christos << (63 - stop)); 110 1.1 christos #endif 111 1.1 christos } 112 1.1 christos 113 1.1 christos 114 1.1 christos INLINE_BITS\ 115 1.6 christos (uint32_t) 116 1.6 christos ROTL32(uint32_t val, 117 1.1 christos long shift) 118 1.1 christos { 119 1.1 christos ASSERT(shift >= 0 && shift <= 32); 120 1.1 christos return _ROTLn(32, val, shift); 121 1.1 christos } 122 1.1 christos 123 1.1 christos 124 1.1 christos INLINE_BITS\ 125 1.6 christos (uint64_t) 126 1.6 christos ROTL64(uint64_t val, 127 1.1 christos long shift) 128 1.1 christos { 129 1.1 christos ASSERT(shift >= 0 && shift <= 64); 130 1.1 christos return _ROTLn(64, val, shift); 131 1.1 christos } 132 1.1 christos 133 1.1 christos #endif /* _BITS_C_ */ 134