1 /*
  2  * Copyright (c) 2013, 2021, 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 = 35300 LP64_ONLY(+35000)          // 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_sp_entry;
 46 
 47   static address _f2i_fixup;
 48   static address _f2l_fixup;
 49   static address _d2i_fixup;
 50   static address _d2l_fixup;
 51 
 52   static address _float_sign_mask;
 53   static address _float_sign_flip;
 54   static address _double_sign_mask;
 55   static address _double_sign_flip;
 56 
 57  public:
 58 
 59   static address get_previous_sp_entry() {
 60     return _get_previous_sp_entry;
 61   }
 62 
 63   static address f2i_fixup() {
 64     return _f2i_fixup;
 65   }
 66 
 67   static address f2l_fixup() {
 68     return _f2l_fixup;
 69   }
 70 
 71   static address d2i_fixup() {
 72     return _d2i_fixup;
 73   }
 74 
 75   static address d2l_fixup() {
 76     return _d2l_fixup;
 77   }
 78 
 79   static address float_sign_mask() {
 80     return _float_sign_mask;
 81   }
 82 
 83   static address float_sign_flip() {
 84     return _float_sign_flip;
 85   }
 86 
 87   static address double_sign_mask() {
 88     return _double_sign_mask;
 89   }
 90 
 91   static address double_sign_flip() {
 92     return _double_sign_flip;
 93   }
 94 
 95 #else // !LP64
 96 
 97  private:
 98   static address _verify_fpu_cntrl_wrd_entry;
 99   static address _d2i_wrapper;
100   static address _d2l_wrapper;
101 
102   static jint    _fpu_cntrl_wrd_std;
103   static jint    _fpu_cntrl_wrd_24;
104   static jint    _fpu_cntrl_wrd_trunc;
105 
106   static jint    _fpu_subnormal_bias1[3];
107   static jint    _fpu_subnormal_bias2[3];
108 
109  public:
110   static address verify_fpu_cntrl_wrd_entry() { return _verify_fpu_cntrl_wrd_entry; }
111   static address d2i_wrapper()                { return _d2i_wrapper; }
112   static address d2l_wrapper()                { return _d2l_wrapper; }
113   static address addr_fpu_cntrl_wrd_std()     { return (address)&_fpu_cntrl_wrd_std;   }
114   static address addr_fpu_cntrl_wrd_24()      { return (address)&_fpu_cntrl_wrd_24;    }
115   static address addr_fpu_cntrl_wrd_trunc()   { return (address)&_fpu_cntrl_wrd_trunc; }
116   static address addr_fpu_subnormal_bias1()   { return (address)&_fpu_subnormal_bias1; }
117   static address addr_fpu_subnormal_bias2()   { return (address)&_fpu_subnormal_bias2; }
118 
119   static jint    fpu_cntrl_wrd_std()          { return _fpu_cntrl_wrd_std; }
120 #endif // !LP64
121 
122  private:
123   static jint    _mxcsr_std;
124 
125   static address _verify_mxcsr_entry;
126   // shuffle mask for fixing up 128-bit words consisting of big-endian 32-bit integers
127   static address _key_shuffle_mask_addr;
128 
129   //shuffle mask for big-endian 128-bit integers
130   static address _counter_shuffle_mask_addr;
131 
132   static address _method_entry_barrier;
133 
134   // masks and table for CRC32
135   static uint64_t _crc_by128_masks[];
136   static juint    _crc_table[];
137 #ifdef _LP64
138   static juint    _crc_by128_masks_avx512[];
139   static juint    _crc_table_avx512[];
140   static juint    _shuf_table_crc32_avx512[];
141   static juint    _adler32_shuf0_table[];
142   static juint    _adler32_shuf1_table[];
143   static juint    _adler32_ascale_table[];
144 #endif // _LP64
145   // table for CRC32C
146   static juint* _crc32c_table;
147   // swap mask for ghash
148   static address _ghash_long_swap_mask_addr;
149   static address _ghash_byte_swap_mask_addr;
150   static address _ghash_poly_addr;
151   static address _ghash_shuffmask_addr;
152 
153   // upper word mask for sha1
154   static address _upper_word_mask_addr;
155   // byte flip mask for sha1
156   static address _shuffle_byte_flip_mask_addr;
157 
158   //k256 table for sha256
159   static juint _k256[];
160   static address _k256_adr;
161   static address _vector_short_to_byte_mask;
162   static address _vector_float_sign_mask;
163   static address _vector_float_sign_flip;
164   static address _vector_double_sign_mask;
165   static address _vector_double_sign_flip;
166   static address _vector_long_sign_mask;
167   static address _vector_all_bits_set;
168   static address _vector_int_mask_cmp_bits;
169   static address _vector_byte_perm_mask;
170   static address _vector_int_to_byte_mask;
171   static address _vector_int_to_short_mask;
172   static address _vector_32_bit_mask;
173   static address _vector_64_bit_mask;
174   static address _vector_int_shuffle_mask;
175   static address _vector_byte_shuffle_mask;
176   static address _vector_short_shuffle_mask;
177   static address _vector_long_shuffle_mask;
178   static address _vector_iota_indices;
179 #ifdef _LP64
180   static juint _k256_W[];
181   static address _k256_W_adr;
182   static julong _k512_W[];
183   static address _k512_W_addr;
184   // byte flip mask for sha512
185   static address _pshuffle_byte_flip_mask_addr_sha512;
186   static address _counter_mask_addr;
187   // Masks for base64
188   static address _encoding_table_base64;
189   static address _shuffle_base64;
190   static address _avx2_shuffle_base64;
191   static address _avx2_input_mask_base64;
192   static address _avx2_lut_base64;
193   static address _lookup_lo_base64;
194   static address _lookup_hi_base64;
195   static address _lookup_lo_base64url;
196   static address _lookup_hi_base64url;
197   static address _pack_vec_base64;
198   static address _join_0_1_base64;
199   static address _join_1_2_base64;
200   static address _join_2_3_base64;
201   static address _decoding_table_base64;
202   static address _ghash_poly512_addr;
203 #endif
204   // byte flip mask for sha256
205   static address _pshuffle_byte_flip_mask_addr;
206 
207   //tables common for LIBM sin and cos
208   static juint _ONEHALF[];
209   static address _ONEHALF_adr;
210   static juint _P_2[];
211   static address _P_2_adr;
212   static juint _SC_4[];
213   static address _SC_4_adr;
214   static juint _Ctable[];
215   static address _Ctable_adr;
216   static juint _SC_2[];
217   static address _SC_2_adr;
218   static juint _SC_3[];
219   static address _SC_3_adr;
220   static juint _SC_1[];
221   static address _SC_1_adr;
222   static juint _PI_INV_TABLE[];
223   static address _PI_INV_TABLE_adr;
224   static juint _PI_4[];
225   static address _PI_4_adr;
226   static juint _PI32INV[];
227   static address _PI32INV_adr;
228   static juint _SIGN_MASK[];
229   static address _SIGN_MASK_adr;
230   static juint _P_1[];
231   static address _P_1_adr;
232   static juint _P_3[];
233   static address _P_3_adr;
234   static juint _NEG_ZERO[];
235   static address _NEG_ZERO_adr;
236 
237   //tables common for LIBM sincos and tancot
238   static juint _L_2il0floatpacket_0[];
239   static address _L_2il0floatpacket_0_adr;
240   static juint _Pi4Inv[];
241   static address _Pi4Inv_adr;
242   static juint _Pi4x3[];
243   static address _Pi4x3_adr;
244   static juint _Pi4x4[];
245   static address _Pi4x4_adr;
246   static juint _ones[];
247   static address _ones_adr;
248 
249  public:
250   static address addr_mxcsr_std()        { return (address)&_mxcsr_std; }
251   static address verify_mxcsr_entry()    { return _verify_mxcsr_entry; }
252   static address key_shuffle_mask_addr() { return _key_shuffle_mask_addr; }
253   static address counter_shuffle_mask_addr() { return _counter_shuffle_mask_addr; }
254   static address crc_by128_masks_addr()  { return (address)_crc_by128_masks; }
255 #ifdef _LP64
256   static address crc_by128_masks_avx512_addr()  { return (address)_crc_by128_masks_avx512; }
257   static address shuf_table_crc32_avx512_addr()  { return (address)_shuf_table_crc32_avx512; }
258   static address crc_table_avx512_addr()  { return (address)_crc_table_avx512; }
259   static address ghash_polynomial512_addr() { return _ghash_poly512_addr; }
260 #endif // _LP64
261   static address ghash_long_swap_mask_addr() { return _ghash_long_swap_mask_addr; }
262   static address ghash_byte_swap_mask_addr() { return _ghash_byte_swap_mask_addr; }
263   static address ghash_shufflemask_addr() { return _ghash_shuffmask_addr; }
264   static address ghash_polynomial_addr() { return _ghash_poly_addr; }
265   static address upper_word_mask_addr() { return _upper_word_mask_addr; }
266   static address shuffle_byte_flip_mask_addr() { return _shuffle_byte_flip_mask_addr; }
267   static address k256_addr()      { return _k256_adr; }
268   static address method_entry_barrier() { return _method_entry_barrier; }
269 
270   static address vector_short_to_byte_mask() {
271     return _vector_short_to_byte_mask;
272   }
273   static address vector_float_sign_mask() {
274     return _vector_float_sign_mask;
275   }
276 
277   static address vector_float_sign_flip() {
278     return _vector_float_sign_flip;
279   }
280 
281   static address vector_double_sign_mask() {
282     return _vector_double_sign_mask;
283   }
284 
285   static address vector_double_sign_flip() {
286     return _vector_double_sign_flip;
287   }
288 
289   static address vector_all_bits_set() {
290     return _vector_all_bits_set;
291   }
292 
293   static address vector_int_mask_cmp_bits() {
294     return _vector_int_mask_cmp_bits;
295   }
296 
297   static address vector_byte_perm_mask() {
298     return _vector_byte_perm_mask;
299   }
300 
301   static address vector_int_to_byte_mask() {
302     return _vector_int_to_byte_mask;
303   }
304 
305   static address vector_int_to_short_mask() {
306     return _vector_int_to_short_mask;
307   }
308 
309   static address vector_32_bit_mask() {
310     return _vector_32_bit_mask;
311   }
312 
313   static address vector_64_bit_mask() {
314     return _vector_64_bit_mask;
315   }
316 
317   static address vector_int_shuffle_mask() {
318     return _vector_int_shuffle_mask;
319   }
320 
321   static address vector_byte_shuffle_mask() {
322     return _vector_byte_shuffle_mask;
323   }
324 
325   static address vector_short_shuffle_mask() {
326     return _vector_short_shuffle_mask;
327   }
328 
329   static address vector_long_shuffle_mask() {
330     return _vector_long_shuffle_mask;
331   }
332 
333   static address vector_long_sign_mask() {
334     return _vector_long_sign_mask;
335   }
336 
337   static address vector_iota_indices() {
338     return _vector_iota_indices;
339   }
340 
341 #ifdef _LP64
342   static address k256_W_addr()    { return _k256_W_adr; }
343   static address k512_W_addr()    { return _k512_W_addr; }
344   static address pshuffle_byte_flip_mask_addr_sha512() { return _pshuffle_byte_flip_mask_addr_sha512; }
345   static address base64_encoding_table_addr() { return _encoding_table_base64; }
346   static address base64_shuffle_addr() { return _shuffle_base64; }
347   static address base64_avx2_shuffle_addr() { return _avx2_shuffle_base64; }
348   static address base64_avx2_input_mask_addr() { return _avx2_input_mask_base64; }
349   static address base64_avx2_lut_addr() { return _avx2_lut_base64; }
350   static address counter_mask_addr() { return _counter_mask_addr; }
351   static address base64_vbmi_lookup_lo_addr() { return _lookup_lo_base64; }
352   static address base64_vbmi_lookup_hi_addr() { return _lookup_hi_base64; }
353   static address base64_vbmi_lookup_lo_url_addr() { return _lookup_lo_base64url; }
354   static address base64_vbmi_lookup_hi_url_addr() { return _lookup_hi_base64url; }
355   static address base64_vbmi_pack_vec_addr() { return _pack_vec_base64; }
356   static address base64_vbmi_join_0_1_addr() { return _join_0_1_base64; }
357   static address base64_vbmi_join_1_2_addr() { return _join_1_2_base64; }
358   static address base64_vbmi_join_2_3_addr() { return _join_2_3_base64; }
359   static address base64_decoding_table_addr() { return _decoding_table_base64; }
360 #endif
361   static address pshuffle_byte_flip_mask_addr() { return _pshuffle_byte_flip_mask_addr; }
362   static void generate_CRC32C_table(bool is_pclmulqdq_supported);
363   static address _ONEHALF_addr()      { return _ONEHALF_adr; }
364   static address _P_2_addr()      { return _P_2_adr; }
365   static address _SC_4_addr()      { return _SC_4_adr; }
366   static address _Ctable_addr()      { return _Ctable_adr; }
367   static address _SC_2_addr()      { return _SC_2_adr; }
368   static address _SC_3_addr()      { return _SC_3_adr; }
369   static address _SC_1_addr()      { return _SC_1_adr; }
370   static address _PI_INV_TABLE_addr()      { return _PI_INV_TABLE_adr; }
371   static address _PI_4_addr()      { return _PI_4_adr; }
372   static address _PI32INV_addr()      { return _PI32INV_adr; }
373   static address _SIGN_MASK_addr()      { return _SIGN_MASK_adr; }
374   static address _P_1_addr()      { return _P_1_adr; }
375   static address _P_3_addr()      { return _P_3_adr; }
376   static address _NEG_ZERO_addr()      { return _NEG_ZERO_adr; }
377   static address _L_2il0floatpacket_0_addr()      { return _L_2il0floatpacket_0_adr; }
378   static address _Pi4Inv_addr()      { return _Pi4Inv_adr; }
379   static address _Pi4x3_addr()      { return _Pi4x3_adr; }
380   static address _Pi4x4_addr()      { return _Pi4x4_adr; }
381   static address _ones_addr()      { return _ones_adr; }
382 
383 };
384 
385 #endif // CPU_X86_STUBROUTINES_X86_HPP