src/cpu/ppc/vm/vm_version_ppc.cpp

Mon, 28 May 2018 10:33:52 +0800

author
aoqi
date
Mon, 28 May 2018 10:33:52 +0800
changeset 9041
95a08233f46c
parent 8903
9575483cce09
parent 8856
ac27a9c85bea
child 9572
624a0741915c
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * Copyright 2012, 2014 SAP AG. All rights reserved.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #include "asm/assembler.inline.hpp"
aoqi@0 28 #include "asm/macroAssembler.inline.hpp"
aoqi@0 29 #include "compiler/disassembler.hpp"
aoqi@0 30 #include "memory/resourceArea.hpp"
aoqi@0 31 #include "runtime/java.hpp"
aoqi@0 32 #include "runtime/stubCodeGenerator.hpp"
aoqi@0 33 #include "utilities/defaultStream.hpp"
aoqi@0 34 #include "vm_version_ppc.hpp"
aoqi@0 35 #ifdef TARGET_OS_FAMILY_aix
aoqi@0 36 # include "os_aix.inline.hpp"
aoqi@0 37 #endif
aoqi@0 38 #ifdef TARGET_OS_FAMILY_linux
aoqi@0 39 # include "os_linux.inline.hpp"
aoqi@0 40 #endif
aoqi@0 41
aoqi@0 42 # include <sys/sysinfo.h>
aoqi@0 43
aoqi@0 44 int VM_Version::_features = VM_Version::unknown_m;
aoqi@0 45 int VM_Version::_measured_cache_line_size = 128; // default value
aoqi@0 46 const char* VM_Version::_features_str = "";
aoqi@0 47 bool VM_Version::_is_determine_features_test_running = false;
aoqi@0 48
aoqi@0 49
aoqi@0 50 #define MSG(flag) \
aoqi@0 51 if (flag && !FLAG_IS_DEFAULT(flag)) \
aoqi@0 52 jio_fprintf(defaultStream::error_stream(), \
aoqi@0 53 "warning: -XX:+" #flag " requires -XX:+UseSIGTRAP\n" \
aoqi@0 54 " -XX:+" #flag " will be disabled!\n");
aoqi@0 55
aoqi@0 56 void VM_Version::initialize() {
aoqi@0 57
aoqi@0 58 // Test which instructions are supported and measure cache line size.
aoqi@0 59 determine_features();
aoqi@0 60
aoqi@0 61 // If PowerArchitecturePPC64 hasn't been specified explicitly determine from features.
aoqi@0 62 if (FLAG_IS_DEFAULT(PowerArchitecturePPC64)) {
aoqi@0 63 if (VM_Version::has_popcntw()) {
aoqi@0 64 FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 7);
aoqi@0 65 } else if (VM_Version::has_cmpb()) {
aoqi@0 66 FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 6);
aoqi@0 67 } else if (VM_Version::has_popcntb()) {
aoqi@0 68 FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 5);
aoqi@0 69 } else {
aoqi@0 70 FLAG_SET_ERGO(uintx, PowerArchitecturePPC64, 0);
aoqi@0 71 }
aoqi@0 72 }
aoqi@0 73 guarantee(PowerArchitecturePPC64 == 0 || PowerArchitecturePPC64 == 5 ||
aoqi@0 74 PowerArchitecturePPC64 == 6 || PowerArchitecturePPC64 == 7,
aoqi@0 75 "PowerArchitecturePPC64 should be 0, 5, 6 or 7");
aoqi@0 76
aoqi@0 77 if (!UseSIGTRAP) {
aoqi@0 78 MSG(TrapBasedICMissChecks);
aoqi@0 79 MSG(TrapBasedNotEntrantChecks);
aoqi@0 80 MSG(TrapBasedNullChecks);
aoqi@0 81 FLAG_SET_ERGO(bool, TrapBasedNotEntrantChecks, false);
aoqi@0 82 FLAG_SET_ERGO(bool, TrapBasedNullChecks, false);
aoqi@0 83 FLAG_SET_ERGO(bool, TrapBasedICMissChecks, false);
aoqi@0 84 }
aoqi@0 85
aoqi@0 86 #ifdef COMPILER2
aoqi@0 87 if (!UseSIGTRAP) {
aoqi@0 88 MSG(TrapBasedRangeChecks);
aoqi@0 89 FLAG_SET_ERGO(bool, TrapBasedRangeChecks, false);
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 // On Power6 test for section size.
aoqi@0 93 if (PowerArchitecturePPC64 == 6) {
aoqi@0 94 determine_section_size();
aoqi@0 95 // TODO: PPC port } else {
aoqi@0 96 // TODO: PPC port PdScheduling::power6SectorSize = 0x20;
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 MaxVectorSize = 8;
aoqi@0 100 #endif
aoqi@0 101
aoqi@0 102 // Create and print feature-string.
aoqi@0 103 char buf[(num_features+1) * 16]; // Max 16 chars per feature.
aoqi@0 104 jio_snprintf(buf, sizeof(buf),
simonis@8608 105 "ppc64%s%s%s%s%s%s%s%s%s",
aoqi@0 106 (has_fsqrt() ? " fsqrt" : ""),
aoqi@0 107 (has_isel() ? " isel" : ""),
aoqi@0 108 (has_lxarxeh() ? " lxarxeh" : ""),
aoqi@0 109 (has_cmpb() ? " cmpb" : ""),
aoqi@0 110 //(has_mftgpr()? " mftgpr" : ""),
aoqi@0 111 (has_popcntb() ? " popcntb" : ""),
aoqi@0 112 (has_popcntw() ? " popcntw" : ""),
aoqi@0 113 (has_fcfids() ? " fcfids" : ""),
simonis@8608 114 (has_vand() ? " vand" : ""),
simonis@8608 115 (has_vcipher() ? " aes" : "")
aoqi@0 116 // Make sure number of %s matches num_features!
aoqi@0 117 );
aoqi@0 118 _features_str = strdup(buf);
aoqi@0 119 NOT_PRODUCT(if (Verbose) print_features(););
aoqi@0 120
aoqi@0 121 // PPC64 supports 8-byte compare-exchange operations (see
aoqi@0 122 // Atomic::cmpxchg and StubGenerator::generate_atomic_cmpxchg_ptr)
aoqi@0 123 // and 'atomic long memory ops' (see Unsafe_GetLongVolatile).
aoqi@0 124 _supports_cx8 = true;
aoqi@0 125
aoqi@0 126 UseSSE = 0; // Only on x86 and x64
aoqi@0 127
aoqi@0 128 intx cache_line_size = _measured_cache_line_size;
aoqi@0 129
aoqi@0 130 if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) AllocatePrefetchStyle = 1;
aoqi@0 131
aoqi@0 132 if (AllocatePrefetchStyle == 4) {
aoqi@0 133 AllocatePrefetchStepSize = cache_line_size; // Need exact value.
aoqi@0 134 if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 12; // Use larger blocks by default.
aoqi@0 135 if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 2*cache_line_size; // Default is not defined?
aoqi@0 136 } else {
aoqi@0 137 if (cache_line_size > AllocatePrefetchStepSize) AllocatePrefetchStepSize = cache_line_size;
aoqi@0 138 if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 3; // Optimistic value.
aoqi@0 139 if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 3*cache_line_size; // Default is not defined?
aoqi@0 140 }
aoqi@0 141
aoqi@0 142 assert(AllocatePrefetchLines > 0, "invalid value");
goetz@7424 143 if (AllocatePrefetchLines < 1) { // Set valid value in product VM.
aoqi@0 144 AllocatePrefetchLines = 1; // Conservative value.
goetz@7424 145 }
aoqi@0 146
goetz@7424 147 if (AllocatePrefetchStyle == 3 && AllocatePrefetchDistance < cache_line_size) {
aoqi@0 148 AllocatePrefetchStyle = 1; // Fall back if inappropriate.
goetz@7424 149 }
aoqi@0 150
aoqi@0 151 assert(AllocatePrefetchStyle >= 0, "AllocatePrefetchStyle should be positive");
goetz@7424 152
goetz@7424 153 if (UseCRC32Intrinsics) {
goetz@7424 154 if (!FLAG_IS_DEFAULT(UseCRC32Intrinsics))
goetz@7424 155 warning("CRC32 intrinsics are not available on this CPU");
goetz@7424 156 FLAG_SET_DEFAULT(UseCRC32Intrinsics, false);
goetz@7424 157 }
goetz@7424 158
goetz@7424 159 // The AES intrinsic stubs require AES instruction support.
simonis@8608 160 #if defined(VM_LITTLE_ENDIAN)
simonis@8608 161 if (has_vcipher()) {
simonis@8608 162 if (FLAG_IS_DEFAULT(UseAES)) {
simonis@8608 163 UseAES = true;
simonis@8608 164 }
simonis@8608 165 } else if (UseAES) {
simonis@8608 166 if (!FLAG_IS_DEFAULT(UseAES))
simonis@8608 167 warning("AES instructions are not available on this CPU");
simonis@8608 168 FLAG_SET_DEFAULT(UseAES, false);
simonis@8608 169 }
simonis@8608 170
simonis@8608 171 if (UseAES && has_vcipher()) {
simonis@8608 172 if (FLAG_IS_DEFAULT(UseAESIntrinsics)) {
simonis@8608 173 UseAESIntrinsics = true;
simonis@8608 174 }
simonis@8608 175 } else if (UseAESIntrinsics) {
simonis@8608 176 if (!FLAG_IS_DEFAULT(UseAESIntrinsics))
simonis@8608 177 warning("AES intrinsics are not available on this CPU");
simonis@8608 178 FLAG_SET_DEFAULT(UseAESIntrinsics, false);
simonis@8608 179 }
simonis@8608 180
simonis@8608 181 #else
goetz@7424 182 if (UseAES) {
goetz@7424 183 warning("AES instructions are not available on this CPU");
goetz@7424 184 FLAG_SET_DEFAULT(UseAES, false);
goetz@7424 185 }
goetz@7424 186 if (UseAESIntrinsics) {
goetz@7424 187 if (!FLAG_IS_DEFAULT(UseAESIntrinsics))
goetz@7424 188 warning("AES intrinsics are not available on this CPU");
goetz@7424 189 FLAG_SET_DEFAULT(UseAESIntrinsics, false);
goetz@7424 190 }
simonis@8608 191 #endif
goetz@7424 192
goetz@7424 193 if (UseSHA) {
goetz@7424 194 warning("SHA instructions are not available on this CPU");
goetz@7424 195 FLAG_SET_DEFAULT(UseSHA, false);
goetz@7424 196 }
goetz@7424 197 if (UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics) {
goetz@7424 198 warning("SHA intrinsics are not available on this CPU");
goetz@7424 199 FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
goetz@7424 200 FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
goetz@7424 201 FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
goetz@7424 202 }
goetz@7424 203
mdoerr@8903 204 if (FLAG_IS_DEFAULT(UseMontgomeryMultiplyIntrinsic)) {
mdoerr@8903 205 UseMontgomeryMultiplyIntrinsic = true;
mdoerr@8903 206 }
mdoerr@8903 207 if (FLAG_IS_DEFAULT(UseMontgomerySquareIntrinsic)) {
mdoerr@8903 208 UseMontgomerySquareIntrinsic = true;
mdoerr@8903 209 }
aoqi@0 210 }
aoqi@0 211
aoqi@0 212 void VM_Version::print_features() {
aoqi@0 213 tty->print_cr("Version: %s cache_line_size = %d", cpu_features(), (int) get_cache_line_size());
aoqi@0 214 }
aoqi@0 215
aoqi@0 216 #ifdef COMPILER2
aoqi@0 217 // Determine section size on power6: If section size is 8 instructions,
aoqi@0 218 // there should be a difference between the two testloops of ~15 %. If
aoqi@0 219 // no difference is detected the section is assumed to be 32 instructions.
aoqi@0 220 void VM_Version::determine_section_size() {
aoqi@0 221
aoqi@0 222 int unroll = 80;
aoqi@0 223
aoqi@0 224 const int code_size = (2* unroll * 32 + 100)*BytesPerInstWord;
aoqi@0 225
aoqi@0 226 // Allocate space for the code.
aoqi@0 227 ResourceMark rm;
aoqi@0 228 CodeBuffer cb("detect_section_size", code_size, 0);
aoqi@0 229 MacroAssembler* a = new MacroAssembler(&cb);
aoqi@0 230
aoqi@0 231 uint32_t *code = (uint32_t *)a->pc();
aoqi@0 232 // Emit code.
aoqi@0 233 void (*test1)() = (void(*)())(void *)a->function_entry();
aoqi@0 234
aoqi@0 235 Label l1;
aoqi@0 236
aoqi@0 237 a->li(R4, 1);
aoqi@0 238 a->sldi(R4, R4, 28);
aoqi@0 239 a->b(l1);
aoqi@0 240 a->align(CodeEntryAlignment);
aoqi@0 241
aoqi@0 242 a->bind(l1);
aoqi@0 243
aoqi@0 244 for (int i = 0; i < unroll; i++) {
aoqi@0 245 // Schleife 1
aoqi@0 246 // ------- sector 0 ------------
aoqi@0 247 // ;; 0
aoqi@0 248 a->nop(); // 1
aoqi@0 249 a->fpnop0(); // 2
aoqi@0 250 a->fpnop1(); // 3
aoqi@0 251 a->addi(R4,R4, -1); // 4
aoqi@0 252
aoqi@0 253 // ;; 1
aoqi@0 254 a->nop(); // 5
aoqi@0 255 a->fmr(F6, F6); // 6
aoqi@0 256 a->fmr(F7, F7); // 7
aoqi@0 257 a->endgroup(); // 8
aoqi@0 258 // ------- sector 8 ------------
aoqi@0 259
aoqi@0 260 // ;; 2
aoqi@0 261 a->nop(); // 9
aoqi@0 262 a->nop(); // 10
aoqi@0 263 a->fmr(F8, F8); // 11
aoqi@0 264 a->fmr(F9, F9); // 12
aoqi@0 265
aoqi@0 266 // ;; 3
aoqi@0 267 a->nop(); // 13
aoqi@0 268 a->fmr(F10, F10); // 14
aoqi@0 269 a->fmr(F11, F11); // 15
aoqi@0 270 a->endgroup(); // 16
aoqi@0 271 // -------- sector 16 -------------
aoqi@0 272
aoqi@0 273 // ;; 4
aoqi@0 274 a->nop(); // 17
aoqi@0 275 a->nop(); // 18
aoqi@0 276 a->fmr(F15, F15); // 19
aoqi@0 277 a->fmr(F16, F16); // 20
aoqi@0 278
aoqi@0 279 // ;; 5
aoqi@0 280 a->nop(); // 21
aoqi@0 281 a->fmr(F17, F17); // 22
aoqi@0 282 a->fmr(F18, F18); // 23
aoqi@0 283 a->endgroup(); // 24
aoqi@0 284 // ------- sector 24 ------------
aoqi@0 285
aoqi@0 286 // ;; 6
aoqi@0 287 a->nop(); // 25
aoqi@0 288 a->nop(); // 26
aoqi@0 289 a->fmr(F19, F19); // 27
aoqi@0 290 a->fmr(F20, F20); // 28
aoqi@0 291
aoqi@0 292 // ;; 7
aoqi@0 293 a->nop(); // 29
aoqi@0 294 a->fmr(F21, F21); // 30
aoqi@0 295 a->fmr(F22, F22); // 31
aoqi@0 296 a->brnop0(); // 32
aoqi@0 297
aoqi@0 298 // ------- sector 32 ------------
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 // ;; 8
aoqi@0 302 a->cmpdi(CCR0, R4, unroll); // 33
aoqi@0 303 a->bge(CCR0, l1); // 34
aoqi@0 304 a->blr();
aoqi@0 305
aoqi@0 306 // Emit code.
aoqi@0 307 void (*test2)() = (void(*)())(void *)a->function_entry();
aoqi@0 308 // uint32_t *code = (uint32_t *)a->pc();
aoqi@0 309
aoqi@0 310 Label l2;
aoqi@0 311
aoqi@0 312 a->li(R4, 1);
aoqi@0 313 a->sldi(R4, R4, 28);
aoqi@0 314 a->b(l2);
aoqi@0 315 a->align(CodeEntryAlignment);
aoqi@0 316
aoqi@0 317 a->bind(l2);
aoqi@0 318
aoqi@0 319 for (int i = 0; i < unroll; i++) {
aoqi@0 320 // Schleife 2
aoqi@0 321 // ------- sector 0 ------------
aoqi@0 322 // ;; 0
aoqi@0 323 a->brnop0(); // 1
aoqi@0 324 a->nop(); // 2
aoqi@0 325 //a->cmpdi(CCR0, R4, unroll);
aoqi@0 326 a->fpnop0(); // 3
aoqi@0 327 a->fpnop1(); // 4
aoqi@0 328 a->addi(R4,R4, -1); // 5
aoqi@0 329
aoqi@0 330 // ;; 1
aoqi@0 331
aoqi@0 332 a->nop(); // 6
aoqi@0 333 a->fmr(F6, F6); // 7
aoqi@0 334 a->fmr(F7, F7); // 8
aoqi@0 335 // ------- sector 8 ---------------
aoqi@0 336
aoqi@0 337 // ;; 2
aoqi@0 338 a->endgroup(); // 9
aoqi@0 339
aoqi@0 340 // ;; 3
aoqi@0 341 a->nop(); // 10
aoqi@0 342 a->nop(); // 11
aoqi@0 343 a->fmr(F8, F8); // 12
aoqi@0 344
aoqi@0 345 // ;; 4
aoqi@0 346 a->fmr(F9, F9); // 13
aoqi@0 347 a->nop(); // 14
aoqi@0 348 a->fmr(F10, F10); // 15
aoqi@0 349
aoqi@0 350 // ;; 5
aoqi@0 351 a->fmr(F11, F11); // 16
aoqi@0 352 // -------- sector 16 -------------
aoqi@0 353
aoqi@0 354 // ;; 6
aoqi@0 355 a->endgroup(); // 17
aoqi@0 356
aoqi@0 357 // ;; 7
aoqi@0 358 a->nop(); // 18
aoqi@0 359 a->nop(); // 19
aoqi@0 360 a->fmr(F15, F15); // 20
aoqi@0 361
aoqi@0 362 // ;; 8
aoqi@0 363 a->fmr(F16, F16); // 21
aoqi@0 364 a->nop(); // 22
aoqi@0 365 a->fmr(F17, F17); // 23
aoqi@0 366
aoqi@0 367 // ;; 9
aoqi@0 368 a->fmr(F18, F18); // 24
aoqi@0 369 // -------- sector 24 -------------
aoqi@0 370
aoqi@0 371 // ;; 10
aoqi@0 372 a->endgroup(); // 25
aoqi@0 373
aoqi@0 374 // ;; 11
aoqi@0 375 a->nop(); // 26
aoqi@0 376 a->nop(); // 27
aoqi@0 377 a->fmr(F19, F19); // 28
aoqi@0 378
aoqi@0 379 // ;; 12
aoqi@0 380 a->fmr(F20, F20); // 29
aoqi@0 381 a->nop(); // 30
aoqi@0 382 a->fmr(F21, F21); // 31
aoqi@0 383
aoqi@0 384 // ;; 13
aoqi@0 385 a->fmr(F22, F22); // 32
aoqi@0 386 }
aoqi@0 387
aoqi@0 388 // -------- sector 32 -------------
aoqi@0 389 // ;; 14
aoqi@0 390 a->cmpdi(CCR0, R4, unroll); // 33
aoqi@0 391 a->bge(CCR0, l2); // 34
aoqi@0 392
aoqi@0 393 a->blr();
aoqi@0 394 uint32_t *code_end = (uint32_t *)a->pc();
aoqi@0 395 a->flush();
aoqi@0 396
aoqi@0 397 double loop1_seconds,loop2_seconds, rel_diff;
aoqi@0 398 uint64_t start1, stop1;
aoqi@0 399
aoqi@0 400 start1 = os::current_thread_cpu_time(false);
aoqi@0 401 (*test1)();
aoqi@0 402 stop1 = os::current_thread_cpu_time(false);
aoqi@0 403 loop1_seconds = (stop1- start1) / (1000 *1000 *1000.0);
aoqi@0 404
aoqi@0 405
aoqi@0 406 start1 = os::current_thread_cpu_time(false);
aoqi@0 407 (*test2)();
aoqi@0 408 stop1 = os::current_thread_cpu_time(false);
aoqi@0 409
aoqi@0 410 loop2_seconds = (stop1 - start1) / (1000 *1000 *1000.0);
aoqi@0 411
aoqi@0 412 rel_diff = (loop2_seconds - loop1_seconds) / loop1_seconds *100;
aoqi@0 413
aoqi@0 414 if (PrintAssembly) {
aoqi@0 415 ttyLocker ttyl;
coleenp@7358 416 tty->print_cr("Decoding section size detection stub at " INTPTR_FORMAT " before execution:", p2i(code));
aoqi@0 417 Disassembler::decode((u_char*)code, (u_char*)code_end, tty);
aoqi@0 418 tty->print_cr("Time loop1 :%f", loop1_seconds);
aoqi@0 419 tty->print_cr("Time loop2 :%f", loop2_seconds);
aoqi@0 420 tty->print_cr("(time2 - time1) / time1 = %f %%", rel_diff);
aoqi@0 421
aoqi@0 422 if (rel_diff > 12.0) {
aoqi@0 423 tty->print_cr("Section Size 8 Instructions");
aoqi@0 424 } else{
aoqi@0 425 tty->print_cr("Section Size 32 Instructions or Power5");
aoqi@0 426 }
aoqi@0 427 }
aoqi@0 428
aoqi@0 429 #if 0 // TODO: PPC port
aoqi@0 430 // Set sector size (if not set explicitly).
aoqi@0 431 if (FLAG_IS_DEFAULT(Power6SectorSize128PPC64)) {
aoqi@0 432 if (rel_diff > 12.0) {
aoqi@0 433 PdScheduling::power6SectorSize = 0x20;
aoqi@0 434 } else {
aoqi@0 435 PdScheduling::power6SectorSize = 0x80;
aoqi@0 436 }
aoqi@0 437 } else if (Power6SectorSize128PPC64) {
aoqi@0 438 PdScheduling::power6SectorSize = 0x80;
aoqi@0 439 } else {
aoqi@0 440 PdScheduling::power6SectorSize = 0x20;
aoqi@0 441 }
aoqi@0 442 #endif
aoqi@0 443 if (UsePower6SchedulerPPC64) Unimplemented();
aoqi@0 444 }
aoqi@0 445 #endif // COMPILER2
aoqi@0 446
aoqi@0 447 void VM_Version::determine_features() {
aoqi@0 448 #if defined(ABI_ELFv2)
aoqi@0 449 const int code_size = (num_features+1+2*7)*BytesPerInstWord; // TODO(asmundak): calculation is incorrect.
aoqi@0 450 #else
aoqi@0 451 // 7 InstWords for each call (function descriptor + blr instruction).
aoqi@0 452 const int code_size = (num_features+1+2*7)*BytesPerInstWord;
aoqi@0 453 #endif
aoqi@0 454 int features = 0;
aoqi@0 455
aoqi@0 456 // create test area
aoqi@0 457 enum { BUFFER_SIZE = 2*4*K }; // Needs to be >=2* max cache line size (cache line size can't exceed min page size).
aoqi@0 458 char test_area[BUFFER_SIZE];
aoqi@0 459 char *mid_of_test_area = &test_area[BUFFER_SIZE>>1];
aoqi@0 460
aoqi@0 461 // Allocate space for the code.
aoqi@0 462 ResourceMark rm;
aoqi@0 463 CodeBuffer cb("detect_cpu_features", code_size, 0);
aoqi@0 464 MacroAssembler* a = new MacroAssembler(&cb);
aoqi@0 465
aoqi@0 466 // Must be set to true so we can generate the test code.
aoqi@0 467 _features = VM_Version::all_features_m;
aoqi@0 468
aoqi@0 469 // Emit code.
aoqi@0 470 void (*test)(address addr, uint64_t offset)=(void(*)(address addr, uint64_t offset))(void *)a->function_entry();
aoqi@0 471 uint32_t *code = (uint32_t *)a->pc();
aoqi@0 472 // Don't use R0 in ldarx.
aoqi@0 473 // Keep R3_ARG1 unmodified, it contains &field (see below).
aoqi@0 474 // Keep R4_ARG2 unmodified, it contains offset = 0 (see below).
aoqi@0 475 a->fsqrt(F3, F4); // code[0] -> fsqrt_m
aoqi@0 476 a->fsqrts(F3, F4); // code[1] -> fsqrts_m
aoqi@0 477 a->isel(R7, R5, R6, 0); // code[2] -> isel_m
aoqi@0 478 a->ldarx_unchecked(R7, R3_ARG1, R4_ARG2, 1); // code[3] -> lxarx_m
aoqi@0 479 a->cmpb(R7, R5, R6); // code[4] -> bcmp
aoqi@0 480 //a->mftgpr(R7, F3); // code[5] -> mftgpr
aoqi@0 481 a->popcntb(R7, R5); // code[6] -> popcntb
aoqi@0 482 a->popcntw(R7, R5); // code[7] -> popcntw
aoqi@0 483 a->fcfids(F3, F4); // code[8] -> fcfids
aoqi@0 484 a->vand(VR0, VR0, VR0); // code[9] -> vand
simonis@8608 485 a->vcipher(VR0, VR1, VR2); // code[10] -> vcipher
aoqi@0 486 a->blr();
aoqi@0 487
aoqi@0 488 // Emit function to set one cache line to zero. Emit function descriptor and get pointer to it.
aoqi@0 489 void (*zero_cacheline_func_ptr)(char*) = (void(*)(char*))(void *)a->function_entry();
aoqi@0 490 a->dcbz(R3_ARG1); // R3_ARG1 = addr
aoqi@0 491 a->blr();
aoqi@0 492
aoqi@0 493 uint32_t *code_end = (uint32_t *)a->pc();
aoqi@0 494 a->flush();
aoqi@0 495 _features = VM_Version::unknown_m;
aoqi@0 496
aoqi@0 497 // Print the detection code.
aoqi@0 498 if (PrintAssembly) {
aoqi@0 499 ttyLocker ttyl;
coleenp@7358 500 tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " before execution:", p2i(code));
aoqi@0 501 Disassembler::decode((u_char*)code, (u_char*)code_end, tty);
aoqi@0 502 }
aoqi@0 503
aoqi@0 504 // Measure cache line size.
aoqi@0 505 memset(test_area, 0xFF, BUFFER_SIZE); // Fill test area with 0xFF.
aoqi@0 506 (*zero_cacheline_func_ptr)(mid_of_test_area); // Call function which executes dcbz to the middle.
aoqi@0 507 int count = 0; // count zeroed bytes
aoqi@0 508 for (int i = 0; i < BUFFER_SIZE; i++) if (test_area[i] == 0) count++;
aoqi@0 509 guarantee(is_power_of_2(count), "cache line size needs to be a power of 2");
aoqi@0 510 _measured_cache_line_size = count;
aoqi@0 511
aoqi@0 512 // Execute code. Illegal instructions will be replaced by 0 in the signal handler.
aoqi@0 513 VM_Version::_is_determine_features_test_running = true;
aoqi@0 514 (*test)((address)mid_of_test_area, (uint64_t)0);
aoqi@0 515 VM_Version::_is_determine_features_test_running = false;
aoqi@0 516
aoqi@0 517 // determine which instructions are legal.
aoqi@0 518 int feature_cntr = 0;
aoqi@0 519 if (code[feature_cntr++]) features |= fsqrt_m;
aoqi@0 520 if (code[feature_cntr++]) features |= fsqrts_m;
aoqi@0 521 if (code[feature_cntr++]) features |= isel_m;
aoqi@0 522 if (code[feature_cntr++]) features |= lxarxeh_m;
aoqi@0 523 if (code[feature_cntr++]) features |= cmpb_m;
aoqi@0 524 //if(code[feature_cntr++])features |= mftgpr_m;
aoqi@0 525 if (code[feature_cntr++]) features |= popcntb_m;
aoqi@0 526 if (code[feature_cntr++]) features |= popcntw_m;
aoqi@0 527 if (code[feature_cntr++]) features |= fcfids_m;
aoqi@0 528 if (code[feature_cntr++]) features |= vand_m;
simonis@8608 529 if (code[feature_cntr++]) features |= vcipher_m;
aoqi@0 530
aoqi@0 531 // Print the detection code.
aoqi@0 532 if (PrintAssembly) {
aoqi@0 533 ttyLocker ttyl;
coleenp@7358 534 tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " after execution:", p2i(code));
aoqi@0 535 Disassembler::decode((u_char*)code, (u_char*)code_end, tty);
aoqi@0 536 }
aoqi@0 537
aoqi@0 538 _features = features;
aoqi@0 539 }
aoqi@0 540
aoqi@0 541
aoqi@0 542 static int saved_features = 0;
aoqi@0 543
aoqi@0 544 void VM_Version::allow_all() {
aoqi@0 545 saved_features = _features;
aoqi@0 546 _features = all_features_m;
aoqi@0 547 }
aoqi@0 548
aoqi@0 549 void VM_Version::revert() {
aoqi@0 550 _features = saved_features;
aoqi@0 551 }

mercurial