Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: nss/lib/freebl/mpi/mpcpucache.c

Issue 1504923011: Update NSS to 3.21 RTM and NSPR to 4.11 RTM (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/nss
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 #include "mpi.h" 5 #include "mpi.h"
6 #include "prtypes.h"
6 7
7 /* 8 /*
8 * This file implements a single function: s_mpi_getProcessorLineSize(); 9 * This file implements a single function: s_mpi_getProcessorLineSize();
9 * s_mpi_getProcessorLineSize() returns the size in bytes of the cache line 10 * s_mpi_getProcessorLineSize() returns the size in bytes of the cache line
10 * if a cache exists, or zero if there is no cache. If more than one 11 * if a cache exists, or zero if there is no cache. If more than one
11 * cache line exists, it should return the smallest line size (which is 12 * cache line exists, it should return the smallest line size (which is
12 * usually the L1 cache). 13 * usually the L1 cache).
13 * 14 *
14 * mp_modexp uses this information to make sure that private key information 15 * mp_modexp uses this information to make sure that private key information
15 * isn't being leaked through the cache. 16 * isn't being leaked through the cache.
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 613
613 614
614 #define MAN_UNKNOWN 9 615 #define MAN_UNKNOWN 9
615 616
616 #if !defined(AMD_64) 617 #if !defined(AMD_64)
617 #define SSE2_FLAG (1<<26) 618 #define SSE2_FLAG (1<<26)
618 unsigned long 619 unsigned long
619 s_mpi_is_sse2() 620 s_mpi_is_sse2()
620 { 621 {
621 unsigned long eax, ebx, ecx, edx; 622 unsigned long eax, ebx, ecx, edx;
622 int manufacturer = MAN_UNKNOWN;
623 int i;
624 char string[13];
625 623
626 if (is386() || is486()) { 624 if (is386() || is486()) {
627 return 0; 625 return 0;
628 } 626 }
629 freebl_cpuid(0, &eax, &ebx, &ecx, &edx); 627 freebl_cpuid(0, &eax, &ebx, &ecx, &edx);
630 /* string holds the CPU's manufacturer ID string - a twelve
631 * character ASCII string stored in ebx, edx, ecx, and
632 * the 32-bit extended feature flags are in edx, ecx.
633 */
634 *(int *)string = ebx;
635 *(int *)&string[4] = (int)edx;
636 *(int *)&string[8] = (int)ecx;
637 string[12] = 0;
638 628
639 /* has no SSE2 extensions */ 629 /* has no SSE2 extensions */
640 if (eax == 0) { 630 if (eax == 0) {
641 return 0; 631 return 0;
642 } 632 }
643 633
644 for (i=0; i < n_manufacturers; i++) {
645 if ( strcmp(manMap[i],string) == 0) {
646 manufacturer = i;
647 break;
648 }
649 }
650
651 freebl_cpuid(1,&eax,&ebx,&ecx,&edx); 634 freebl_cpuid(1,&eax,&ebx,&ecx,&edx);
652 return (edx & SSE2_FLAG) == SSE2_FLAG; 635 return (edx & SSE2_FLAG) == SSE2_FLAG;
653 } 636 }
654 #endif 637 #endif
655 638
656 unsigned long 639 unsigned long
657 s_mpi_getProcessorLineSize() 640 s_mpi_getProcessorLineSize()
658 { 641 {
659 unsigned long eax, ebx, ecx, edx; 642 unsigned long eax, ebx, ecx, edx;
643 PRUint32 cpuid[3];
660 unsigned long cpuidLevel; 644 unsigned long cpuidLevel;
661 unsigned long cacheLineSize = 0; 645 unsigned long cacheLineSize = 0;
662 int manufacturer = MAN_UNKNOWN; 646 int manufacturer = MAN_UNKNOWN;
663 int i; 647 int i;
664 char string[65]; 648 char string[13];
665 649
666 #if !defined(AMD_64) 650 #if !defined(AMD_64)
667 if (is386()) { 651 if (is386()) {
668 return 0; /* 386 had no cache */ 652 return 0; /* 386 had no cache */
669 } if (is486()) { 653 } if (is486()) {
670 return 32; /* really? need more info */ 654 return 32; /* really? need more info */
671 } 655 }
672 #endif 656 #endif
673 657
674 /* Pentium, cpuid command is available */ 658 /* Pentium, cpuid command is available */
675 freebl_cpuid(0, &eax, &ebx, &ecx, &edx); 659 freebl_cpuid(0, &eax, &ebx, &ecx, &edx);
676 cpuidLevel = eax; 660 cpuidLevel = eax;
677 /* string holds the CPU's manufacturer ID string - a twelve 661 /* string holds the CPU's manufacturer ID string - a twelve
678 * character ASCII string stored in ebx, edx, ecx, and 662 * character ASCII string stored in ebx, edx, ecx, and
679 * the 32-bit extended feature flags are in edx, ecx. 663 * the 32-bit extended feature flags are in edx, ecx.
680 */ 664 */
681 *(int *)string = ebx; 665 cpuid[0] = ebx;
682 *(int *)&string[4] = (int)edx; 666 cpuid[1] = ecx;
683 *(int *)&string[8] = (int)ecx; 667 cpuid[2] = edx;
668 memcpy(string, cpuid, sizeof(cpuid));
684 string[12] = 0; 669 string[12] = 0;
685 670
686 manufacturer = MAN_UNKNOWN; 671 manufacturer = MAN_UNKNOWN;
687 for (i=0; i < n_manufacturers; i++) { 672 for (i=0; i < n_manufacturers; i++) {
688 if ( strcmp(manMap[i],string) == 0) { 673 if ( strcmp(manMap[i],string) == 0) {
689 manufacturer = i; 674 manufacturer = i;
690 } 675 }
691 } 676 }
692 677
693 if (manufacturer == INTEL) { 678 if (manufacturer == INTEL) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 #endif 789 #endif
805 790
806 #ifdef TEST_IT 791 #ifdef TEST_IT
807 #include <stdio.h> 792 #include <stdio.h>
808 793
809 main() 794 main()
810 { 795 {
811 printf("line size = %d\n", s_mpi_getProcessorLineSize()); 796 printf("line size = %d\n", s_mpi_getProcessorLineSize());
812 } 797 }
813 #endif 798 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698