1 /*
 2  * Copyright (c) 2015, 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 #include "precompiled.hpp"
26 #include "runtime/registerMap.hpp"
27 #include "vmreg_x86.inline.hpp"
28 
29 address RegisterMap::pd_location(VMReg reg) const {
30   if (reg->is_XMMRegister()) {
31     int reg_base = reg->value() - ConcreteRegisterImpl::max_fpr;
32     int base_reg_enc = (reg_base / XMMRegisterImpl::max_slots_per_register);
33     assert(base_reg_enc >= 0 && base_reg_enc < XMMRegisterImpl::number_of_registers, "invalid XMMRegister: %d", base_reg_enc);
34     VMReg base_reg = as_XMMRegister(base_reg_enc)->as_VMReg();
35     intptr_t offset_in_bytes = (reg->value() - base_reg->value()) * VMRegImpl::stack_slot_size;
36     if (base_reg_enc > 15) {
37       if (offset_in_bytes == 0) {
38         return NULL; // ZMM16-31 are stored in full.
39       }
40     } else {
41       if (offset_in_bytes == 0 || offset_in_bytes == 16 || offset_in_bytes == 32) {
42         // Reads of the low and high 16 byte parts should be handled by location itself because
43         // they have separate callee saved entries (see RegisterSaver::save_live_registers()).
44         return NULL;
45       }
46       // The upper part of YMM0-15 and ZMM0-15 registers are saved separately in the frame.
47       if (offset_in_bytes > 32) {
48         base_reg = base_reg->next(8);
49         offset_in_bytes -= 32;
50       } else if (offset_in_bytes > 16) {
51         base_reg = base_reg->next(4);
52         offset_in_bytes -= 16;
53       } else {
54         // XMM0-15 case (0 < offset_in_bytes < 16). No need to adjust base register (or offset).
55       }
56     }
57     address base_location = location(base_reg);
58     if (base_location != NULL) {
59       return base_location + offset_in_bytes;
60     }
61   }
62   return NULL;
63 }
64 
65 address RegisterMap::pd_location(VMReg base_reg, int slot_idx) const {
66   return location(base_reg->next(slot_idx));
67 }




--- EOF ---