src/cpu/ppc/vm/vm_version_ppc.cpp

Thu, 04 Apr 2019 17:56:29 +0800

author
aoqi
date
Thu, 04 Apr 2019 17:56:29 +0800
changeset 9572
624a0741915c
parent 9497
f892c3b6b651
parent 9041
95a08233f46c
child 9703
2fdf635bcf28
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),
mdoerr@9497 105 "ppc64%s%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" : ""),
mdoerr@9497 115 (has_vcipher() ? " aes" : ""),
mdoerr@9497 116 (has_vpmsumb() ? " vpmsumb" : "")
aoqi@0 117 // Make sure number of %s matches num_features!
aoqi@0 118 );
aoqi@0 119 _features_str = strdup(buf);
aoqi@0 120 NOT_PRODUCT(if (Verbose) print_features(););
aoqi@0 121
aoqi@0 122 // PPC64 supports 8-byte compare-exchange operations (see
aoqi@0 123 // Atomic::cmpxchg and StubGenerator::generate_atomic_cmpxchg_ptr)
aoqi@0 124 // and 'atomic long memory ops' (see Unsafe_GetLongVolatile).
aoqi@0 125 _supports_cx8 = true;
aoqi@0 126
aoqi@0 127 UseSSE = 0; // Only on x86 and x64
aoqi@0 128
aoqi@0 129 intx cache_line_size = _measured_cache_line_size;
aoqi@0 130
aoqi@0 131 if (FLAG_IS_DEFAULT(AllocatePrefetchStyle)) AllocatePrefetchStyle = 1;
aoqi@0 132
aoqi@0 133 if (AllocatePrefetchStyle == 4) {
aoqi@0 134 AllocatePrefetchStepSize = cache_line_size; // Need exact value.
aoqi@0 135 if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 12; // Use larger blocks by default.
aoqi@0 136 if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 2*cache_line_size; // Default is not defined?
aoqi@0 137 } else {
aoqi@0 138 if (cache_line_size > AllocatePrefetchStepSize) AllocatePrefetchStepSize = cache_line_size;
aoqi@0 139 if (FLAG_IS_DEFAULT(AllocatePrefetchLines)) AllocatePrefetchLines = 3; // Optimistic value.
aoqi@0 140 if (AllocatePrefetchDistance < 0) AllocatePrefetchDistance = 3*cache_line_size; // Default is not defined?
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 assert(AllocatePrefetchLines > 0, "invalid value");
goetz@7424 144 if (AllocatePrefetchLines < 1) { // Set valid value in product VM.
aoqi@0 145 AllocatePrefetchLines = 1; // Conservative value.
goetz@7424 146 }
aoqi@0 147
goetz@7424 148 if (AllocatePrefetchStyle == 3 && AllocatePrefetchDistance < cache_line_size) {
aoqi@0 149 AllocatePrefetchStyle = 1; // Fall back if inappropriate.
goetz@7424 150 }
aoqi@0 151
aoqi@0 152 assert(AllocatePrefetchStyle >= 0, "AllocatePrefetchStyle should be positive");
goetz@7424 153
gromero@9496 154 // Implementation does not use any of the vector instructions
gromero@9496 155 // available with Power8. Their exploitation is still pending.
gromero@9496 156 if (!UseCRC32Intrinsics) {
gromero@9496 157 if (FLAG_IS_DEFAULT(UseCRC32Intrinsics)) {
gromero@9496 158 FLAG_SET_DEFAULT(UseCRC32Intrinsics, true);
gromero@9496 159 }
goetz@7424 160 }
goetz@7424 161
goetz@7424 162 // The AES intrinsic stubs require AES instruction support.
simonis@8608 163 #if defined(VM_LITTLE_ENDIAN)
simonis@8608 164 if (has_vcipher()) {
simonis@8608 165 if (FLAG_IS_DEFAULT(UseAES)) {
simonis@8608 166 UseAES = true;
simonis@8608 167 }
simonis@8608 168 } else if (UseAES) {
simonis@8608 169 if (!FLAG_IS_DEFAULT(UseAES))
simonis@8608 170 warning("AES instructions are not available on this CPU");
simonis@8608 171 FLAG_SET_DEFAULT(UseAES, false);
simonis@8608 172 }
simonis@8608 173
simonis@8608 174 if (UseAES && has_vcipher()) {
simonis@8608 175 if (FLAG_IS_DEFAULT(UseAESIntrinsics)) {
simonis@8608 176 UseAESIntrinsics = true;
simonis@8608 177 }
simonis@8608 178 } else if (UseAESIntrinsics) {
simonis@8608 179 if (!FLAG_IS_DEFAULT(UseAESIntrinsics))
simonis@8608 180 warning("AES intrinsics are not available on this CPU");
simonis@8608 181 FLAG_SET_DEFAULT(UseAESIntrinsics, false);
simonis@8608 182 }
simonis@8608 183
simonis@8608 184 #else
goetz@7424 185 if (UseAES) {
goetz@7424 186 warning("AES instructions are not available on this CPU");
goetz@7424 187 FLAG_SET_DEFAULT(UseAES, false);
goetz@7424 188 }
goetz@7424 189 if (UseAESIntrinsics) {
goetz@7424 190 if (!FLAG_IS_DEFAULT(UseAESIntrinsics))
goetz@7424 191 warning("AES intrinsics are not available on this CPU");
goetz@7424 192 FLAG_SET_DEFAULT(UseAESIntrinsics, false);
goetz@7424 193 }
simonis@8608 194 #endif
goetz@7424 195
goetz@7424 196 if (UseSHA) {
goetz@7424 197 warning("SHA instructions are not available on this CPU");
goetz@7424 198 FLAG_SET_DEFAULT(UseSHA, false);
goetz@7424 199 }
goetz@7424 200 if (UseSHA1Intrinsics || UseSHA256Intrinsics || UseSHA512Intrinsics) {
goetz@7424 201 warning("SHA intrinsics are not available on this CPU");
goetz@7424 202 FLAG_SET_DEFAULT(UseSHA1Intrinsics, false);
goetz@7424 203 FLAG_SET_DEFAULT(UseSHA256Intrinsics, false);
goetz@7424 204 FLAG_SET_DEFAULT(UseSHA512Intrinsics, false);
goetz@7424 205 }
goetz@7424 206
mdoerr@8903 207 if (FLAG_IS_DEFAULT(UseMontgomeryMultiplyIntrinsic)) {
mdoerr@8903 208 UseMontgomeryMultiplyIntrinsic = true;
mdoerr@8903 209 }
mdoerr@8903 210 if (FLAG_IS_DEFAULT(UseMontgomerySquareIntrinsic)) {
mdoerr@8903 211 UseMontgomerySquareIntrinsic = true;
mdoerr@8903 212 }
aoqi@0 213 }
aoqi@0 214
aoqi@0 215 void VM_Version::print_features() {
aoqi@0 216 tty->print_cr("Version: %s cache_line_size = %d", cpu_features(), (int) get_cache_line_size());
aoqi@0 217 }
aoqi@0 218
aoqi@0 219 #ifdef COMPILER2
aoqi@0 220 // Determine section size on power6: If section size is 8 instructions,
aoqi@0 221 // there should be a difference between the two testloops of ~15 %. If
aoqi@0 222 // no difference is detected the section is assumed to be 32 instructions.
aoqi@0 223 void VM_Version::determine_section_size() {
aoqi@0 224
aoqi@0 225 int unroll = 80;
aoqi@0 226
aoqi@0 227 const int code_size = (2* unroll * 32 + 100)*BytesPerInstWord;
aoqi@0 228
aoqi@0 229 // Allocate space for the code.
aoqi@0 230 ResourceMark rm;
aoqi@0 231 CodeBuffer cb("detect_section_size", code_size, 0);
aoqi@0 232 MacroAssembler* a = new MacroAssembler(&cb);
aoqi@0 233
aoqi@0 234 uint32_t *code = (uint32_t *)a->pc();
aoqi@0 235 // Emit code.
aoqi@0 236 void (*test1)() = (void(*)())(void *)a->function_entry();
aoqi@0 237
aoqi@0 238 Label l1;
aoqi@0 239
aoqi@0 240 a->li(R4, 1);
aoqi@0 241 a->sldi(R4, R4, 28);
aoqi@0 242 a->b(l1);
aoqi@0 243 a->align(CodeEntryAlignment);
aoqi@0 244
aoqi@0 245 a->bind(l1);
aoqi@0 246
aoqi@0 247 for (int i = 0; i < unroll; i++) {
aoqi@0 248 // Schleife 1
aoqi@0 249 // ------- sector 0 ------------
aoqi@0 250 // ;; 0
aoqi@0 251 a->nop(); // 1
aoqi@0 252 a->fpnop0(); // 2
aoqi@0 253 a->fpnop1(); // 3
aoqi@0 254 a->addi(R4,R4, -1); // 4
aoqi@0 255
aoqi@0 256 // ;; 1
aoqi@0 257 a->nop(); // 5
aoqi@0 258 a->fmr(F6, F6); // 6
aoqi@0 259 a->fmr(F7, F7); // 7
aoqi@0 260 a->endgroup(); // 8
aoqi@0 261 // ------- sector 8 ------------
aoqi@0 262
aoqi@0 263 // ;; 2
aoqi@0 264 a->nop(); // 9
aoqi@0 265 a->nop(); // 10
aoqi@0 266 a->fmr(F8, F8); // 11
aoqi@0 267 a->fmr(F9, F9); // 12
aoqi@0 268
aoqi@0 269 // ;; 3
aoqi@0 270 a->nop(); // 13
aoqi@0 271 a->fmr(F10, F10); // 14
aoqi@0 272 a->fmr(F11, F11); // 15
aoqi@0 273 a->endgroup(); // 16
aoqi@0 274 // -------- sector 16 -------------
aoqi@0 275
aoqi@0 276 // ;; 4
aoqi@0 277 a->nop(); // 17
aoqi@0 278 a->nop(); // 18
aoqi@0 279 a->fmr(F15, F15); // 19
aoqi@0 280 a->fmr(F16, F16); // 20
aoqi@0 281
aoqi@0 282 // ;; 5
aoqi@0 283 a->nop(); // 21
aoqi@0 284 a->fmr(F17, F17); // 22
aoqi@0 285 a->fmr(F18, F18); // 23
aoqi@0 286 a->endgroup(); // 24
aoqi@0 287 // ------- sector 24 ------------
aoqi@0 288
aoqi@0 289 // ;; 6
aoqi@0 290 a->nop(); // 25
aoqi@0 291 a->nop(); // 26
aoqi@0 292 a->fmr(F19, F19); // 27
aoqi@0 293 a->fmr(F20, F20); // 28
aoqi@0 294
aoqi@0 295 // ;; 7
aoqi@0 296 a->nop(); // 29
aoqi@0 297 a->fmr(F21, F21); // 30
aoqi@0 298 a->fmr(F22, F22); // 31
aoqi@0 299 a->brnop0(); // 32
aoqi@0 300
aoqi@0 301 // ------- sector 32 ------------
aoqi@0 302 }
aoqi@0 303
aoqi@0 304 // ;; 8
aoqi@0 305 a->cmpdi(CCR0, R4, unroll); // 33
aoqi@0 306 a->bge(CCR0, l1); // 34
aoqi@0 307 a->blr();
aoqi@0 308
aoqi@0 309 // Emit code.
aoqi@0 310 void (*test2)() = (void(*)())(void *)a->function_entry();
aoqi@0 311 // uint32_t *code = (uint32_t *)a->pc();
aoqi@0 312
aoqi@0 313 Label l2;
aoqi@0 314
aoqi@0 315 a->li(R4, 1);
aoqi@0 316 a->sldi(R4, R4, 28);
aoqi@0 317 a->b(l2);
aoqi@0 318 a->align(CodeEntryAlignment);
aoqi@0 319
aoqi@0 320 a->bind(l2);
aoqi@0 321
aoqi@0 322 for (int i = 0; i < unroll; i++) {
aoqi@0 323 // Schleife 2
aoqi@0 324 // ------- sector 0 ------------
aoqi@0 325 // ;; 0
aoqi@0 326 a->brnop0(); // 1
aoqi@0 327 a->nop(); // 2
aoqi@0 328 //a->cmpdi(CCR0, R4, unroll);
aoqi@0 329 a->fpnop0(); // 3
aoqi@0 330 a->fpnop1(); // 4
aoqi@0 331 a->addi(R4,R4, -1); // 5
aoqi@0 332
aoqi@0 333 // ;; 1
aoqi@0 334
aoqi@0 335 a->nop(); // 6
aoqi@0 336 a->fmr(F6, F6); // 7
aoqi@0 337 a->fmr(F7, F7); // 8
aoqi@0 338 // ------- sector 8 ---------------
aoqi@0 339
aoqi@0 340 // ;; 2
aoqi@0 341 a->endgroup(); // 9
aoqi@0 342
aoqi@0 343 // ;; 3
aoqi@0 344 a->nop(); // 10
aoqi@0 345 a->nop(); // 11
aoqi@0 346 a->fmr(F8, F8); // 12
aoqi@0 347
aoqi@0 348 // ;; 4
aoqi@0 349 a->fmr(F9, F9); // 13
aoqi@0 350 a->nop(); // 14
aoqi@0 351 a->fmr(F10, F10); // 15
aoqi@0 352
aoqi@0 353 // ;; 5
aoqi@0 354 a->fmr(F11, F11); // 16
aoqi@0 355 // -------- sector 16 -------------
aoqi@0 356
aoqi@0 357 // ;; 6
aoqi@0 358 a->endgroup(); // 17
aoqi@0 359
aoqi@0 360 // ;; 7
aoqi@0 361 a->nop(); // 18
aoqi@0 362 a->nop(); // 19
aoqi@0 363 a->fmr(F15, F15); // 20
aoqi@0 364
aoqi@0 365 // ;; 8
aoqi@0 366 a->fmr(F16, F16); // 21
aoqi@0 367 a->nop(); // 22
aoqi@0 368 a->fmr(F17, F17); // 23
aoqi@0 369
aoqi@0 370 // ;; 9
aoqi@0 371 a->fmr(F18, F18); // 24
aoqi@0 372 // -------- sector 24 -------------
aoqi@0 373
aoqi@0 374 // ;; 10
aoqi@0 375 a->endgroup(); // 25
aoqi@0 376
aoqi@0 377 // ;; 11
aoqi@0 378 a->nop(); // 26
aoqi@0 379 a->nop(); // 27
aoqi@0 380 a->fmr(F19, F19); // 28
aoqi@0 381
aoqi@0 382 // ;; 12
aoqi@0 383 a->fmr(F20, F20); // 29
aoqi@0 384 a->nop(); // 30
aoqi@0 385 a->fmr(F21, F21); // 31
aoqi@0 386
aoqi@0 387 // ;; 13
aoqi@0 388 a->fmr(F22, F22); // 32
aoqi@0 389 }
aoqi@0 390
aoqi@0 391 // -------- sector 32 -------------
aoqi@0 392 // ;; 14
aoqi@0 393 a->cmpdi(CCR0, R4, unroll); // 33
aoqi@0 394 a->bge(CCR0, l2); // 34
aoqi@0 395
aoqi@0 396 a->blr();
aoqi@0 397 uint32_t *code_end = (uint32_t *)a->pc();
aoqi@0 398 a->flush();
aoqi@0 399
aoqi@0 400 double loop1_seconds,loop2_seconds, rel_diff;
aoqi@0 401 uint64_t start1, stop1;
aoqi@0 402
aoqi@0 403 start1 = os::current_thread_cpu_time(false);
aoqi@0 404 (*test1)();
aoqi@0 405 stop1 = os::current_thread_cpu_time(false);
aoqi@0 406 loop1_seconds = (stop1- start1) / (1000 *1000 *1000.0);
aoqi@0 407
aoqi@0 408
aoqi@0 409 start1 = os::current_thread_cpu_time(false);
aoqi@0 410 (*test2)();
aoqi@0 411 stop1 = os::current_thread_cpu_time(false);
aoqi@0 412
aoqi@0 413 loop2_seconds = (stop1 - start1) / (1000 *1000 *1000.0);
aoqi@0 414
aoqi@0 415 rel_diff = (loop2_seconds - loop1_seconds) / loop1_seconds *100;
aoqi@0 416
aoqi@0 417 if (PrintAssembly) {
aoqi@0 418 ttyLocker ttyl;
coleenp@7358 419 tty->print_cr("Decoding section size detection stub at " INTPTR_FORMAT " before execution:", p2i(code));
aoqi@0 420 Disassembler::decode((u_char*)code, (u_char*)code_end, tty);
aoqi@0 421 tty->print_cr("Time loop1 :%f", loop1_seconds);
aoqi@0 422 tty->print_cr("Time loop2 :%f", loop2_seconds);
aoqi@0 423 tty->print_cr("(time2 - time1) / time1 = %f %%", rel_diff);
aoqi@0 424
aoqi@0 425 if (rel_diff > 12.0) {
aoqi@0 426 tty->print_cr("Section Size 8 Instructions");
aoqi@0 427 } else{
aoqi@0 428 tty->print_cr("Section Size 32 Instructions or Power5");
aoqi@0 429 }
aoqi@0 430 }
aoqi@0 431
aoqi@0 432 #if 0 // TODO: PPC port
aoqi@0 433 // Set sector size (if not set explicitly).
aoqi@0 434 if (FLAG_IS_DEFAULT(Power6SectorSize128PPC64)) {
aoqi@0 435 if (rel_diff > 12.0) {
aoqi@0 436 PdScheduling::power6SectorSize = 0x20;
aoqi@0 437 } else {
aoqi@0 438 PdScheduling::power6SectorSize = 0x80;
aoqi@0 439 }
aoqi@0 440 } else if (Power6SectorSize128PPC64) {
aoqi@0 441 PdScheduling::power6SectorSize = 0x80;
aoqi@0 442 } else {
aoqi@0 443 PdScheduling::power6SectorSize = 0x20;
aoqi@0 444 }
aoqi@0 445 #endif
aoqi@0 446 if (UsePower6SchedulerPPC64) Unimplemented();
aoqi@0 447 }
aoqi@0 448 #endif // COMPILER2
aoqi@0 449
aoqi@0 450 void VM_Version::determine_features() {
aoqi@0 451 #if defined(ABI_ELFv2)
aoqi@0 452 const int code_size = (num_features+1+2*7)*BytesPerInstWord; // TODO(asmundak): calculation is incorrect.
aoqi@0 453 #else
aoqi@0 454 // 7 InstWords for each call (function descriptor + blr instruction).
aoqi@0 455 const int code_size = (num_features+1+2*7)*BytesPerInstWord;
aoqi@0 456 #endif
aoqi@0 457 int features = 0;
aoqi@0 458
aoqi@0 459 // create test area
aoqi@0 460 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 461 char test_area[BUFFER_SIZE];
aoqi@0 462 char *mid_of_test_area = &test_area[BUFFER_SIZE>>1];
aoqi@0 463
aoqi@0 464 // Allocate space for the code.
aoqi@0 465 ResourceMark rm;
aoqi@0 466 CodeBuffer cb("detect_cpu_features", code_size, 0);
aoqi@0 467 MacroAssembler* a = new MacroAssembler(&cb);
aoqi@0 468
aoqi@0 469 // Must be set to true so we can generate the test code.
aoqi@0 470 _features = VM_Version::all_features_m;
aoqi@0 471
aoqi@0 472 // Emit code.
aoqi@0 473 void (*test)(address addr, uint64_t offset)=(void(*)(address addr, uint64_t offset))(void *)a->function_entry();
aoqi@0 474 uint32_t *code = (uint32_t *)a->pc();
aoqi@0 475 // Don't use R0 in ldarx.
aoqi@0 476 // Keep R3_ARG1 unmodified, it contains &field (see below).
aoqi@0 477 // Keep R4_ARG2 unmodified, it contains offset = 0 (see below).
aoqi@0 478 a->fsqrt(F3, F4); // code[0] -> fsqrt_m
aoqi@0 479 a->fsqrts(F3, F4); // code[1] -> fsqrts_m
aoqi@0 480 a->isel(R7, R5, R6, 0); // code[2] -> isel_m
aoqi@0 481 a->ldarx_unchecked(R7, R3_ARG1, R4_ARG2, 1); // code[3] -> lxarx_m
aoqi@0 482 a->cmpb(R7, R5, R6); // code[4] -> bcmp
aoqi@0 483 //a->mftgpr(R7, F3); // code[5] -> mftgpr
aoqi@0 484 a->popcntb(R7, R5); // code[6] -> popcntb
aoqi@0 485 a->popcntw(R7, R5); // code[7] -> popcntw
aoqi@0 486 a->fcfids(F3, F4); // code[8] -> fcfids
aoqi@0 487 a->vand(VR0, VR0, VR0); // code[9] -> vand
simonis@8608 488 a->vcipher(VR0, VR1, VR2); // code[10] -> vcipher
mdoerr@9497 489 a->vpmsumb(VR0, VR1, VR2); // code[11] -> vpmsumb
aoqi@0 490 a->blr();
aoqi@0 491
aoqi@0 492 // Emit function to set one cache line to zero. Emit function descriptor and get pointer to it.
aoqi@0 493 void (*zero_cacheline_func_ptr)(char*) = (void(*)(char*))(void *)a->function_entry();
aoqi@0 494 a->dcbz(R3_ARG1); // R3_ARG1 = addr
aoqi@0 495 a->blr();
aoqi@0 496
aoqi@0 497 uint32_t *code_end = (uint32_t *)a->pc();
aoqi@0 498 a->flush();
aoqi@0 499 _features = VM_Version::unknown_m;
aoqi@0 500
aoqi@0 501 // Print the detection code.
aoqi@0 502 if (PrintAssembly) {
aoqi@0 503 ttyLocker ttyl;
coleenp@7358 504 tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " before execution:", p2i(code));
aoqi@0 505 Disassembler::decode((u_char*)code, (u_char*)code_end, tty);
aoqi@0 506 }
aoqi@0 507
aoqi@0 508 // Measure cache line size.
aoqi@0 509 memset(test_area, 0xFF, BUFFER_SIZE); // Fill test area with 0xFF.
aoqi@0 510 (*zero_cacheline_func_ptr)(mid_of_test_area); // Call function which executes dcbz to the middle.
aoqi@0 511 int count = 0; // count zeroed bytes
aoqi@0 512 for (int i = 0; i < BUFFER_SIZE; i++) if (test_area[i] == 0) count++;
aoqi@0 513 guarantee(is_power_of_2(count), "cache line size needs to be a power of 2");
aoqi@0 514 _measured_cache_line_size = count;
aoqi@0 515
aoqi@0 516 // Execute code. Illegal instructions will be replaced by 0 in the signal handler.
aoqi@0 517 VM_Version::_is_determine_features_test_running = true;
aoqi@0 518 (*test)((address)mid_of_test_area, (uint64_t)0);
aoqi@0 519 VM_Version::_is_determine_features_test_running = false;
aoqi@0 520
aoqi@0 521 // determine which instructions are legal.
aoqi@0 522 int feature_cntr = 0;
aoqi@0 523 if (code[feature_cntr++]) features |= fsqrt_m;
aoqi@0 524 if (code[feature_cntr++]) features |= fsqrts_m;
aoqi@0 525 if (code[feature_cntr++]) features |= isel_m;
aoqi@0 526 if (code[feature_cntr++]) features |= lxarxeh_m;
aoqi@0 527 if (code[feature_cntr++]) features |= cmpb_m;
aoqi@0 528 //if(code[feature_cntr++])features |= mftgpr_m;
aoqi@0 529 if (code[feature_cntr++]) features |= popcntb_m;
aoqi@0 530 if (code[feature_cntr++]) features |= popcntw_m;
aoqi@0 531 if (code[feature_cntr++]) features |= fcfids_m;
aoqi@0 532 if (code[feature_cntr++]) features |= vand_m;
simonis@8608 533 if (code[feature_cntr++]) features |= vcipher_m;
mdoerr@9497 534 if (code[feature_cntr++]) features |= vpmsumb_m;
aoqi@0 535
aoqi@0 536 // Print the detection code.
aoqi@0 537 if (PrintAssembly) {
aoqi@0 538 ttyLocker ttyl;
coleenp@7358 539 tty->print_cr("Decoding cpu-feature detection stub at " INTPTR_FORMAT " after execution:", p2i(code));
aoqi@0 540 Disassembler::decode((u_char*)code, (u_char*)code_end, tty);
aoqi@0 541 }
aoqi@0 542
aoqi@0 543 _features = features;
aoqi@0 544 }
aoqi@0 545
aoqi@0 546
aoqi@0 547 static int saved_features = 0;
aoqi@0 548
aoqi@0 549 void VM_Version::allow_all() {
aoqi@0 550 saved_features = _features;
aoqi@0 551 _features = all_features_m;
aoqi@0 552 }
aoqi@0 553
aoqi@0 554 void VM_Version::revert() {
aoqi@0 555 _features = saved_features;
aoqi@0 556 }

mercurial