1 /*
   2  * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   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 #ifndef CPU_X86_STUBROUTINES_X86_HPP
  26 #define CPU_X86_STUBROUTINES_X86_HPP
  27 
  28 // This file holds the platform specific parts of the StubRoutines
  29 // definition. See stubRoutines.hpp for a description on how to
  30 // extend it.
  31 
  32 static bool returns_to_call_stub(address return_pc) { return return_pc == _call_stub_return_address; }
  33 
  34 enum platform_dependent_constants {
  35   code_size1 = 20000 LP64_ONLY(+10000),         // simply increase if too small (assembler will crash if too small)
  36   code_size2 = 35800 LP64_ONLY(+11000)          // simply increase if too small (assembler will crash if too small)
  37 };
  38 
  39 class x86 {
  40  friend class StubGenerator;
  41  friend class VMStructs;
  42 
  43 #ifdef _LP64
  44  private:
  45   static address _get_previous_fp_entry;
  46   static address _get_previous_sp_entry;
  47 
  48   static address _f2i_fixup;
  49   static address _f2l_fixup;
  50   static address _d2i_fixup;
  51   static address _d2l_fixup;
  52 
  53   static address _vector_iota_indices;
  54   static address _float_sign_mask;
  55   static address _float_sign_flip;
  56   static address _double_sign_mask;
  57   static address _double_sign_flip;
  58   static address _vector_float_sign_mask;
  59   static address _vector_float_sign_flip;
  60   static address _vector_double_sign_mask;
  61   static address _vector_double_sign_flip;
  62   static address _vector_all_bits_set;
  63   static address _vector_byte_bitset;
  64   static address _vector_long_perm_mask;
  65   static address _vector_short_to_byte_mask;
  66   static address _vector_byte_perm_mask;
  67   static address _vector_int_to_byte_mask;
  68   static address _vector_int_to_short_mask;
  69   static address _vector_32_bit_mask;
  70   static address _vector_64_bit_mask;
  71   static address _vector_int_shuffle_mask;
  72   static address _vector_int_size_mask; 
  73   static address _vector_short_shuffle_mask;
  74   static address _vector_short_size_mask;
  75   static address _vector_long_shuffle_mask;
  76   static address _vector_long_size_mask;
  77 
  78   static address _method_entry_barrier;
  79 
  80  public:
  81 
  82   static address method_entry_barrier() {
  83     return _method_entry_barrier;
  84   }
  85 
  86   static address get_previous_fp_entry() {
  87     return _get_previous_fp_entry;
  88   }
  89 
  90   static address get_previous_sp_entry() {
  91     return _get_previous_sp_entry;
  92   }
  93 
  94   static address f2i_fixup() {
  95     return _f2i_fixup;
  96   }
  97 
  98   static address f2l_fixup() {
  99     return _f2l_fixup;
 100   }
 101 
 102   static address d2i_fixup() {
 103     return _d2i_fixup;
 104   }
 105 
 106   static address d2l_fixup() {
 107     return _d2l_fixup;
 108   }
 109 
 110   static address float_sign_mask() {
 111     return _float_sign_mask;
 112   }
 113 
 114   static address float_sign_flip() {
 115     return _float_sign_flip;
 116   }
 117 
 118   static address double_sign_mask() {
 119     return _double_sign_mask;
 120   }
 121 
 122   static address double_sign_flip() {
 123     return _double_sign_flip;
 124   }
 125 
 126   static address vector_float_sign_mask() {
 127     return _vector_float_sign_mask;
 128   }
 129 
 130   static address vector_float_sign_flip() {
 131     return _vector_float_sign_flip;
 132   }
 133 
 134   static address vector_double_sign_mask() {
 135     return _vector_double_sign_mask;
 136   }
 137 
 138   static address vector_double_sign_flip() {
 139     return _vector_double_sign_flip;
 140   }
 141 
 142   static address vector_all_bits_set() {
 143     return _vector_all_bits_set;
 144   }
 145 
 146   static address vector_byte_bitset() {
 147     return _vector_byte_bitset;
 148   }
 149 
 150   static address vector_iota_indices() {
 151     return _vector_iota_indices;
 152   }
 153 
 154   static address vector_long_perm_mask() {
 155     return _vector_long_perm_mask;
 156   }
 157 
 158   static address vector_short_to_byte_mask() {
 159     return _vector_short_to_byte_mask;
 160   }
 161 
 162   static address vector_byte_perm_mask() {
 163     return _vector_byte_perm_mask;
 164   }
 165 
 166   static address vector_int_to_byte_mask() {
 167     return _vector_int_to_byte_mask;
 168   }
 169 
 170   static address vector_int_to_short_mask() {
 171     return _vector_int_to_short_mask;
 172   }
 173 
 174   static address vector_32_bit_mask() {
 175     return _vector_32_bit_mask;
 176   }
 177 
 178   static address vector_64_bit_mask() {
 179     return _vector_64_bit_mask;
 180   }
 181 
 182   static address vector_all_ones_mask() {
 183     return _vector_double_sign_flip;
 184   }
 185   static address vector_int_shuffle_mask() {
 186     return _vector_int_shuffle_mask;
 187   }
 188   static address vector_int_size_mask() {
 189     return _vector_int_size_mask;
 190   }
 191   static address vector_short_shuffle_mask() {
 192     return _vector_short_shuffle_mask;
 193   }
 194   static address vector_short_size_mask() {
 195     return _vector_short_size_mask;
 196   }
 197   static address vector_long_shuffle_mask() {
 198     return _vector_long_shuffle_mask;
 199   }
 200   static address vector_long_size_mask() {
 201     return _vector_long_size_mask;
 202   }
 203 #else // !LP64
 204 
 205  private:
 206   static address _verify_fpu_cntrl_wrd_entry;
 207 
 208  public:
 209   static address verify_fpu_cntrl_wrd_entry() { return _verify_fpu_cntrl_wrd_entry; }
 210 
 211 #endif // !LP64
 212 
 213  private:
 214   static address _verify_mxcsr_entry;
 215   // shuffle mask for fixing up 128-bit words consisting of big-endian 32-bit integers
 216   static address _key_shuffle_mask_addr;
 217 
 218   //shuffle mask for big-endian 128-bit integers
 219   static address _counter_shuffle_mask_addr;
 220 
 221   // masks and table for CRC32
 222   static uint64_t _crc_by128_masks[];
 223   static juint    _crc_table[];
 224   // table for CRC32C
 225   static juint* _crc32c_table;
 226   // swap mask for ghash
 227   static address _ghash_long_swap_mask_addr;
 228   static address _ghash_byte_swap_mask_addr;
 229   static address _ghash_poly_addr;
 230   static address _ghash_shuffmask_addr;
 231 
 232   // upper word mask for sha1
 233   static address _upper_word_mask_addr;
 234   // byte flip mask for sha1
 235   static address _shuffle_byte_flip_mask_addr;
 236 
 237   //k256 table for sha256
 238   static juint _k256[];
 239   static address _k256_adr;
 240 #ifdef _LP64
 241   static juint _k256_W[];
 242   static address _k256_W_adr;
 243   static julong _k512_W[];
 244   static address _k512_W_addr;
 245   // byte flip mask for sha512
 246   static address _pshuffle_byte_flip_mask_addr_sha512;
 247   // Masks for base64
 248   static address _base64_charset;
 249   static address _bswap_mask;
 250   static address _gather_mask;
 251   static address _right_shift_mask;
 252   static address _left_shift_mask;
 253   static address _and_mask;
 254   static address _url_charset;
 255 #endif
 256   // byte flip mask for sha256
 257   static address _pshuffle_byte_flip_mask_addr;
 258 
 259   //tables common for LIBM sin and cos
 260   static juint _ONEHALF[];
 261   static address _ONEHALF_adr;
 262   static juint _P_2[];
 263   static address _P_2_adr;
 264   static juint _SC_4[];
 265   static address _SC_4_adr;
 266   static juint _Ctable[];
 267   static address _Ctable_adr;
 268   static juint _SC_2[];
 269   static address _SC_2_adr;
 270   static juint _SC_3[];
 271   static address _SC_3_adr;
 272   static juint _SC_1[];
 273   static address _SC_1_adr;
 274   static juint _PI_INV_TABLE[];
 275   static address _PI_INV_TABLE_adr;
 276   static juint _PI_4[];
 277   static address _PI_4_adr;
 278   static juint _PI32INV[];
 279   static address _PI32INV_adr;
 280   static juint _SIGN_MASK[];
 281   static address _SIGN_MASK_adr;
 282   static juint _P_1[];
 283   static address _P_1_adr;
 284   static juint _P_3[];
 285   static address _P_3_adr;
 286   static juint _NEG_ZERO[];
 287   static address _NEG_ZERO_adr;
 288 
 289   //tables common for LIBM sincos and tancot
 290   static juint _L_2il0floatpacket_0[];
 291   static address _L_2il0floatpacket_0_adr;
 292   static juint _Pi4Inv[];
 293   static address _Pi4Inv_adr;
 294   static juint _Pi4x3[];
 295   static address _Pi4x3_adr;
 296   static juint _Pi4x4[];
 297   static address _Pi4x4_adr;
 298   static juint _ones[];
 299   static address _ones_adr;
 300 
 301  public:
 302   static address verify_mxcsr_entry()    { return _verify_mxcsr_entry; }
 303   static address key_shuffle_mask_addr() { return _key_shuffle_mask_addr; }
 304   static address counter_shuffle_mask_addr() { return _counter_shuffle_mask_addr; }
 305   static address crc_by128_masks_addr()  { return (address)_crc_by128_masks; }
 306   static address ghash_long_swap_mask_addr() { return _ghash_long_swap_mask_addr; }
 307   static address ghash_byte_swap_mask_addr() { return _ghash_byte_swap_mask_addr; }
 308   static address ghash_shufflemask_addr() { return _ghash_shuffmask_addr; }
 309   static address ghash_polynomial_addr() { return _ghash_poly_addr; }
 310   static address upper_word_mask_addr() { return _upper_word_mask_addr; }
 311   static address shuffle_byte_flip_mask_addr() { return _shuffle_byte_flip_mask_addr; }
 312   static address k256_addr()      { return _k256_adr; }
 313 #ifdef _LP64
 314   static address k256_W_addr()    { return _k256_W_adr; }
 315   static address k512_W_addr()    { return _k512_W_addr; }
 316   static address pshuffle_byte_flip_mask_addr_sha512() { return _pshuffle_byte_flip_mask_addr_sha512; }
 317   static address base64_charset_addr() { return _base64_charset; }
 318   static address base64url_charset_addr() { return _url_charset; }
 319   static address base64_bswap_mask_addr() { return _bswap_mask; }
 320   static address base64_gather_mask_addr() { return _gather_mask; }
 321   static address base64_right_shift_mask_addr() { return _right_shift_mask; }
 322   static address base64_left_shift_mask_addr() { return _left_shift_mask; }
 323   static address base64_and_mask_addr() { return _and_mask; }
 324 #endif
 325   static address pshuffle_byte_flip_mask_addr() { return _pshuffle_byte_flip_mask_addr; }
 326   static void generate_CRC32C_table(bool is_pclmulqdq_supported);
 327   static address _ONEHALF_addr()      { return _ONEHALF_adr; }
 328   static address _P_2_addr()      { return _P_2_adr; }
 329   static address _SC_4_addr()      { return _SC_4_adr; }
 330   static address _Ctable_addr()      { return _Ctable_adr; }
 331   static address _SC_2_addr()      { return _SC_2_adr; }
 332   static address _SC_3_addr()      { return _SC_3_adr; }
 333   static address _SC_1_addr()      { return _SC_1_adr; }
 334   static address _PI_INV_TABLE_addr()      { return _PI_INV_TABLE_adr; }
 335   static address _PI_4_addr()      { return _PI_4_adr; }
 336   static address _PI32INV_addr()      { return _PI32INV_adr; }
 337   static address _SIGN_MASK_addr()      { return _SIGN_MASK_adr; }
 338   static address _P_1_addr()      { return _P_1_adr; }
 339   static address _P_3_addr()      { return _P_3_adr; }
 340   static address _NEG_ZERO_addr()      { return _NEG_ZERO_adr; }
 341   static address _L_2il0floatpacket_0_addr()      { return _L_2il0floatpacket_0_adr; }
 342   static address _Pi4Inv_addr()      { return _Pi4Inv_adr; }
 343   static address _Pi4x3_addr()      { return _Pi4x3_adr; }
 344   static address _Pi4x4_addr()      { return _Pi4x4_adr; }
 345   static address _ones_addr()      { return _ones_adr; }
 346 
 347 };
 348 
 349 #endif // CPU_X86_STUBROUTINES_X86_HPP