Rev 154 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 154 | Rev 156 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | ******************************************************************************* |
30 | ******************************************************************************* |
31 | */ |
31 | */ |
32 | void AlignedMalloc(void **pointer, uint64_t alignment, size_t size) { |
32 | void AlignedMalloc(void **pointer, uint64_t alignment, size_t size) { |
33 | uint64_t temp; |
33 | uint64_t temp; |
34 | 34 | ||
35 | segments[nsegments][0] = malloc( |
35 | segments[nsegments][0] = malloc((size_t) (size + alignment - 1)); // Pierre-Marie Baty -- added type cast |
36 | segments[nsegments][1] = segments[nsegments][0]; |
36 | segments[nsegments][1] = segments[nsegments][0]; |
37 | temp = (uint64_t) segments[nsegments][0]; |
37 | temp = (uint64_t) segments[nsegments][0]; |
38 | temp = (temp + alignment - 1) & ~(alignment - 1); |
38 | temp = (temp + alignment - 1) & ~(alignment - 1); |
39 | segments[nsegments][1] = (void *) temp; |
39 | segments[nsegments][1] = (void *) temp; |
40 | *pointer = segments[nsegments][1]; |
40 | *pointer = segments[nsegments][1]; |
Line 82... | Line 82... | ||
82 | if (i == nsegments) { |
82 | if (i == nsegments) { |
83 | Print(4095, "ERROR AlignedRemalloc() given an invalid pointer\n"); |
83 | Print(4095, "ERROR AlignedRemalloc() given an invalid pointer\n"); |
84 | exit(1); |
84 | exit(1); |
85 | } |
85 | } |
86 | free(segments[i][0]); |
86 | free(segments[i][0]); |
87 | segments[i][0] = malloc( |
87 | segments[i][0] = malloc((size_t) (size + alignment - 1)); // Pierre-Marie Baty -- added type cast |
88 | temp = (uint64_t) segments[i][0]; |
88 | temp = (uint64_t) segments[i][0]; |
89 | temp = (temp + alignment - 1) & ~(alignment - 1); |
89 | temp = (temp + alignment - 1) & ~(alignment - 1); |
90 | segments[i][1] = (void *) temp; |
90 | segments[i][1] = (void *) temp; |
91 | *pointer = segments[i][1]; |
91 | *pointer = segments[i][1]; |
92 | } |
92 | } |
Line 270... | Line 270... | ||
270 | int i; |
270 | int i; |
271 | static int init = 0, pipe; |
271 | static int init = 0, pipe; |
272 | static HANDLE inh; |
272 | static HANDLE inh; |
273 | DWORD dw; |
273 | DWORD dw; |
274 | 274 | ||
275 | if (!xboard && ! |
275 | if (!xboard && !_isatty(_fileno(stdin))) // Pierre-Marie Baty -- ISO C++ name conformance fixes |
276 | return 0; |
276 | return 0; |
277 | if (batch_mode) |
277 | if (batch_mode) |
278 | return 0; |
278 | return 0; |
279 | if (strchr(cmd_buffer, '\n')) |
279 | if (strchr(cmd_buffer, '\n')) |
280 | return 1; |
280 | return 1; |
Line 288... | Line 288... | ||
288 | inh = GetStdHandle(STD_INPUT_HANDLE); |
288 | inh = GetStdHandle(STD_INPUT_HANDLE); |
289 | pipe = !GetConsoleMode(inh, &dw); |
289 | pipe = !GetConsoleMode(inh, &dw); |
290 | if (!pipe) { |
290 | if (!pipe) { |
291 | SetConsoleMode(inh, dw & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT)); |
291 | SetConsoleMode(inh, dw & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT)); |
292 | FlushConsoleInputBuffer(inh); |
292 | FlushConsoleInputBuffer(inh); |
293 | } |
293 | } |
294 | } |
294 | } |
295 | if (pipe) { |
295 | if (pipe) { |
296 | if (!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL)) { |
296 | if (!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL)) { |
297 | return 1; |
297 | return 1; |
298 | } |
298 | } |
Line 340... | Line 340... | ||
340 | * search path information in it. * |
340 | * search path information in it. * |
341 | * * |
341 | * * |
342 | ******************************************************************************* |
342 | ******************************************************************************* |
343 | */ |
343 | */ |
344 | void ClearHashTableScores(void) { |
344 | void ClearHashTableScores(void) { |
345 | int |
345 | unsigned int i; // Pierre-Marie Baty -- fixed type |
346 | 346 | ||
347 | if (hash_table) |
347 | if (hash_table) |
348 | for (i = 0; i < hash_table_size; i++) { |
348 | for (i = 0; i < hash_table_size; i++) { |
349 | (hash_table + i)->word2 ^= (hash_table + i)->word1; |
349 | (hash_table + i)->word2 ^= (hash_table + i)->word1; |
350 | (hash_table + i)->word1 = |
350 | (hash_table + i)->word1 = |
Line 848... | Line 848... | ||
848 | else if (pv->pathh == 3) |
848 | else if (pv->pathh == 3) |
849 | sprintf(buffer + strlen(buffer), " <50-move>"); |
849 | sprintf(buffer + strlen(buffer), " <50-move>"); |
850 | else if (pv->pathh == 4) |
850 | else if (pv->pathh == 4) |
851 | sprintf(buffer + strlen(buffer), " <EGTB>"); |
851 | sprintf(buffer + strlen(buffer), " <EGTB>"); |
852 | if (strlen(buffer) < 30) |
852 | if (strlen(buffer) < 30) |
853 | for (i = 0; i < 30 - strlen |
853 | for (i = 0; i < 30 - (int) strlen(buffer); i++) // Pierre-Marie Baty -- added type cast |
854 | strcat(buffer, " "); |
854 | strcat(buffer, " "); |
855 | strcpy(kibitz_text, buffer); |
855 | strcpy(kibitz_text, buffer); |
856 | for (i = pv->pathl - 1; i > 0; i--) { |
856 | for (i = pv->pathl - 1; i > 0; i--) { |
857 | wtm = Flip(wtm); |
857 | wtm = Flip(wtm); |
858 | UnmakeMove(tree, i, wtm, pv->path[i]); |
858 | UnmakeMove(tree, i, wtm, pv->path[i]); |
Line 879... | Line 879... | ||
879 | * return immediately. Otherwise we add the fail high/low * |
879 | * return immediately. Otherwise we add the fail high/low * |
880 | * indicator (++/--) and then display the times. * |
880 | * indicator (++/--) and then display the times. * |
881 | * * |
881 | * * |
882 | ************************************************************ |
882 | ************************************************************ |
883 | */ |
883 | */ |
884 | if (time < noise_level) |
884 | if (time < (int) noise_level) // Pierre-Marie Baty -- added type cast |
885 | return; |
885 | return; |
886 | if (type == 1) |
886 | if (type == 1) |
887 | fh_indicator = (wtm) ? "++" : "--"; |
887 | fh_indicator = (wtm) ? "++" : "--"; |
888 | else |
888 | else |
889 | fh_indicator = (wtm) ? "--" : "++"; |
889 | fh_indicator = (wtm) ? "--" : "++"; |
Line 911... | Line 911... | ||
911 | sprintf(buffer, "%d. (%s)", move_number, ponder_text); |
911 | sprintf(buffer, "%d. (%s)", move_number, ponder_text); |
912 | } |
912 | } |
913 | sprintf(buffer + strlen(buffer), " %s%c", OutputMove(tree, 1, wtm, move), |
913 | sprintf(buffer + strlen(buffer), " %s%c", OutputMove(tree, 1, wtm, move), |
914 | (type == 1) ? '!' : '?'); |
914 | (type == 1) ? '!' : '?'); |
915 | strcpy(kibitz_text, buffer); |
915 | strcpy(kibitz_text, buffer); |
916 | if (time >= |
916 | if (time >= (int) noise_level || force) { // Pierre-Marie Baty -- added type cast |
917 | noise_block = 0; |
917 | noise_block = 0; |
918 | Lock(lock_io); |
918 | Lock(lock_io); |
919 | Print(4, "%s", buffer); |
919 | Print(4, "%s", buffer); |
920 | Unlock(lock_io); |
920 | Unlock(lock_io); |
921 | if (type == 1) |
921 | if (type == 1) |
Line 989... | Line 989... | ||
989 | len = 30 - strlen(buffer); |
989 | len = 30 - strlen(buffer); |
990 | for (i = 0; i < len; i++) |
990 | for (i = 0; i < len; i++) |
991 | strcat(buffer, " "); |
991 | strcat(buffer, " "); |
992 | } |
992 | } |
993 | strcpy(kibitz_text, buffer); |
993 | strcpy(kibitz_text, buffer); |
994 | if (time >= |
994 | if (time >= (int) noise_level || force) { // Pierre-Marie Baty -- added type cast |
995 | noise_block = 0; |
995 | noise_block = 0; |
996 | Lock(lock_io); |
996 | Lock(lock_io); |
997 | Print(2, " "); |
997 | Print(2, " "); |
998 | if (level == 6) |
998 | if (level == 6) |
999 | Print(2, "%2i %s%s ", pv_depth, Display2Times(time), |
999 | Print(2, "%2i %s%s ", pv_depth, Display2Times(time), |
Line 1026... | Line 1026... | ||
1026 | idle_time += thread[i].idle; |
1026 | idle_time += thread[i].idle; |
1027 | busy_percent = |
1027 | busy_percent = |
1028 | 100 - Min(100, |
1028 | 100 - Min(100, |
1029 | 100 * idle_time / (smp_max_threads * (end_time - start_time) + 1)); |
1029 | 100 * idle_time / (smp_max_threads * (end_time - start_time) + 1)); |
1030 | Kibitz(level, twtm, pv_depth, end_time - start_time, pv->pathv, |
1030 | Kibitz(level, twtm, pv_depth, end_time - start_time, pv->pathv, |
1031 | tree->nodes_searched, busy_percent, tree |
1031 | tree->nodes_searched, busy_percent, (int) tree->egtb_hits, kibitz_text); // Pierre-Marie Baty -- added type cast |
1032 | Unlock(lock_io); |
1032 | Unlock(lock_io); |
1033 | } |
1033 | } |
1034 | for (i = pv->pathl - 1; i > 0; i--) { |
1034 | for (i = pv->pathl - 1; i > 0; i--) { |
1035 | wtm = Flip(wtm); |
1035 | wtm = Flip(wtm); |
1036 | UnmakeMove(tree, i, wtm, pv->path[i]); |
1036 | UnmakeMove(tree, i, wtm, pv->path[i]); |
Line 1821... | Line 1821... | ||
1821 | int ReadInput(void) { |
1821 | int ReadInput(void) { |
1822 | int bytes; |
1822 | int bytes; |
1823 | char buffer[4096], *end; |
1823 | char buffer[4096], *end; |
1824 | 1824 | ||
1825 | do |
1825 | do |
1826 | bytes = |
1826 | bytes = _read(_fileno(input_stream), buffer, 2048); // Pierre-Marie Baty -- ISO C++ name conformance fixes |
1827 | while (bytes < 0 && errno == EINTR); |
1827 | while (bytes < 0 && errno == EINTR); |
1828 | if (bytes == 0) { |
1828 | if (bytes == 0) { |
1829 | if (input_stream != stdin) |
1829 | if (input_stream != stdin) |
1830 | fclose(input_stream); |
1830 | fclose(input_stream); |
1831 | input_stream = stdin; |
1831 | input_stream = stdin; |
Line 2321... | Line 2321... | ||
2321 | * StrCnt() counts the number of times a character occurs in a string. * |
2321 | * StrCnt() counts the number of times a character occurs in a string. * |
2322 | * * |
2322 | * * |
2323 | ******************************************************************************* |
2323 | ******************************************************************************* |
2324 | */ |
2324 | */ |
2325 | int StrCnt(char *string, char testchar) { |
2325 | int StrCnt(char *string, char testchar) { |
2326 | int count = 0 |
2326 | int count = 0; size_t i; // Pierre-Marie Baty -- fixed type |
2327 | 2327 | ||
2328 | for (i = 0; i < strlen(string); i++) |
2328 | for (i = 0; i < strlen(string); i++) |
2329 | if (string[i] == testchar) |
2329 | if (string[i] == testchar) |
2330 | count++; |
2330 | count++; |
2331 | return count; |
2331 | return count; |
Line 2528... | Line 2528... | ||
2528 | if (pGetNumaHighestNodeNumber && pGetNumaNodeProcessorMask && |
2528 | if (pGetNumaHighestNodeNumber && pGetNumaNodeProcessorMask && |
2529 | pGetNumaHighestNodeNumber(&ulNumaNodes) && (ulNumaNodes > 0)) { |
2529 | pGetNumaHighestNodeNumber(&ulNumaNodes) && (ulNumaNodes > 0)) { |
2530 | fSystemIsNUMA = TRUE; |
2530 | fSystemIsNUMA = TRUE; |
2531 | if (ulNumaNodes > 255) |
2531 | if (ulNumaNodes > 255) |
2532 | ulNumaNodes = 255; |
2532 | ulNumaNodes = 255; |
2533 | printf("System is NUMA. " PRId64 " nodes reported by Windows\n", |
2533 | printf("System is NUMA. %" PRId64 " nodes reported by Windows\n", // Pierre-Marie Baty -- fixed format string |
2534 |
|
2534 | (int64_t) (ulNumaNodes + 1)); // Pierre-Marie Baty -- added type cast |
2535 | for (ulNode = 0; ulNode <= ulNumaNodes; ulNode++) { |
2535 | for (ulNode = 0; ulNode <= ulNumaNodes; ulNode++) { |
2536 | pGetNumaNodeProcessorMask((UCHAR) ulNode, |
2536 | pGetNumaNodeProcessorMask((UCHAR) ulNode, |
2537 | &ullProcessorMask[ulNode]); |
2537 | &ullProcessorMask[ulNode]); |
2538 | printf("Node " PRId64 " CPUs: ", ulNode) |
2538 | printf("Node %" PRId64 " CPUs: ", (int64_t) ulNode); // Pierre-Marie Baty -- fixed format string + added type cast |
2539 | ullMask = ullProcessorMask[ulNode]; |
2539 | ullMask = ullProcessorMask[ulNode]; |
2540 | if (0 == ullMask) |
2540 | if (0 == ullMask) |
2541 | fSystemIsNUMA = FALSE; |
2541 | fSystemIsNUMA = FALSE; |
2542 | else { |
2542 | else { |
2543 | ulCPU = 0; |
2543 | ulCPU = 0; |
2544 | do { |
2544 | do { |
2545 | if (ullMask & 1) |
2545 | if (ullMask & 1) |
2546 | printf("" PRId64 " ", ulCPU) |
2546 | printf("%" PRId64 " ", (int64_t) ulCPU); // Pierre-Marie Baty -- fixed format string + added type cast |
2547 | ulCPU++; |
2547 | ulCPU++; |
2548 | ullMask >>= 1; |
2548 | ullMask >>= 1; |
2549 | } while (ullMask); |
2549 | } while (ullMask); |
2550 | } |
2550 | } |
2551 | printf("\n"); |
2551 | printf("\n"); |
Line 2553... | Line 2553... | ||
2553 | // Thread 0 was already started on some CPU. To simplify things further, |
2553 | // Thread 0 was already started on some CPU. To simplify things further, |
2554 | // exchange ProcessorMask[0] and ProcessorMask[node for that CPU], |
2554 | // exchange ProcessorMask[0] and ProcessorMask[node for that CPU], |
2555 | // so ProcessorMask[0] would always be node for thread 0 |
2555 | // so ProcessorMask[0] would always be node for thread 0 |
2556 | dwCPU = |
2556 | dwCPU = |
2557 | pSetThreadIdealProcessor(GetCurrentThread(), MAXIMUM_PROCESSORS); |
2557 | pSetThreadIdealProcessor(GetCurrentThread(), MAXIMUM_PROCESSORS); |
2558 | printf("Current ideal CPU is %llu\n", dwCPU) |
2558 | printf("Current ideal CPU is %llu\n", (long long unsigned) dwCPU); // Pierre-Marie Baty -- added type cast |
2559 | pSetThreadIdealProcessor(GetCurrentThread(), dwCPU); |
2559 | pSetThreadIdealProcessor(GetCurrentThread(), dwCPU); |
2560 | if ((((DWORD) - 1) != dwCPU) && (MAXIMUM_PROCESSORS != dwCPU) |
2560 | if ((((DWORD) - 1) != dwCPU) && (MAXIMUM_PROCESSORS != dwCPU) |
2561 | && !(ullProcessorMask[0] & ( |
2561 | && !(ullProcessorMask[0] & (1uLL << dwCPU))) { // Pierre-Marie Baty -- fixed type |
2562 | for (ulNode = 1; ulNode <= ulNumaNodes; ulNode++) { |
2562 | for (ulNode = 1; ulNode <= ulNumaNodes; ulNode++) { |
2563 | if (ullProcessorMask[ulNode] & ( |
2563 | if (ullProcessorMask[ulNode] & (1uLL << dwCPU)) { // Pierre-Marie Baty -- fixed type |
2564 | printf("Exchanging nodes 0 and " PRId64 "\n", ulNode) |
2564 | printf("Exchanging nodes 0 and %" PRId64 "\n", (int64_t) ulNode); // Pierre-Marie Baty -- fixed format string + added type cast |
2565 | ullMask = ullProcessorMask[ulNode]; |
2565 | ullMask = ullProcessorMask[ulNode]; |
2566 | ullProcessorMask[ulNode] = ullProcessorMask[0]; |
2566 | ullProcessorMask[ulNode] = ullProcessorMask[0]; |
2567 | ullProcessorMask[0] = ullMask; |
2567 | ullProcessorMask[0] = ullMask; |
2568 | break; |
2568 | break; |
2569 | } |
2569 | } |
Line 2586... | Line 2586... | ||
2586 | if (fSystemIsNUMA) { |
2586 | if (fSystemIsNUMA) { |
2587 | ulNumaNode++; |
2587 | ulNumaNode++; |
2588 | if (ulNumaNode > ulNumaNodes) |
2588 | if (ulNumaNode > ulNumaNodes) |
2589 | ulNumaNode = 0; |
2589 | ulNumaNode = 0; |
2590 | ullMask = ullProcessorMask[ulNumaNode]; |
2590 | ullMask = ullProcessorMask[ulNumaNode]; |
2591 | printf("Starting thread on node " PRId64 " CPU mask %I64d\n", ulNumaNode, |
2591 | printf("Starting thread on node %" PRId64 " CPU mask %I64d\n", (int64_t) ulNumaNode, // Pierre-Marie Baty -- fixed format string + added type cast |
2592 | ullMask); |
2592 | ullMask); |
2593 | SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) ullMask); |
2593 | SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) ullMask); |
2594 | hThread = (HANDLE) _beginthreadex(0, 0, func, args, CREATE_SUSPENDED, 0); |
2594 | hThread = (HANDLE) _beginthreadex(0, 0, func, args, CREATE_SUSPENDED, 0); |
2595 | SetThreadAffinityMask(hThread, (DWORD_PTR) ullMask); |
2595 | SetThreadAffinityMask(hThread, (DWORD_PTR) ullMask); |
2596 | ResumeThread(hThread); |
2596 | ResumeThread(hThread); |
2597 | SetThreadAffinityMask(GetCurrentThread(), |
2597 | SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) ullProcessorMask[0]); // Pierre-Marie Baty -- added type cast |
2598 | } else |
2598 | } else |
2599 | hThread = (HANDLE) _beginthreadex(0, 0, func, args, 0, 0); |
2599 | hThread = (HANDLE) _beginthreadex(0, 0, func, args, 0, 0); |
2600 | return hThread; |
2600 | return hThread; |
2601 | } |
2601 | } |
2602 | # endif |
2602 | # endif |
Line 2610... | Line 2610... | ||
2610 | 2610 | ||
2611 | WinNumaInit(); |
2611 | WinNumaInit(); |
2612 | if (fSystemIsNUMA) { |
2612 | if (fSystemIsNUMA) { |
2613 | ulNode = iThread % (ulNumaNodes + 1); |
2613 | ulNode = iThread % (ulNumaNodes + 1); |
2614 | hThread = GetCurrentThread(); |
2614 | hThread = GetCurrentThread(); |
2615 | dwAffinityMask = SetThreadAffinityMask(hThread, |
2615 | dwAffinityMask = SetThreadAffinityMask(hThread, (DWORD_PTR) ullProcessorMask[ulNode]); // Pierre-Marie Baty -- added type cast |
2616 | pBytes = VirtualAlloc(NULL, cbBytes, MEM_COMMIT, PAGE_READWRITE); |
2616 | pBytes = VirtualAlloc(NULL, cbBytes, MEM_COMMIT, PAGE_READWRITE); |
2617 | if (pBytes == NULL) |
2617 | if (pBytes == NULL) |
2618 | ExitProcess(GetLastError()); |
2618 | ExitProcess(GetLastError()); |
2619 | memset(pBytes, 0, cbBytes); |
2619 | memset(pBytes, 0, cbBytes); |
2620 | SetThreadAffinityMask(hThread, dwAffinityMask); |
2620 | SetThreadAffinityMask(hThread, dwAffinityMask); |
Line 2656... | Line 2656... | ||
2656 | dwStep = dwPageSize * cThreads; |
2656 | dwStep = dwPageSize * cThreads; |
2657 | pEnd = pBase + cbBytes; |
2657 | pEnd = pBase + cbBytes; |
2658 | for (iThread = 0; iThread < cThreads; iThread++) { |
2658 | for (iThread = 0; iThread < cThreads; iThread++) { |
2659 | ulNode = iThread % (ulNumaNodes + 1); |
2659 | ulNode = iThread % (ulNumaNodes + 1); |
2660 | dwAffinityMask = |
2660 | dwAffinityMask = |
2661 | SetThreadAffinityMask(hThread, |
2661 | SetThreadAffinityMask(hThread, (DWORD_PTR) ullProcessorMask[ulNode]); // Pierre-Marie Baty -- added type cast |
2662 | for (pch = pBase + iThread * dwPageSize; pch < pEnd; pch += dwStep) { |
2662 | for (pch = pBase + iThread * dwPageSize; pch < pEnd; pch += dwStep) { |
2663 | lpvResult = VirtualAlloc(pch, // next page to commit |
2663 | lpvResult = VirtualAlloc(pch, // next page to commit |
2664 | dwPageSize, // page size, in bytes |
2664 | dwPageSize, // page size, in bytes |
2665 | MEM_COMMIT, // allocate a committed page |
2665 | MEM_COMMIT, // allocate a committed page |
2666 | PAGE_READWRITE); // read/write access |
2666 | PAGE_READWRITE); // read/write access |