xref: /netbsd-src/external/gpl3/gdb/dist/sim/ppc/bits.c (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
14e98e3e1Schristos /*  This file is part of the program psim.
24e98e3e1Schristos 
34e98e3e1Schristos     Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
44e98e3e1Schristos 
54e98e3e1Schristos     This program is free software; you can redistribute it and/or modify
64e98e3e1Schristos     it under the terms of the GNU General Public License as published by
7a2e2270fSchristos     the Free Software Foundation; either version 3 of the License, or
84e98e3e1Schristos     (at your option) any later version.
94e98e3e1Schristos 
104e98e3e1Schristos     This program is distributed in the hope that it will be useful,
114e98e3e1Schristos     but WITHOUT ANY WARRANTY; without even the implied warranty of
124e98e3e1Schristos     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
134e98e3e1Schristos     GNU General Public License for more details.
144e98e3e1Schristos 
154e98e3e1Schristos     You should have received a copy of the GNU General Public License
16a2e2270fSchristos     along with this program; if not, see <http://www.gnu.org/licenses/>.
174e98e3e1Schristos 
184e98e3e1Schristos     */
194e98e3e1Schristos 
204e98e3e1Schristos 
214e98e3e1Schristos #ifndef _BITS_C_
224e98e3e1Schristos #define _BITS_C_
234e98e3e1Schristos 
244e98e3e1Schristos #include "basics.h"
254e98e3e1Schristos 
264e98e3e1Schristos INLINE_BITS\
27*4b169a6bSchristos (uint64_t)
LSMASKED64(uint64_t word,int start,int stop)28*4b169a6bSchristos LSMASKED64 (uint64_t word,
294e98e3e1Schristos 	    int start,
304e98e3e1Schristos 	    int stop)
314e98e3e1Schristos {
324e98e3e1Schristos   word &= LSMASK64 (start, stop);
334e98e3e1Schristos   return word;
344e98e3e1Schristos }
354e98e3e1Schristos 
364e98e3e1Schristos INLINE_BITS\
37*4b169a6bSchristos (uint64_t)
LSEXTRACTED64(uint64_t val,int start,int stop)38*4b169a6bSchristos LSEXTRACTED64 (uint64_t val,
394e98e3e1Schristos 	       int start,
404e98e3e1Schristos 	       int stop)
414e98e3e1Schristos {
424e98e3e1Schristos   val <<= (64 - 1 - start); /* drop high bits */
434e98e3e1Schristos   val >>= (64 - 1 - start) + (stop); /* drop low bits */
444e98e3e1Schristos   return val;
454e98e3e1Schristos }
464e98e3e1Schristos 
474e98e3e1Schristos INLINE_BITS\
48*4b169a6bSchristos (uint32_t)
MASKED32(uint32_t word,unsigned start,unsigned stop)49*4b169a6bSchristos MASKED32(uint32_t word,
504e98e3e1Schristos 	 unsigned start,
514e98e3e1Schristos 	 unsigned stop)
524e98e3e1Schristos {
534e98e3e1Schristos   return (word & MASK32(start, stop));
544e98e3e1Schristos }
554e98e3e1Schristos 
564e98e3e1Schristos INLINE_BITS\
57*4b169a6bSchristos (uint64_t)
MASKED64(uint64_t word,unsigned start,unsigned stop)58*4b169a6bSchristos MASKED64(uint64_t word,
594e98e3e1Schristos 	 unsigned start,
604e98e3e1Schristos 	 unsigned stop)
614e98e3e1Schristos {
624e98e3e1Schristos   return (word & MASK64(start, stop));
634e98e3e1Schristos }
644e98e3e1Schristos 
654e98e3e1Schristos INLINE_BITS\
664e98e3e1Schristos (unsigned_word)
MASKED(unsigned_word word,unsigned start,unsigned stop)674e98e3e1Schristos MASKED(unsigned_word word,
684e98e3e1Schristos        unsigned start,
694e98e3e1Schristos        unsigned stop)
704e98e3e1Schristos {
714e98e3e1Schristos   return ((word) & MASK(start, stop));
724e98e3e1Schristos }
734e98e3e1Schristos 
744e98e3e1Schristos 
754e98e3e1Schristos 
764e98e3e1Schristos INLINE_BITS\
774e98e3e1Schristos (unsigned_word)
EXTRACTED(unsigned_word word,unsigned start,unsigned stop)784e98e3e1Schristos EXTRACTED(unsigned_word word,
794e98e3e1Schristos 	  unsigned start,
804e98e3e1Schristos 	  unsigned stop)
814e98e3e1Schristos {
824e98e3e1Schristos   ASSERT(start <= stop);
834e98e3e1Schristos #if (WITH_TARGET_WORD_BITSIZE == 64)
844e98e3e1Schristos   return _EXTRACTEDn(64, word, start, stop);
854e98e3e1Schristos #else
864e98e3e1Schristos   if (stop < 32)
874e98e3e1Schristos     return 0;
884e98e3e1Schristos   else
894e98e3e1Schristos     return ((word >> (63 - stop))
904e98e3e1Schristos 	    & MASK(start+(63-stop), 63));
914e98e3e1Schristos #endif
924e98e3e1Schristos }
934e98e3e1Schristos 
944e98e3e1Schristos 
954e98e3e1Schristos INLINE_BITS\
964e98e3e1Schristos (unsigned_word)
INSERTED(unsigned_word word,unsigned start,unsigned stop)974e98e3e1Schristos INSERTED(unsigned_word word,
984e98e3e1Schristos 	 unsigned start,
994e98e3e1Schristos 	 unsigned stop)
1004e98e3e1Schristos {
1014e98e3e1Schristos   ASSERT(start <= stop);
1024e98e3e1Schristos #if (WITH_TARGET_WORD_BITSIZE == 64)
1034e98e3e1Schristos   return _INSERTEDn(64, word, start, stop);
1044e98e3e1Schristos #else
1054e98e3e1Schristos   if (stop < 32)
1064e98e3e1Schristos     return 0;
1074e98e3e1Schristos   else
1084e98e3e1Schristos     return ((word & MASK(start+(63-stop), 63))
1094e98e3e1Schristos 	    << (63 - stop));
1104e98e3e1Schristos #endif
1114e98e3e1Schristos }
1124e98e3e1Schristos 
1134e98e3e1Schristos 
1144e98e3e1Schristos INLINE_BITS\
115*4b169a6bSchristos (uint32_t)
ROTL32(uint32_t val,long shift)116*4b169a6bSchristos ROTL32(uint32_t val,
1174e98e3e1Schristos        long shift)
1184e98e3e1Schristos {
1194e98e3e1Schristos   ASSERT(shift >= 0 && shift <= 32);
1204e98e3e1Schristos   return _ROTLn(32, val, shift);
1214e98e3e1Schristos }
1224e98e3e1Schristos 
1234e98e3e1Schristos 
1244e98e3e1Schristos INLINE_BITS\
125*4b169a6bSchristos (uint64_t)
ROTL64(uint64_t val,long shift)126*4b169a6bSchristos ROTL64(uint64_t val,
1274e98e3e1Schristos        long shift)
1284e98e3e1Schristos {
1294e98e3e1Schristos   ASSERT(shift >= 0 && shift <= 64);
1304e98e3e1Schristos   return _ROTLn(64, val, shift);
1314e98e3e1Schristos }
1324e98e3e1Schristos 
1334e98e3e1Schristos #endif /* _BITS_C_ */
134