hotspot/src/cpu/x86/vm/vm_version_x86.cpp
author twisti
Fri, 13 Mar 2009 11:35:17 -0700
changeset 2255 54abdf3e1055
parent 2111 dab8a43dd738
child 2348 4e71ed4c2709
permissions -rw-r--r--
6378821: bitCount() should use POPC on SPARC processors and AMD+10h Summary: bitCount() should use POPC on SPARC processors where POPC is implemented directly in hardware. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2111
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     1
/*
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     2
 * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     4
 *
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     8
 *
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    13
 * accompanied this code).
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    14
 *
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    18
 *
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    21
 * have any questions.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    22
 *
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    23
 */
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    24
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    26
# include "incls/_vm_version_x86.cpp.incl"
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    27
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    28
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    29
int VM_Version::_cpu;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    30
int VM_Version::_model;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    31
int VM_Version::_stepping;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    32
int VM_Version::_cpuFeatures;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    33
const char*           VM_Version::_features_str = "";
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    34
VM_Version::CpuidInfo VM_Version::_cpuid_info   = { 0, };
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    35
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    36
static BufferBlob* stub_blob;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    37
static const int stub_size = 300;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    38
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    39
extern "C" {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    40
  typedef void (*getPsrInfo_stub_t)(void*);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    41
}
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    42
static getPsrInfo_stub_t getPsrInfo_stub = NULL;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    43
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    44
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    45
class VM_Version_StubGenerator: public StubCodeGenerator {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    46
 public:
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    47
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    48
  VM_Version_StubGenerator(CodeBuffer *c) : StubCodeGenerator(c) {}
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    49
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    50
  address generate_getPsrInfo() {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    51
    // Flags to test CPU type.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    52
    const uint32_t EFL_AC           = 0x40000;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    53
    const uint32_t EFL_ID           = 0x200000;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    54
    // Values for when we don't have a CPUID instruction.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    55
    const int      CPU_FAMILY_SHIFT = 8;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    56
    const uint32_t CPU_FAMILY_386   = (3 << CPU_FAMILY_SHIFT);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    57
    const uint32_t CPU_FAMILY_486   = (4 << CPU_FAMILY_SHIFT);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    58
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    59
    Label detect_486, cpu486, detect_586, std_cpuid1;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    60
    Label ext_cpuid1, ext_cpuid5, done;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    61
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    62
    StubCodeMark mark(this, "VM_Version", "getPsrInfo_stub");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    63
#   define __ _masm->
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    64
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    65
    address start = __ pc();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    66
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    67
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    68
    // void getPsrInfo(VM_Version::CpuidInfo* cpuid_info);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    69
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    70
    // LP64: rcx and rdx are first and second argument registers on windows
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    71
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    72
    __ push(rbp);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    73
#ifdef _LP64
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    74
    __ mov(rbp, c_rarg0); // cpuid_info address
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    75
#else
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    76
    __ movptr(rbp, Address(rsp, 8)); // cpuid_info address
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    77
#endif
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    78
    __ push(rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    79
    __ push(rsi);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    80
    __ pushf();          // preserve rbx, and flags
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    81
    __ pop(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    82
    __ push(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    83
    __ mov(rcx, rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    84
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    85
    // if we are unable to change the AC flag, we have a 386
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    86
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    87
    __ xorl(rax, EFL_AC);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    88
    __ push(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    89
    __ popf();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    90
    __ pushf();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    91
    __ pop(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    92
    __ cmpptr(rax, rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    93
    __ jccb(Assembler::notEqual, detect_486);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    94
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    95
    __ movl(rax, CPU_FAMILY_386);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    96
    __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    97
    __ jmp(done);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    98
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
    99
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   100
    // If we are unable to change the ID flag, we have a 486 which does
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   101
    // not support the "cpuid" instruction.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   102
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   103
    __ bind(detect_486);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   104
    __ mov(rax, rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   105
    __ xorl(rax, EFL_ID);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   106
    __ push(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   107
    __ popf();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   108
    __ pushf();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   109
    __ pop(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   110
    __ cmpptr(rcx, rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   111
    __ jccb(Assembler::notEqual, detect_586);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   112
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   113
    __ bind(cpu486);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   114
    __ movl(rax, CPU_FAMILY_486);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   115
    __ movl(Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   116
    __ jmp(done);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   117
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   118
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   119
    // At this point, we have a chip which supports the "cpuid" instruction
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   120
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   121
    __ bind(detect_586);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   122
    __ xorl(rax, rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   123
    __ cpuid();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   124
    __ orl(rax, rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   125
    __ jcc(Assembler::equal, cpu486);   // if cpuid doesn't support an input
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   126
                                        // value of at least 1, we give up and
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   127
                                        // assume a 486
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   128
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid0_offset())));
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   129
    __ movl(Address(rsi, 0), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   130
    __ movl(Address(rsi, 4), rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   131
    __ movl(Address(rsi, 8), rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   132
    __ movl(Address(rsi,12), rdx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   133
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   134
    __ cmpl(rax, 3);     // Is cpuid(0x4) supported?
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   135
    __ jccb(Assembler::belowEqual, std_cpuid1);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   136
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   137
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   138
    // cpuid(0x4) Deterministic cache params
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   139
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   140
    __ movl(rax, 4);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   141
    __ xorl(rcx, rcx);   // L1 cache
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   142
    __ cpuid();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   143
    __ push(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   144
    __ andl(rax, 0x1f);  // Determine if valid cache parameters used
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   145
    __ orl(rax, rax);    // eax[4:0] == 0 indicates invalid cache
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   146
    __ pop(rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   147
    __ jccb(Assembler::equal, std_cpuid1);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   148
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   149
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::dcp_cpuid4_offset())));
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   150
    __ movl(Address(rsi, 0), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   151
    __ movl(Address(rsi, 4), rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   152
    __ movl(Address(rsi, 8), rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   153
    __ movl(Address(rsi,12), rdx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   154
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   155
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   156
    // Standard cpuid(0x1)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   157
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   158
    __ bind(std_cpuid1);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   159
    __ movl(rax, 1);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   160
    __ cpuid();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   161
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::std_cpuid1_offset())));
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   162
    __ movl(Address(rsi, 0), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   163
    __ movl(Address(rsi, 4), rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   164
    __ movl(Address(rsi, 8), rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   165
    __ movl(Address(rsi,12), rdx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   166
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   167
    __ movl(rax, 0x80000000);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   168
    __ cpuid();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   169
    __ cmpl(rax, 0x80000000);     // Is cpuid(0x80000001) supported?
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   170
    __ jcc(Assembler::belowEqual, done);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   171
    __ cmpl(rax, 0x80000004);     // Is cpuid(0x80000005) supported?
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   172
    __ jccb(Assembler::belowEqual, ext_cpuid1);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   173
    __ cmpl(rax, 0x80000007);     // Is cpuid(0x80000008) supported?
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   174
    __ jccb(Assembler::belowEqual, ext_cpuid5);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   175
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   176
    // Extended cpuid(0x80000008)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   177
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   178
    __ movl(rax, 0x80000008);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   179
    __ cpuid();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   180
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid8_offset())));
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   181
    __ movl(Address(rsi, 0), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   182
    __ movl(Address(rsi, 4), rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   183
    __ movl(Address(rsi, 8), rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   184
    __ movl(Address(rsi,12), rdx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   185
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   186
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   187
    // Extended cpuid(0x80000005)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   188
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   189
    __ bind(ext_cpuid5);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   190
    __ movl(rax, 0x80000005);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   191
    __ cpuid();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   192
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid5_offset())));
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   193
    __ movl(Address(rsi, 0), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   194
    __ movl(Address(rsi, 4), rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   195
    __ movl(Address(rsi, 8), rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   196
    __ movl(Address(rsi,12), rdx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   197
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   198
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   199
    // Extended cpuid(0x80000001)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   200
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   201
    __ bind(ext_cpuid1);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   202
    __ movl(rax, 0x80000001);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   203
    __ cpuid();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   204
    __ lea(rsi, Address(rbp, in_bytes(VM_Version::ext_cpuid1_offset())));
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   205
    __ movl(Address(rsi, 0), rax);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   206
    __ movl(Address(rsi, 4), rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   207
    __ movl(Address(rsi, 8), rcx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   208
    __ movl(Address(rsi,12), rdx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   209
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   210
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   211
    // return
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   212
    //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   213
    __ bind(done);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   214
    __ popf();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   215
    __ pop(rsi);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   216
    __ pop(rbx);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   217
    __ pop(rbp);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   218
    __ ret(0);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   219
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   220
#   undef __
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   221
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   222
    return start;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   223
  };
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   224
};
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   225
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   226
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   227
void VM_Version::get_processor_features() {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   228
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   229
  _cpu = 4; // 486 by default
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   230
  _model = 0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   231
  _stepping = 0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   232
  _cpuFeatures = 0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   233
  _logical_processors_per_package = 1;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   234
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   235
  if (!Use486InstrsOnly) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   236
    // Get raw processor info
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   237
    getPsrInfo_stub(&_cpuid_info);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   238
    assert_is_initialized();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   239
    _cpu = extended_cpu_family();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   240
    _model = extended_cpu_model();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   241
    _stepping = cpu_stepping();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   242
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   243
    if (cpu_family() > 4) { // it supports CPUID
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   244
      _cpuFeatures = feature_flags();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   245
      // Logical processors are only available on P4s and above,
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   246
      // and only if hyperthreading is available.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   247
      _logical_processors_per_package = logical_processor_count();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   248
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   249
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   250
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   251
  _supports_cx8 = supports_cmpxchg8();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   252
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   253
#ifdef _LP64
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   254
  // OS should support SSE for x64 and hardware should support at least SSE2.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   255
  if (!VM_Version::supports_sse2()) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   256
    vm_exit_during_initialization("Unknown x64 processor: SSE2 not supported");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   257
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   258
#endif
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   259
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   260
  // If the OS doesn't support SSE, we can't use this feature even if the HW does
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   261
  if (!os::supports_sse())
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   262
    _cpuFeatures &= ~(CPU_SSE|CPU_SSE2|CPU_SSE3|CPU_SSSE3|CPU_SSE4A|CPU_SSE4_1|CPU_SSE4_2);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   263
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   264
  if (UseSSE < 4) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   265
    _cpuFeatures &= ~CPU_SSE4_1;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   266
    _cpuFeatures &= ~CPU_SSE4_2;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   267
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   268
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   269
  if (UseSSE < 3) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   270
    _cpuFeatures &= ~CPU_SSE3;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   271
    _cpuFeatures &= ~CPU_SSSE3;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   272
    _cpuFeatures &= ~CPU_SSE4A;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   273
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   274
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   275
  if (UseSSE < 2)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   276
    _cpuFeatures &= ~CPU_SSE2;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   277
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   278
  if (UseSSE < 1)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   279
    _cpuFeatures &= ~CPU_SSE;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   280
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   281
  if (logical_processors_per_package() == 1) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   282
    // HT processor could be installed on a system which doesn't support HT.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   283
    _cpuFeatures &= ~CPU_HT;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   284
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   285
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   286
  char buf[256];
2255
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   287
  jio_snprintf(buf, sizeof(buf), "(%u cores per cpu, %u threads per core) family %d model %d stepping %d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
2111
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   288
               cores_per_cpu(), threads_per_core(),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   289
               cpu_family(), _model, _stepping,
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   290
               (supports_cmov() ? ", cmov" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   291
               (supports_cmpxchg8() ? ", cx8" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   292
               (supports_fxsr() ? ", fxsr" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   293
               (supports_mmx()  ? ", mmx"  : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   294
               (supports_sse()  ? ", sse"  : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   295
               (supports_sse2() ? ", sse2" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   296
               (supports_sse3() ? ", sse3" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   297
               (supports_ssse3()? ", ssse3": ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   298
               (supports_sse4_1() ? ", sse4.1" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   299
               (supports_sse4_2() ? ", sse4.2" : ""),
2255
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   300
               (supports_popcnt() ? ", popcnt" : ""),
2111
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   301
               (supports_mmx_ext() ? ", mmxext" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   302
               (supports_3dnow()   ? ", 3dnow"  : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   303
               (supports_3dnow2()  ? ", 3dnowext" : ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   304
               (supports_sse4a()   ? ", sse4a": ""),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   305
               (supports_ht() ? ", ht": ""));
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   306
  _features_str = strdup(buf);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   307
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   308
  // UseSSE is set to the smaller of what hardware supports and what
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   309
  // the command line requires.  I.e., you cannot set UseSSE to 2 on
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   310
  // older Pentiums which do not support it.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   311
  if( UseSSE > 4 ) UseSSE=4;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   312
  if( UseSSE < 0 ) UseSSE=0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   313
  if( !supports_sse4_1() ) // Drop to 3 if no SSE4 support
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   314
    UseSSE = MIN2((intx)3,UseSSE);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   315
  if( !supports_sse3() ) // Drop to 2 if no SSE3 support
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   316
    UseSSE = MIN2((intx)2,UseSSE);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   317
  if( !supports_sse2() ) // Drop to 1 if no SSE2 support
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   318
    UseSSE = MIN2((intx)1,UseSSE);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   319
  if( !supports_sse () ) // Drop to 0 if no SSE  support
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   320
    UseSSE = 0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   321
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   322
  // On new cpus instructions which update whole XMM register should be used
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   323
  // to prevent partial register stall due to dependencies on high half.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   324
  //
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   325
  // UseXmmLoadAndClearUpper == true  --> movsd(xmm, mem)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   326
  // UseXmmLoadAndClearUpper == false --> movlpd(xmm, mem)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   327
  // UseXmmRegToRegMoveAll == true  --> movaps(xmm, xmm), movapd(xmm, xmm).
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   328
  // UseXmmRegToRegMoveAll == false --> movss(xmm, xmm),  movsd(xmm, xmm).
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   329
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   330
  if( is_amd() ) { // AMD cpus specific settings
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   331
    if( supports_sse2() && FLAG_IS_DEFAULT(UseAddressNop) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   332
      // Use it on new AMD cpus starting from Opteron.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   333
      UseAddressNop = true;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   334
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   335
    if( supports_sse2() && FLAG_IS_DEFAULT(UseNewLongLShift) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   336
      // Use it on new AMD cpus starting from Opteron.
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   337
      UseNewLongLShift = true;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   338
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   339
    if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   340
      if( supports_sse4a() ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   341
        UseXmmLoadAndClearUpper = true; // use movsd only on '10h' Opteron
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   342
      } else {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   343
        UseXmmLoadAndClearUpper = false;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   344
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   345
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   346
    if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   347
      if( supports_sse4a() ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   348
        UseXmmRegToRegMoveAll = true; // use movaps, movapd only on '10h'
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   349
      } else {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   350
        UseXmmRegToRegMoveAll = false;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   351
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   352
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   353
    if( FLAG_IS_DEFAULT(UseXmmI2F) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   354
      if( supports_sse4a() ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   355
        UseXmmI2F = true;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   356
      } else {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   357
        UseXmmI2F = false;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   358
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   359
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   360
    if( FLAG_IS_DEFAULT(UseXmmI2D) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   361
      if( supports_sse4a() ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   362
        UseXmmI2D = true;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   363
      } else {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   364
        UseXmmI2D = false;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   365
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   366
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   367
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   368
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   369
  if( is_intel() ) { // Intel cpus specific settings
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   370
    if( FLAG_IS_DEFAULT(UseStoreImmI16) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   371
      UseStoreImmI16 = false; // don't use it on Intel cpus
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   372
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   373
    if( cpu_family() == 6 || cpu_family() == 15 ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   374
      if( FLAG_IS_DEFAULT(UseAddressNop) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   375
        // Use it on all Intel cpus starting from PentiumPro
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   376
        UseAddressNop = true;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   377
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   378
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   379
    if( FLAG_IS_DEFAULT(UseXmmLoadAndClearUpper) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   380
      UseXmmLoadAndClearUpper = true; // use movsd on all Intel cpus
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   381
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   382
    if( FLAG_IS_DEFAULT(UseXmmRegToRegMoveAll) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   383
      if( supports_sse3() ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   384
        UseXmmRegToRegMoveAll = true; // use movaps, movapd on new Intel cpus
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   385
      } else {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   386
        UseXmmRegToRegMoveAll = false;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   387
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   388
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   389
    if( cpu_family() == 6 && supports_sse3() ) { // New Intel cpus
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   390
#ifdef COMPILER2
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   391
      if( FLAG_IS_DEFAULT(MaxLoopPad) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   392
        // For new Intel cpus do the next optimization:
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   393
        // don't align the beginning of a loop if there are enough instructions
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   394
        // left (NumberOfLoopInstrToAlign defined in c2_globals.hpp)
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   395
        // in current fetch line (OptoLoopAlignment) or the padding
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   396
        // is big (> MaxLoopPad).
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   397
        // Set MaxLoopPad to 11 for new Intel cpus to reduce number of
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   398
        // generated NOP instructions. 11 is the largest size of one
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   399
        // address NOP instruction '0F 1F' (see Assembler::nop(i)).
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   400
        MaxLoopPad = 11;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   401
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   402
#endif // COMPILER2
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   403
      if( FLAG_IS_DEFAULT(UseXMMForArrayCopy) ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   404
        UseXMMForArrayCopy = true; // use SSE2 movq on new Intel cpus
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   405
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   406
      if( supports_sse4_2() && supports_ht() ) { // Newest Intel cpus
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   407
        if( FLAG_IS_DEFAULT(UseUnalignedLoadStores) && UseXMMForArrayCopy ) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   408
          UseUnalignedLoadStores = true; // use movdqu on newest Intel cpus
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   409
        }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   410
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   411
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   412
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   413
2255
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   414
  // Use population count instruction if available.
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   415
  if (supports_popcnt()) {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   416
    if (FLAG_IS_DEFAULT(UsePopCountInstruction)) {
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   417
      UsePopCountInstruction = true;
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   418
    }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   419
  }
54abdf3e1055 6378821: bitCount() should use POPC on SPARC processors and AMD+10h
twisti
parents: 2111
diff changeset
   420
2111
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   421
  assert(0 <= ReadPrefetchInstr && ReadPrefetchInstr <= 3, "invalid value");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   422
  assert(0 <= AllocatePrefetchInstr && AllocatePrefetchInstr <= 3, "invalid value");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   423
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   424
  // set valid Prefetch instruction
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   425
  if( ReadPrefetchInstr < 0 ) ReadPrefetchInstr = 0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   426
  if( ReadPrefetchInstr > 3 ) ReadPrefetchInstr = 3;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   427
  if( ReadPrefetchInstr == 3 && !supports_3dnow() ) ReadPrefetchInstr = 0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   428
  if( !supports_sse() && supports_3dnow() ) ReadPrefetchInstr = 3;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   429
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   430
  if( AllocatePrefetchInstr < 0 ) AllocatePrefetchInstr = 0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   431
  if( AllocatePrefetchInstr > 3 ) AllocatePrefetchInstr = 3;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   432
  if( AllocatePrefetchInstr == 3 && !supports_3dnow() ) AllocatePrefetchInstr=0;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   433
  if( !supports_sse() && supports_3dnow() ) AllocatePrefetchInstr = 3;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   434
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   435
  // Allocation prefetch settings
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   436
  intx cache_line_size = L1_data_cache_line_size();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   437
  if( cache_line_size > AllocatePrefetchStepSize )
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   438
    AllocatePrefetchStepSize = cache_line_size;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   439
  if( FLAG_IS_DEFAULT(AllocatePrefetchLines) )
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   440
    AllocatePrefetchLines = 3; // Optimistic value
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   441
  assert(AllocatePrefetchLines > 0, "invalid value");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   442
  if( AllocatePrefetchLines < 1 ) // set valid value in product VM
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   443
    AllocatePrefetchLines = 1; // Conservative value
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   444
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   445
  AllocatePrefetchDistance = allocate_prefetch_distance();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   446
  AllocatePrefetchStyle    = allocate_prefetch_style();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   447
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   448
  if( AllocatePrefetchStyle == 2 && is_intel() &&
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   449
      cpu_family() == 6 && supports_sse3() ) { // watermark prefetching on Core
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   450
#ifdef _LP64
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   451
    AllocatePrefetchDistance = 384;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   452
#else
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   453
    AllocatePrefetchDistance = 320;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   454
#endif
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   455
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   456
  assert(AllocatePrefetchDistance % AllocatePrefetchStepSize == 0, "invalid value");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   457
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   458
#ifdef _LP64
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   459
  // Prefetch settings
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   460
  PrefetchCopyIntervalInBytes = prefetch_copy_interval_in_bytes();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   461
  PrefetchScanIntervalInBytes = prefetch_scan_interval_in_bytes();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   462
  PrefetchFieldsAhead         = prefetch_fields_ahead();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   463
#endif
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   464
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   465
#ifndef PRODUCT
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   466
  if (PrintMiscellaneous && Verbose) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   467
    tty->print_cr("Logical CPUs per core: %u",
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   468
                  logical_processors_per_package());
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   469
    tty->print_cr("UseSSE=%d",UseSSE);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   470
    tty->print("Allocation: ");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   471
    if (AllocatePrefetchStyle <= 0 || UseSSE == 0 && !supports_3dnow()) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   472
      tty->print_cr("no prefetching");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   473
    } else {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   474
      if (UseSSE == 0 && supports_3dnow()) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   475
        tty->print("PREFETCHW");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   476
      } else if (UseSSE >= 1) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   477
        if (AllocatePrefetchInstr == 0) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   478
          tty->print("PREFETCHNTA");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   479
        } else if (AllocatePrefetchInstr == 1) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   480
          tty->print("PREFETCHT0");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   481
        } else if (AllocatePrefetchInstr == 2) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   482
          tty->print("PREFETCHT2");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   483
        } else if (AllocatePrefetchInstr == 3) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   484
          tty->print("PREFETCHW");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   485
        }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   486
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   487
      if (AllocatePrefetchLines > 1) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   488
        tty->print_cr(" %d, %d lines with step %d bytes", AllocatePrefetchDistance, AllocatePrefetchLines, AllocatePrefetchStepSize);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   489
      } else {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   490
        tty->print_cr(" %d, one line", AllocatePrefetchDistance);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   491
      }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   492
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   493
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   494
    if (PrefetchCopyIntervalInBytes > 0) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   495
      tty->print_cr("PrefetchCopyIntervalInBytes %d", PrefetchCopyIntervalInBytes);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   496
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   497
    if (PrefetchScanIntervalInBytes > 0) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   498
      tty->print_cr("PrefetchScanIntervalInBytes %d", PrefetchScanIntervalInBytes);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   499
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   500
    if (PrefetchFieldsAhead > 0) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   501
      tty->print_cr("PrefetchFieldsAhead %d", PrefetchFieldsAhead);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   502
    }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   503
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   504
#endif // !PRODUCT
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   505
}
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   506
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   507
void VM_Version::initialize() {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   508
  ResourceMark rm;
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   509
  // Making this stub must be FIRST use of assembler
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   510
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   511
  stub_blob = BufferBlob::create("getPsrInfo_stub", stub_size);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   512
  if (stub_blob == NULL) {
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   513
    vm_exit_during_initialization("Unable to allocate getPsrInfo_stub");
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   514
  }
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   515
  CodeBuffer c(stub_blob->instructions_begin(),
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   516
               stub_blob->instructions_size());
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   517
  VM_Version_StubGenerator g(&c);
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   518
  getPsrInfo_stub = CAST_TO_FN_PTR(getPsrInfo_stub_t,
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   519
                                   g.generate_getPsrInfo());
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   520
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   521
  get_processor_features();
dab8a43dd738 6808589: Merge vm_version_x86_{32,64}.{cpp,hpp}
twisti
parents:
diff changeset
   522
}