src/cpu/ppc/vm/vm_version_ppc.cpp

Thu, 12 Oct 2017 16:29:52 +0100

author
mdoerr
date
Thu, 12 Oct 2017 16:29:52 +0100
changeset 8903
9575483cce09
parent 8608
0d78aecb0948
child 9041
95a08233f46c
child 9496
bcccbecdde63
permissions
-rw-r--r--

8145913: PPC64: add Montgomery multiply intrinsic
Reviewed-by: aph, goetz, mdoerr
Contributed-by: Gustavo Serra Scalet <gustavo.scalet@eldorado.org.br>

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

mercurial