< prev index next >

src/hotspot/cpu/aarch64/immediate_aarch64.cpp

Print this page
rev 60625 : 8248676: AArch64: Add workaround for LITable constructor
Reviewed-by: aph
Contributed-by: mbeckwit, luhenry, burban
rev 60629 : 8248656: Add Windows AArch64 platform support code
Reviewed-by:
Contributed-by: mbeckwit, luhenry, burban


   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 <stdint.h>



  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 uint64_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   uint64_t immediate;
  45   uint32_t encoding;
  46 };


 227     uint64_t or_bits_top = (or_bits_sub << nbits) | 0;
 228 
 229     wmask = ((wmask
 230               & (replicate(and_bits_top, 2 * nbits, 32 / nbits)))
 231              | replicate(or_bits_top, 2 * nbits, 32 / nbits));
 232   }
 233 
 234   if (diff & (1U << 6)) {
 235     imm64 = tmask & wmask;
 236   } else {
 237     imm64 = tmask | wmask;
 238   }
 239 
 240 
 241   bimm = imm64;
 242   return 1;
 243 }
 244 
 245 // constructor to initialise the lookup tables
 246 
 247 static void initLITables() __attribute__ ((constructor));



 248 static void initLITables()
 249 {
 250   li_table_entry_count = 0;
 251   for (unsigned index = 0; index < LI_TABLE_SIZE; index++) {
 252     uint32_t N = uimm(index, 12, 12);
 253     uint32_t immr = uimm(index, 11, 6);
 254     uint32_t imms = uimm(index, 5, 0);
 255     if (expandLogicalImmediate(N, immr, imms, LITable[index])) {
 256       InverseLITable[li_table_entry_count].immediate = LITable[index];
 257       InverseLITable[li_table_entry_count].encoding = index;
 258       li_table_entry_count++;
 259     }
 260   }
 261   // now sort the inverse table
 262   qsort(InverseLITable, li_table_entry_count,
 263         sizeof(InverseLITable[0]), compare_immediate_pair);
 264 }
 265 
 266 // public APIs provided for logical immediate lookup and reverse lookup
 267 




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


 230     uint64_t or_bits_top = (or_bits_sub << nbits) | 0;
 231 
 232     wmask = ((wmask
 233               & (replicate(and_bits_top, 2 * nbits, 32 / nbits)))
 234              | replicate(or_bits_top, 2 * nbits, 32 / nbits));
 235   }
 236 
 237   if (diff & (1U << 6)) {
 238     imm64 = tmask & wmask;
 239   } else {
 240     imm64 = tmask | wmask;
 241   }
 242 
 243 
 244   bimm = imm64;
 245   return 1;
 246 }
 247 
 248 // constructor to initialise the lookup tables
 249 
 250 static void initLITables();
 251 // Use an empty struct with a construtor as MSVC doesn't support `__attribute__ ((constructor))`
 252 // See https://stackoverflow.com/questions/1113409/attribute-constructor-equivalent-in-vc
 253 static struct initLITables_t { initLITables_t(void) { initLITables(); } } _initLITables;
 254 static void initLITables()
 255 {
 256   li_table_entry_count = 0;
 257   for (unsigned index = 0; index < LI_TABLE_SIZE; index++) {
 258     uint32_t N = uimm(index, 12, 12);
 259     uint32_t immr = uimm(index, 11, 6);
 260     uint32_t imms = uimm(index, 5, 0);
 261     if (expandLogicalImmediate(N, immr, imms, LITable[index])) {
 262       InverseLITable[li_table_entry_count].immediate = LITable[index];
 263       InverseLITable[li_table_entry_count].encoding = index;
 264       li_table_entry_count++;
 265     }
 266   }
 267   // now sort the inverse table
 268   qsort(InverseLITable, li_table_entry_count,
 269         sizeof(InverseLITable[0]), compare_immediate_pair);
 270 }
 271 
 272 // public APIs provided for logical immediate lookup and reverse lookup
 273 


< prev index next >