< prev index next >

src/hotspot/cpu/aarch64/immediate_aarch64.cpp

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include <stdlib.h>

  26 #include "immediate_aarch64.hpp"
  27 
  28 // there are at most 2^13 possible logical immediate encodings
  29 // however, some combinations of immr and imms are invalid
  30 static const unsigned  LI_TABLE_SIZE = (1 << 13);
  31 
  32 static int li_table_entry_count;
  33 
  34 // for forward lookup we just use a direct array lookup
  35 // and assume that the cient has supplied a valid encoding
  36 // table[encoding] = immediate
  37 static u_int64_t LITable[LI_TABLE_SIZE];
  38 
  39 // for reverse lookup we need a sparse map so we store a table of
  40 // immediate and encoding pairs sorted by immediate value
  41 
  42 struct li_pair {
  43   u_int64_t immediate;
  44   u_int32_t encoding;
  45 };


  51 {
  52   struct li_pair *li1 = (struct li_pair *)i1;
  53   struct li_pair *li2 = (struct li_pair *)i2;
  54   if (li1->immediate < li2->immediate) {
  55     return -1;
  56   }
  57   if (li1->immediate > li2->immediate) {
  58     return 1;
  59   }
  60   return 0;
  61 }
  62 
  63 // helper functions used by expandLogicalImmediate
  64 
  65 // for i = 1, ... N result<i-1> = 1 other bits are zero
  66 static inline u_int64_t ones(int N)
  67 {
  68   return (N == 64 ? (u_int64_t)-1UL : ((1UL << N) - 1));
  69 }
  70 
  71 /*
  72  * bit twiddling helpers for instruction decode
  73  */
  74 
  75 // 32 bit mask with bits [hi,...,lo] set
  76 static inline u_int32_t mask32(int hi = 31, int lo = 0)
  77 {
  78   int nbits = (hi + 1) - lo;
  79   return ((1 << nbits) - 1) << lo;
  80 }
  81 
  82 static inline u_int64_t mask64(int hi = 63, int lo = 0)
  83 {
  84   int nbits = (hi + 1) - lo;
  85   return ((1L << nbits) - 1) << lo;
  86 }
  87 
  88 // pick bits [hi,...,lo] from val
  89 static inline u_int32_t pick32(u_int32_t val, int hi = 31, int lo = 0)
  90 {
  91   return (val & mask32(hi, lo));
  92 }
  93 
  94 // pick bits [hi,...,lo] from val
  95 static inline u_int64_t pick64(u_int64_t val, int hi = 31, int lo = 0)
  96 {
  97   return (val & mask64(hi, lo));
  98 }
  99 
 100 // mask [hi,lo] and shift down to start at bit 0
 101 static inline u_int32_t pickbits32(u_int32_t val, int hi = 31, int lo = 0)
 102 {
 103   return (pick32(val, hi, lo) >> lo);
 104 }
 105 
 106 // mask [hi,lo] and shift down to start at bit 0
 107 static inline u_int64_t pickbits64(u_int64_t val, int hi = 63, int lo = 0)
 108 {
 109   return (pick64(val, hi, lo) >> lo);
 110 }
 111 
 112 // result<0> to val<N>
 113 static inline u_int64_t pickbit(u_int64_t val, int N)
 114 {
 115   return pickbits64(val, N, N);
 116 }
 117 
 118 static inline u_int32_t uimm(u_int32_t val, int hi, int lo)
 119 {
 120   return pickbits32(val, hi, lo);
 121 }
 122 
 123 // SPEC bits(M*N) Replicate(bits(M) x, integer N);
 124 // this is just an educated guess
 125 
 126 u_int64_t replicate(u_int64_t bits, int nbits, int count)
 127 {
 128   u_int64_t result = 0;
 129   // nbits may be 64 in which case we want mask to be -1
 130   u_int64_t mask = ones(nbits);
 131   for (int i = 0; i < count ; i++) {
 132     result <<= nbits;
 133     result |= (bits & mask);
 134   }
 135   return result;
 136 }
 137 
 138 // this function writes the supplied bimm reference and returns a
 139 // boolean to indicate success (1) or fail (0) because an illegal
 140 // encoding must be treated as an UNALLOC instruction
 141 




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include <stdlib.h>
  26 #include "decode_aarch64.hpp"
  27 #include "immediate_aarch64.hpp"
  28 
  29 // there are at most 2^13 possible logical immediate encodings
  30 // however, some combinations of immr and imms are invalid
  31 static const unsigned  LI_TABLE_SIZE = (1 << 13);
  32 
  33 static int li_table_entry_count;
  34 
  35 // for forward lookup we just use a direct array lookup
  36 // and assume that the cient has supplied a valid encoding
  37 // table[encoding] = immediate
  38 static u_int64_t LITable[LI_TABLE_SIZE];
  39 
  40 // for reverse lookup we need a sparse map so we store a table of
  41 // immediate and encoding pairs sorted by immediate value
  42 
  43 struct li_pair {
  44   u_int64_t immediate;
  45   u_int32_t encoding;
  46 };


  52 {
  53   struct li_pair *li1 = (struct li_pair *)i1;
  54   struct li_pair *li2 = (struct li_pair *)i2;
  55   if (li1->immediate < li2->immediate) {
  56     return -1;
  57   }
  58   if (li1->immediate > li2->immediate) {
  59     return 1;
  60   }
  61   return 0;
  62 }
  63 
  64 // helper functions used by expandLogicalImmediate
  65 
  66 // for i = 1, ... N result<i-1> = 1 other bits are zero
  67 static inline u_int64_t ones(int N)
  68 {
  69   return (N == 64 ? (u_int64_t)-1UL : ((1UL << N) - 1));
  70 }
  71 









































  72 // result<0> to val<N>
  73 static inline u_int64_t pickbit(u_int64_t val, int N)
  74 {
  75   return pickbits64(val, N, N);
  76 }
  77 




  78 
  79 // SPEC bits(M*N) Replicate(bits(M) x, integer N);
  80 // this is just an educated guess
  81 
  82 u_int64_t replicate(u_int64_t bits, int nbits, int count)
  83 {
  84   u_int64_t result = 0;
  85   // nbits may be 64 in which case we want mask to be -1
  86   u_int64_t mask = ones(nbits);
  87   for (int i = 0; i < count ; i++) {
  88     result <<= nbits;
  89     result |= (bits & mask);
  90   }
  91   return result;
  92 }
  93 
  94 // this function writes the supplied bimm reference and returns a
  95 // boolean to indicate success (1) or fail (0) because an illegal
  96 // encoding must be treated as an UNALLOC instruction
  97 


< prev index next >