src/cpu/x86/vm/vm_version_x86.hpp

Tue, 20 Dec 2011 00:55:02 -0800

author
kvn
date
Tue, 20 Dec 2011 00:55:02 -0800
changeset 3390
65149e74c706
parent 3388
127b3692c168
child 3400
22cee0ee8927
permissions
-rw-r--r--

7121648: Use 3-operands SIMD instructions on x86 with AVX
Summary: Use 3-operands SIMD instructions in C2 generated code for machines with AVX.
Reviewed-by: never

twisti@1020 1 /*
katleman@3058 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
twisti@1020 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
twisti@1020 4 *
twisti@1020 5 * This code is free software; you can redistribute it and/or modify it
twisti@1020 6 * under the terms of the GNU General Public License version 2 only, as
twisti@1020 7 * published by the Free Software Foundation.
twisti@1020 8 *
twisti@1020 9 * This code is distributed in the hope that it will be useful, but WITHOUT
twisti@1020 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
twisti@1020 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
twisti@1020 12 * version 2 for more details (a copy is included in the LICENSE file that
twisti@1020 13 * accompanied this code).
twisti@1020 14 *
twisti@1020 15 * You should have received a copy of the GNU General Public License version
twisti@1020 16 * 2 along with this work; if not, write to the Free Software Foundation,
twisti@1020 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
twisti@1020 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
twisti@1020 22 *
twisti@1020 23 */
twisti@1020 24
stefank@2314 25 #ifndef CPU_X86_VM_VM_VERSION_X86_HPP
stefank@2314 26 #define CPU_X86_VM_VM_VERSION_X86_HPP
stefank@2314 27
stefank@2314 28 #include "runtime/globals_extension.hpp"
stefank@2314 29 #include "runtime/vm_version.hpp"
stefank@2314 30
twisti@1020 31 class VM_Version : public Abstract_VM_Version {
twisti@1020 32 public:
twisti@1020 33 // cpuid result register layouts. These are all unions of a uint32_t
twisti@1020 34 // (in case anyone wants access to the register as a whole) and a bitfield.
twisti@1020 35
twisti@1020 36 union StdCpuid1Eax {
twisti@1020 37 uint32_t value;
twisti@1020 38 struct {
twisti@1020 39 uint32_t stepping : 4,
twisti@1020 40 model : 4,
twisti@1020 41 family : 4,
twisti@1020 42 proc_type : 2,
twisti@1020 43 : 2,
twisti@1020 44 ext_model : 4,
twisti@1020 45 ext_family : 8,
twisti@1020 46 : 4;
twisti@1020 47 } bits;
twisti@1020 48 };
twisti@1020 49
twisti@1020 50 union StdCpuid1Ebx { // example, unused
twisti@1020 51 uint32_t value;
twisti@1020 52 struct {
twisti@1020 53 uint32_t brand_id : 8,
twisti@1020 54 clflush_size : 8,
twisti@1020 55 threads_per_cpu : 8,
twisti@1020 56 apic_id : 8;
twisti@1020 57 } bits;
twisti@1020 58 };
twisti@1020 59
twisti@1020 60 union StdCpuid1Ecx {
twisti@1020 61 uint32_t value;
twisti@1020 62 struct {
twisti@1020 63 uint32_t sse3 : 1,
twisti@1020 64 : 2,
twisti@1020 65 monitor : 1,
twisti@1020 66 : 1,
twisti@1020 67 vmx : 1,
twisti@1020 68 : 1,
twisti@1020 69 est : 1,
twisti@1020 70 : 1,
twisti@1020 71 ssse3 : 1,
twisti@1020 72 cid : 1,
twisti@1020 73 : 2,
twisti@1020 74 cmpxchg16: 1,
twisti@1020 75 : 4,
twisti@1020 76 dca : 1,
twisti@1020 77 sse4_1 : 1,
twisti@1020 78 sse4_2 : 1,
twisti@1078 79 : 2,
twisti@1078 80 popcnt : 1,
kvn@3388 81 : 3,
kvn@3388 82 osxsave : 1,
kvn@3388 83 avx : 1,
kvn@3388 84 : 3;
twisti@1020 85 } bits;
twisti@1020 86 };
twisti@1020 87
twisti@1020 88 union StdCpuid1Edx {
twisti@1020 89 uint32_t value;
twisti@1020 90 struct {
twisti@1020 91 uint32_t : 4,
twisti@1020 92 tsc : 1,
twisti@1020 93 : 3,
twisti@1020 94 cmpxchg8 : 1,
twisti@1020 95 : 6,
twisti@1020 96 cmov : 1,
kvn@2984 97 : 3,
kvn@2984 98 clflush : 1,
kvn@2984 99 : 3,
twisti@1020 100 mmx : 1,
twisti@1020 101 fxsr : 1,
twisti@1020 102 sse : 1,
twisti@1020 103 sse2 : 1,
twisti@1020 104 : 1,
twisti@1020 105 ht : 1,
twisti@1020 106 : 3;
twisti@1020 107 } bits;
twisti@1020 108 };
twisti@1020 109
twisti@1020 110 union DcpCpuid4Eax {
twisti@1020 111 uint32_t value;
twisti@1020 112 struct {
twisti@1020 113 uint32_t cache_type : 5,
twisti@1020 114 : 21,
twisti@1020 115 cores_per_cpu : 6;
twisti@1020 116 } bits;
twisti@1020 117 };
twisti@1020 118
twisti@1020 119 union DcpCpuid4Ebx {
twisti@1020 120 uint32_t value;
twisti@1020 121 struct {
twisti@1020 122 uint32_t L1_line_size : 12,
twisti@1020 123 partitions : 10,
twisti@1020 124 associativity : 10;
twisti@1020 125 } bits;
twisti@1020 126 };
twisti@1020 127
kvn@1977 128 union TplCpuidBEbx {
kvn@1977 129 uint32_t value;
kvn@1977 130 struct {
kvn@1977 131 uint32_t logical_cpus : 16,
kvn@1977 132 : 16;
kvn@1977 133 } bits;
kvn@1977 134 };
kvn@1977 135
twisti@1020 136 union ExtCpuid1Ecx {
twisti@1020 137 uint32_t value;
twisti@1020 138 struct {
twisti@1020 139 uint32_t LahfSahf : 1,
twisti@1020 140 CmpLegacy : 1,
twisti@1020 141 : 4,
twisti@1210 142 lzcnt : 1,
twisti@1020 143 sse4a : 1,
twisti@1020 144 misalignsse : 1,
twisti@1020 145 prefetchw : 1,
twisti@1020 146 : 22;
twisti@1020 147 } bits;
twisti@1020 148 };
twisti@1020 149
twisti@1020 150 union ExtCpuid1Edx {
twisti@1020 151 uint32_t value;
twisti@1020 152 struct {
twisti@1020 153 uint32_t : 22,
twisti@1020 154 mmx_amd : 1,
twisti@1020 155 mmx : 1,
twisti@1020 156 fxsr : 1,
twisti@1020 157 : 4,
twisti@1020 158 long_mode : 1,
twisti@1020 159 tdnow2 : 1,
twisti@1020 160 tdnow : 1;
twisti@1020 161 } bits;
twisti@1020 162 };
twisti@1020 163
twisti@1020 164 union ExtCpuid5Ex {
twisti@1020 165 uint32_t value;
twisti@1020 166 struct {
twisti@1020 167 uint32_t L1_line_size : 8,
twisti@1020 168 L1_tag_lines : 8,
twisti@1020 169 L1_assoc : 8,
twisti@1020 170 L1_size : 8;
twisti@1020 171 } bits;
twisti@1020 172 };
twisti@1020 173
twisti@1020 174 union ExtCpuid8Ecx {
twisti@1020 175 uint32_t value;
twisti@1020 176 struct {
twisti@1020 177 uint32_t cores_per_cpu : 8,
twisti@1020 178 : 24;
twisti@1020 179 } bits;
twisti@1020 180 };
twisti@1020 181
kvn@3388 182 union SefCpuid7Eax {
kvn@3388 183 uint32_t value;
kvn@3388 184 };
kvn@3388 185
kvn@3388 186 union SefCpuid7Ebx {
kvn@3388 187 uint32_t value;
kvn@3388 188 struct {
kvn@3388 189 uint32_t fsgsbase : 1,
kvn@3388 190 : 2,
kvn@3388 191 bmi1 : 1,
kvn@3388 192 : 1,
kvn@3388 193 avx2 : 1,
kvn@3388 194 : 2,
kvn@3388 195 bmi2 : 1,
kvn@3388 196 : 23;
kvn@3388 197 } bits;
kvn@3388 198 };
kvn@3388 199
kvn@3388 200 union XemXcr0Eax {
kvn@3388 201 uint32_t value;
kvn@3388 202 struct {
kvn@3388 203 uint32_t x87 : 1,
kvn@3388 204 sse : 1,
kvn@3388 205 ymm : 1,
kvn@3388 206 : 29;
kvn@3388 207 } bits;
kvn@3388 208 };
kvn@3388 209
twisti@1020 210 protected:
twisti@1020 211 static int _cpu;
twisti@1020 212 static int _model;
twisti@1020 213 static int _stepping;
twisti@1020 214 static int _cpuFeatures; // features returned by the "cpuid" instruction
twisti@1020 215 // 0 if this instruction is not available
twisti@1020 216 static const char* _features_str;
twisti@1020 217
twisti@1020 218 enum {
twisti@1020 219 CPU_CX8 = (1 << 0), // next bits are from cpuid 1 (EDX)
twisti@1020 220 CPU_CMOV = (1 << 1),
twisti@1020 221 CPU_FXSR = (1 << 2),
twisti@1020 222 CPU_HT = (1 << 3),
twisti@1020 223 CPU_MMX = (1 << 4),
kvn@2761 224 CPU_3DNOW_PREFETCH = (1 << 5), // Processor supports 3dnow prefetch and prefetchw instructions
kvn@2761 225 // may not necessarily support other 3dnow instructions
twisti@1020 226 CPU_SSE = (1 << 6),
twisti@1020 227 CPU_SSE2 = (1 << 7),
twisti@1020 228 CPU_SSE3 = (1 << 8), // SSE3 comes from cpuid 1 (ECX)
twisti@1020 229 CPU_SSSE3 = (1 << 9),
twisti@1020 230 CPU_SSE4A = (1 << 10),
twisti@1020 231 CPU_SSE4_1 = (1 << 11),
twisti@1078 232 CPU_SSE4_2 = (1 << 12),
twisti@1210 233 CPU_POPCNT = (1 << 13),
kvn@3388 234 CPU_LZCNT = (1 << 14),
kvn@3388 235 CPU_AVX = (1 << 15),
kvn@3388 236 CPU_AVX2 = (1 << 16)
twisti@1020 237 } cpuFeatureFlags;
twisti@1020 238
twisti@1020 239 // cpuid information block. All info derived from executing cpuid with
twisti@1020 240 // various function numbers is stored here. Intel and AMD info is
twisti@1020 241 // merged in this block: accessor methods disentangle it.
twisti@1020 242 //
twisti@1020 243 // The info block is laid out in subblocks of 4 dwords corresponding to
twisti@1020 244 // eax, ebx, ecx and edx, whether or not they contain anything useful.
twisti@1020 245 struct CpuidInfo {
twisti@1020 246 // cpuid function 0
twisti@1020 247 uint32_t std_max_function;
twisti@1020 248 uint32_t std_vendor_name_0;
twisti@1020 249 uint32_t std_vendor_name_1;
twisti@1020 250 uint32_t std_vendor_name_2;
twisti@1020 251
twisti@1020 252 // cpuid function 1
twisti@1020 253 StdCpuid1Eax std_cpuid1_eax;
twisti@1020 254 StdCpuid1Ebx std_cpuid1_ebx;
twisti@1020 255 StdCpuid1Ecx std_cpuid1_ecx;
twisti@1020 256 StdCpuid1Edx std_cpuid1_edx;
twisti@1020 257
twisti@1020 258 // cpuid function 4 (deterministic cache parameters)
twisti@1020 259 DcpCpuid4Eax dcp_cpuid4_eax;
twisti@1020 260 DcpCpuid4Ebx dcp_cpuid4_ebx;
twisti@1020 261 uint32_t dcp_cpuid4_ecx; // unused currently
twisti@1020 262 uint32_t dcp_cpuid4_edx; // unused currently
twisti@1020 263
kvn@3388 264 // cpuid function 7 (structured extended features)
kvn@3388 265 SefCpuid7Eax sef_cpuid7_eax;
kvn@3388 266 SefCpuid7Ebx sef_cpuid7_ebx;
kvn@3388 267 uint32_t sef_cpuid7_ecx; // unused currently
kvn@3388 268 uint32_t sef_cpuid7_edx; // unused currently
kvn@3388 269
kvn@1977 270 // cpuid function 0xB (processor topology)
kvn@1977 271 // ecx = 0
kvn@1977 272 uint32_t tpl_cpuidB0_eax;
kvn@1977 273 TplCpuidBEbx tpl_cpuidB0_ebx;
kvn@1977 274 uint32_t tpl_cpuidB0_ecx; // unused currently
kvn@1977 275 uint32_t tpl_cpuidB0_edx; // unused currently
kvn@1977 276
kvn@1977 277 // ecx = 1
kvn@1977 278 uint32_t tpl_cpuidB1_eax;
kvn@1977 279 TplCpuidBEbx tpl_cpuidB1_ebx;
kvn@1977 280 uint32_t tpl_cpuidB1_ecx; // unused currently
kvn@1977 281 uint32_t tpl_cpuidB1_edx; // unused currently
kvn@1977 282
kvn@1977 283 // ecx = 2
kvn@1977 284 uint32_t tpl_cpuidB2_eax;
kvn@1977 285 TplCpuidBEbx tpl_cpuidB2_ebx;
kvn@1977 286 uint32_t tpl_cpuidB2_ecx; // unused currently
kvn@1977 287 uint32_t tpl_cpuidB2_edx; // unused currently
kvn@1977 288
twisti@1020 289 // cpuid function 0x80000000 // example, unused
twisti@1020 290 uint32_t ext_max_function;
twisti@1020 291 uint32_t ext_vendor_name_0;
twisti@1020 292 uint32_t ext_vendor_name_1;
twisti@1020 293 uint32_t ext_vendor_name_2;
twisti@1020 294
twisti@1020 295 // cpuid function 0x80000001
twisti@1020 296 uint32_t ext_cpuid1_eax; // reserved
twisti@1020 297 uint32_t ext_cpuid1_ebx; // reserved
twisti@1020 298 ExtCpuid1Ecx ext_cpuid1_ecx;
twisti@1020 299 ExtCpuid1Edx ext_cpuid1_edx;
twisti@1020 300
twisti@1020 301 // cpuid functions 0x80000002 thru 0x80000004: example, unused
twisti@1020 302 uint32_t proc_name_0, proc_name_1, proc_name_2, proc_name_3;
twisti@1020 303 uint32_t proc_name_4, proc_name_5, proc_name_6, proc_name_7;
twisti@1020 304 uint32_t proc_name_8, proc_name_9, proc_name_10,proc_name_11;
twisti@1020 305
twisti@1020 306 // cpuid function 0x80000005 //AMD L1, Intel reserved
twisti@1020 307 uint32_t ext_cpuid5_eax; // unused currently
twisti@1020 308 uint32_t ext_cpuid5_ebx; // reserved
twisti@1020 309 ExtCpuid5Ex ext_cpuid5_ecx; // L1 data cache info (AMD)
twisti@1020 310 ExtCpuid5Ex ext_cpuid5_edx; // L1 instruction cache info (AMD)
twisti@1020 311
twisti@1020 312 // cpuid function 0x80000008
twisti@1020 313 uint32_t ext_cpuid8_eax; // unused currently
twisti@1020 314 uint32_t ext_cpuid8_ebx; // reserved
twisti@1020 315 ExtCpuid8Ecx ext_cpuid8_ecx;
twisti@1020 316 uint32_t ext_cpuid8_edx; // reserved
kvn@3388 317
kvn@3388 318 // extended control register XCR0 (the XFEATURE_ENABLED_MASK register)
kvn@3388 319 XemXcr0Eax xem_xcr0_eax;
kvn@3388 320 uint32_t xem_xcr0_edx; // reserved
twisti@1020 321 };
twisti@1020 322
twisti@1020 323 // The actual cpuid info block
twisti@1020 324 static CpuidInfo _cpuid_info;
twisti@1020 325
twisti@1020 326 // Extractors and predicates
twisti@1020 327 static uint32_t extended_cpu_family() {
twisti@1020 328 uint32_t result = _cpuid_info.std_cpuid1_eax.bits.family;
twisti@1020 329 result += _cpuid_info.std_cpuid1_eax.bits.ext_family;
twisti@1020 330 return result;
twisti@1020 331 }
twisti@1020 332 static uint32_t extended_cpu_model() {
twisti@1020 333 uint32_t result = _cpuid_info.std_cpuid1_eax.bits.model;
twisti@1020 334 result |= _cpuid_info.std_cpuid1_eax.bits.ext_model << 4;
twisti@1020 335 return result;
twisti@1020 336 }
twisti@1020 337 static uint32_t cpu_stepping() {
twisti@1020 338 uint32_t result = _cpuid_info.std_cpuid1_eax.bits.stepping;
twisti@1020 339 return result;
twisti@1020 340 }
twisti@1020 341 static uint logical_processor_count() {
twisti@1020 342 uint result = threads_per_core();
twisti@1020 343 return result;
twisti@1020 344 }
twisti@1020 345 static uint32_t feature_flags() {
twisti@1020 346 uint32_t result = 0;
twisti@1020 347 if (_cpuid_info.std_cpuid1_edx.bits.cmpxchg8 != 0)
twisti@1020 348 result |= CPU_CX8;
twisti@1020 349 if (_cpuid_info.std_cpuid1_edx.bits.cmov != 0)
twisti@1020 350 result |= CPU_CMOV;
twisti@2144 351 if (_cpuid_info.std_cpuid1_edx.bits.fxsr != 0 || (is_amd() &&
twisti@2144 352 _cpuid_info.ext_cpuid1_edx.bits.fxsr != 0))
twisti@1020 353 result |= CPU_FXSR;
twisti@1020 354 // HT flag is set for multi-core processors also.
twisti@1020 355 if (threads_per_core() > 1)
twisti@1020 356 result |= CPU_HT;
twisti@2144 357 if (_cpuid_info.std_cpuid1_edx.bits.mmx != 0 || (is_amd() &&
twisti@2144 358 _cpuid_info.ext_cpuid1_edx.bits.mmx != 0))
twisti@1020 359 result |= CPU_MMX;
twisti@1020 360 if (_cpuid_info.std_cpuid1_edx.bits.sse != 0)
twisti@1020 361 result |= CPU_SSE;
twisti@1020 362 if (_cpuid_info.std_cpuid1_edx.bits.sse2 != 0)
twisti@1020 363 result |= CPU_SSE2;
twisti@1020 364 if (_cpuid_info.std_cpuid1_ecx.bits.sse3 != 0)
twisti@1020 365 result |= CPU_SSE3;
twisti@1020 366 if (_cpuid_info.std_cpuid1_ecx.bits.ssse3 != 0)
twisti@1020 367 result |= CPU_SSSE3;
twisti@1020 368 if (_cpuid_info.std_cpuid1_ecx.bits.sse4_1 != 0)
twisti@1020 369 result |= CPU_SSE4_1;
twisti@1020 370 if (_cpuid_info.std_cpuid1_ecx.bits.sse4_2 != 0)
twisti@1020 371 result |= CPU_SSE4_2;
twisti@1078 372 if (_cpuid_info.std_cpuid1_ecx.bits.popcnt != 0)
twisti@1078 373 result |= CPU_POPCNT;
kvn@3388 374 if (_cpuid_info.std_cpuid1_ecx.bits.avx != 0 &&
kvn@3388 375 _cpuid_info.std_cpuid1_ecx.bits.osxsave != 0 &&
kvn@3388 376 _cpuid_info.xem_xcr0_eax.bits.sse != 0 &&
kvn@3388 377 _cpuid_info.xem_xcr0_eax.bits.ymm != 0) {
kvn@3388 378 result |= CPU_AVX;
kvn@3388 379 if (_cpuid_info.sef_cpuid7_ebx.bits.avx2 != 0)
kvn@3388 380 result |= CPU_AVX2;
kvn@3388 381 }
twisti@1210 382
twisti@1210 383 // AMD features.
twisti@1210 384 if (is_amd()) {
kvn@2761 385 if ((_cpuid_info.ext_cpuid1_edx.bits.tdnow != 0) ||
kvn@2761 386 (_cpuid_info.ext_cpuid1_ecx.bits.prefetchw != 0))
kvn@2761 387 result |= CPU_3DNOW_PREFETCH;
twisti@1210 388 if (_cpuid_info.ext_cpuid1_ecx.bits.lzcnt != 0)
twisti@1210 389 result |= CPU_LZCNT;
twisti@1210 390 if (_cpuid_info.ext_cpuid1_ecx.bits.sse4a != 0)
twisti@1210 391 result |= CPU_SSE4A;
twisti@1210 392 }
twisti@1210 393
twisti@1020 394 return result;
twisti@1020 395 }
twisti@1020 396
twisti@1020 397 static void get_processor_features();
twisti@1020 398
twisti@1020 399 public:
twisti@1020 400 // Offsets for cpuid asm stub
twisti@1020 401 static ByteSize std_cpuid0_offset() { return byte_offset_of(CpuidInfo, std_max_function); }
twisti@1020 402 static ByteSize std_cpuid1_offset() { return byte_offset_of(CpuidInfo, std_cpuid1_eax); }
twisti@1020 403 static ByteSize dcp_cpuid4_offset() { return byte_offset_of(CpuidInfo, dcp_cpuid4_eax); }
kvn@3388 404 static ByteSize sef_cpuid7_offset() { return byte_offset_of(CpuidInfo, sef_cpuid7_eax); }
twisti@1020 405 static ByteSize ext_cpuid1_offset() { return byte_offset_of(CpuidInfo, ext_cpuid1_eax); }
twisti@1020 406 static ByteSize ext_cpuid5_offset() { return byte_offset_of(CpuidInfo, ext_cpuid5_eax); }
twisti@1020 407 static ByteSize ext_cpuid8_offset() { return byte_offset_of(CpuidInfo, ext_cpuid8_eax); }
kvn@1977 408 static ByteSize tpl_cpuidB0_offset() { return byte_offset_of(CpuidInfo, tpl_cpuidB0_eax); }
kvn@1977 409 static ByteSize tpl_cpuidB1_offset() { return byte_offset_of(CpuidInfo, tpl_cpuidB1_eax); }
kvn@1977 410 static ByteSize tpl_cpuidB2_offset() { return byte_offset_of(CpuidInfo, tpl_cpuidB2_eax); }
kvn@3388 411 static ByteSize xem_xcr0_offset() { return byte_offset_of(CpuidInfo, xem_xcr0_eax); }
twisti@1020 412
twisti@1020 413 // Initialization
twisti@1020 414 static void initialize();
twisti@1020 415
twisti@1020 416 // Asserts
twisti@1020 417 static void assert_is_initialized() {
twisti@1020 418 assert(_cpuid_info.std_cpuid1_eax.bits.family != 0, "VM_Version not initialized");
twisti@1020 419 }
twisti@1020 420
twisti@1020 421 //
twisti@1020 422 // Processor family:
twisti@1020 423 // 3 - 386
twisti@1020 424 // 4 - 486
twisti@1020 425 // 5 - Pentium
twisti@1020 426 // 6 - PentiumPro, Pentium II, Celeron, Xeon, Pentium III, Athlon,
twisti@1020 427 // Pentium M, Core Solo, Core Duo, Core2 Duo
twisti@1020 428 // family 6 model: 9, 13, 14, 15
twisti@1020 429 // 0x0f - Pentium 4, Opteron
twisti@1020 430 //
twisti@1020 431 // Note: The cpu family should be used to select between
twisti@1020 432 // instruction sequences which are valid on all Intel
twisti@1020 433 // processors. Use the feature test functions below to
twisti@1020 434 // determine whether a particular instruction is supported.
twisti@1020 435 //
twisti@1020 436 static int cpu_family() { return _cpu;}
twisti@1020 437 static bool is_P6() { return cpu_family() >= 6; }
twisti@1020 438
twisti@1020 439 static bool is_amd() { assert_is_initialized(); return _cpuid_info.std_vendor_name_0 == 0x68747541; } // 'htuA'
twisti@1020 440 static bool is_intel() { assert_is_initialized(); return _cpuid_info.std_vendor_name_0 == 0x756e6547; } // 'uneG'
twisti@1020 441
kvn@2002 442 static bool supports_processor_topology() {
kvn@2002 443 return (_cpuid_info.std_max_function >= 0xB) &&
kvn@2002 444 // eax[4:0] | ebx[0:15] == 0 indicates invalid topology level.
kvn@2002 445 // Some cpus have max cpuid >= 0xB but do not support processor topology.
kvn@2002 446 ((_cpuid_info.tpl_cpuidB0_eax & 0x1f | _cpuid_info.tpl_cpuidB0_ebx.bits.logical_cpus) != 0);
kvn@2002 447 }
kvn@2002 448
twisti@1020 449 static uint cores_per_cpu() {
twisti@1020 450 uint result = 1;
twisti@1020 451 if (is_intel()) {
kvn@2002 452 if (supports_processor_topology()) {
kvn@1977 453 result = _cpuid_info.tpl_cpuidB1_ebx.bits.logical_cpus /
kvn@1977 454 _cpuid_info.tpl_cpuidB0_ebx.bits.logical_cpus;
kvn@1977 455 } else {
kvn@1977 456 result = (_cpuid_info.dcp_cpuid4_eax.bits.cores_per_cpu + 1);
kvn@1977 457 }
twisti@1020 458 } else if (is_amd()) {
twisti@1020 459 result = (_cpuid_info.ext_cpuid8_ecx.bits.cores_per_cpu + 1);
twisti@1020 460 }
twisti@1020 461 return result;
twisti@1020 462 }
twisti@1020 463
twisti@1020 464 static uint threads_per_core() {
twisti@1020 465 uint result = 1;
kvn@2002 466 if (is_intel() && supports_processor_topology()) {
kvn@1977 467 result = _cpuid_info.tpl_cpuidB0_ebx.bits.logical_cpus;
kvn@1977 468 } else if (_cpuid_info.std_cpuid1_edx.bits.ht != 0) {
twisti@1020 469 result = _cpuid_info.std_cpuid1_ebx.bits.threads_per_cpu /
twisti@1020 470 cores_per_cpu();
twisti@1020 471 }
twisti@1020 472 return result;
twisti@1020 473 }
twisti@1020 474
kvn@3052 475 static intx prefetch_data_size() {
twisti@1020 476 intx result = 0;
twisti@1020 477 if (is_intel()) {
twisti@1020 478 result = (_cpuid_info.dcp_cpuid4_ebx.bits.L1_line_size + 1);
twisti@1020 479 } else if (is_amd()) {
twisti@1020 480 result = _cpuid_info.ext_cpuid5_ecx.bits.L1_line_size;
twisti@1020 481 }
twisti@1020 482 if (result < 32) // not defined ?
twisti@1020 483 result = 32; // 32 bytes by default on x86 and other x64
twisti@1020 484 return result;
twisti@1020 485 }
twisti@1020 486
twisti@1020 487 //
twisti@1020 488 // Feature identification
twisti@1020 489 //
twisti@1020 490 static bool supports_cpuid() { return _cpuFeatures != 0; }
twisti@1020 491 static bool supports_cmpxchg8() { return (_cpuFeatures & CPU_CX8) != 0; }
twisti@1020 492 static bool supports_cmov() { return (_cpuFeatures & CPU_CMOV) != 0; }
twisti@1020 493 static bool supports_fxsr() { return (_cpuFeatures & CPU_FXSR) != 0; }
twisti@1020 494 static bool supports_ht() { return (_cpuFeatures & CPU_HT) != 0; }
twisti@1020 495 static bool supports_mmx() { return (_cpuFeatures & CPU_MMX) != 0; }
twisti@1020 496 static bool supports_sse() { return (_cpuFeatures & CPU_SSE) != 0; }
twisti@1020 497 static bool supports_sse2() { return (_cpuFeatures & CPU_SSE2) != 0; }
twisti@1020 498 static bool supports_sse3() { return (_cpuFeatures & CPU_SSE3) != 0; }
twisti@1020 499 static bool supports_ssse3() { return (_cpuFeatures & CPU_SSSE3)!= 0; }
twisti@1020 500 static bool supports_sse4_1() { return (_cpuFeatures & CPU_SSE4_1) != 0; }
twisti@1020 501 static bool supports_sse4_2() { return (_cpuFeatures & CPU_SSE4_2) != 0; }
twisti@1078 502 static bool supports_popcnt() { return (_cpuFeatures & CPU_POPCNT) != 0; }
kvn@3388 503 static bool supports_avx() { return (_cpuFeatures & CPU_AVX) != 0; }
kvn@3388 504 static bool supports_avx2() { return (_cpuFeatures & CPU_AVX2) != 0; }
twisti@1020 505 //
twisti@1020 506 // AMD features
twisti@1020 507 //
kvn@2761 508 static bool supports_3dnow_prefetch() { return (_cpuFeatures & CPU_3DNOW_PREFETCH) != 0; }
twisti@1020 509 static bool supports_mmx_ext() { return is_amd() && _cpuid_info.ext_cpuid1_edx.bits.mmx_amd != 0; }
twisti@1210 510 static bool supports_lzcnt() { return (_cpuFeatures & CPU_LZCNT) != 0; }
twisti@1020 511 static bool supports_sse4a() { return (_cpuFeatures & CPU_SSE4A) != 0; }
twisti@1020 512
kvn@2269 513 // Intel Core and newer cpus have fast IDIV instruction (excluding Atom).
kvn@2269 514 static bool has_fast_idiv() { return is_intel() && cpu_family() == 6 &&
kvn@2269 515 supports_sse3() && _model != 0x1C; }
kvn@2269 516
twisti@1020 517 static bool supports_compare_and_exchange() { return true; }
twisti@1020 518
twisti@1020 519 static const char* cpu_features() { return _features_str; }
twisti@1020 520
twisti@1020 521 static intx allocate_prefetch_distance() {
twisti@1020 522 // This method should be called before allocate_prefetch_style().
twisti@1020 523 //
twisti@1020 524 // Hardware prefetching (distance/size in bytes):
twisti@1020 525 // Pentium 3 - 64 / 32
twisti@1020 526 // Pentium 4 - 256 / 128
twisti@1020 527 // Athlon - 64 / 32 ????
twisti@1020 528 // Opteron - 128 / 64 only when 2 sequential cache lines accessed
twisti@1020 529 // Core - 128 / 64
twisti@1020 530 //
twisti@1020 531 // Software prefetching (distance in bytes / instruction with best score):
twisti@1020 532 // Pentium 3 - 128 / prefetchnta
twisti@1020 533 // Pentium 4 - 512 / prefetchnta
twisti@1020 534 // Athlon - 128 / prefetchnta
twisti@1020 535 // Opteron - 256 / prefetchnta
twisti@1020 536 // Core - 256 / prefetchnta
twisti@1020 537 // It will be used only when AllocatePrefetchStyle > 0
twisti@1020 538
twisti@1020 539 intx count = AllocatePrefetchDistance;
twisti@1020 540 if (count < 0) { // default ?
twisti@1020 541 if (is_amd()) { // AMD
twisti@1020 542 if (supports_sse2())
twisti@1020 543 count = 256; // Opteron
twisti@1020 544 else
twisti@1020 545 count = 128; // Athlon
twisti@1020 546 } else { // Intel
twisti@1020 547 if (supports_sse2())
twisti@1020 548 if (cpu_family() == 6) {
twisti@1020 549 count = 256; // Pentium M, Core, Core2
twisti@1020 550 } else {
twisti@1020 551 count = 512; // Pentium 4
twisti@1020 552 }
twisti@1020 553 else
twisti@1020 554 count = 128; // Pentium 3 (and all other old CPUs)
twisti@1020 555 }
twisti@1020 556 }
twisti@1020 557 return count;
twisti@1020 558 }
twisti@1020 559 static intx allocate_prefetch_style() {
twisti@1020 560 assert(AllocatePrefetchStyle >= 0, "AllocatePrefetchStyle should be positive");
twisti@1020 561 // Return 0 if AllocatePrefetchDistance was not defined.
twisti@1020 562 return AllocatePrefetchDistance > 0 ? AllocatePrefetchStyle : 0;
twisti@1020 563 }
twisti@1020 564
twisti@1020 565 // Prefetch interval for gc copy/scan == 9 dcache lines. Derived from
twisti@1020 566 // 50-warehouse specjbb runs on a 2-way 1.8ghz opteron using a 4gb heap.
twisti@1020 567 // Tested intervals from 128 to 2048 in increments of 64 == one cache line.
twisti@1020 568 // 256 bytes (4 dcache lines) was the nearest runner-up to 576.
twisti@1020 569
twisti@1020 570 // gc copy/scan is disabled if prefetchw isn't supported, because
twisti@1020 571 // Prefetch::write emits an inlined prefetchw on Linux.
twisti@1020 572 // Do not use the 3dnow prefetchw instruction. It isn't supported on em64t.
twisti@1020 573 // The used prefetcht0 instruction works for both amd64 and em64t.
twisti@1020 574 static intx prefetch_copy_interval_in_bytes() {
twisti@1020 575 intx interval = PrefetchCopyIntervalInBytes;
twisti@1020 576 return interval >= 0 ? interval : 576;
twisti@1020 577 }
twisti@1020 578 static intx prefetch_scan_interval_in_bytes() {
twisti@1020 579 intx interval = PrefetchScanIntervalInBytes;
twisti@1020 580 return interval >= 0 ? interval : 576;
twisti@1020 581 }
twisti@1020 582 static intx prefetch_fields_ahead() {
twisti@1020 583 intx count = PrefetchFieldsAhead;
twisti@1020 584 return count >= 0 ? count : 1;
twisti@1020 585 }
twisti@1020 586 };
stefank@2314 587
stefank@2314 588 #endif // CPU_X86_VM_VM_VERSION_X86_HPP

mercurial