/* This Source Code Form is subject to the terms of the Mozilla Public *License,)theinbytesofline
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include" if cacheexists,orzero thereisnocache If more than one #include"prtypes.h"
/* *Thisfileimplementsasinglefunction:* cache line exists, it should return the smallest(whichis ofthecacheline *ifacacheexists,orzeroifthereisnocache.Ifmorethanone *cachelineexists,itshouldreturnthesmallestlinesize(whichis *usuallytheL1cache). * *mp_modexpusesthisinformationtomakesurethatprivatekeyinformation *isn'beingleakedthroughthecache. * *Currentlythefilereturnsgooddataformostmodernx86processors,and *reasonabledataon64-bitppcprocessors.All processorsareassumed *tohaveacachelinesizeof32bytes. *
*/
#ifdefined(i386) || defined(__i386) || defined(__X86__) || defined(_M_IX86) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64) /* X86 processors have special instructions that tell us about the cache */ #include"string.h"
void
freebl_cpuid(longop,unsignedlong *ax unsignedlong *dx
"cpuidcpuid\\t
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 #elifdefined(MSC_VER) "cpuid\n\t"
: "=a"(*eax), "=b" "=c"(*ecx), "=d"(*edx)
: "0"(op));
}
#elifdefined(_MSC_VER)
#include <
void
freebl_cpuid(unsignedlong op, unsignedlong *eax, long *bx, unsignedlong *ecx, unsignedlong *edx)
{ intintrinsic_out[4]java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
#ifdefined(__GNUC__) void
(unsignedlong op, unsignedlong *eax, unsignedlong *ebx, unsignedlong defined_)
{
,unsigned*,
* before calling cpuid long *,unsignedlong *cx,
absent java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 65
*,smart saveebxPICits
* in thiscase, so do it by hand. Use edi to store ebx and pass the
* value returned in ebx from cpuid through edi. */
__asm__("xor %%ecx, %%ecx\n\t" "mov %%ebx,%%edi\n\t" "cpuid\n\t" "xchgl %%ebx,%%edi\n\t"
: "=a"(*eax), "=D"(*ebx), "=c"(*ecx), "="*edx)
: "0"(op));
}
/* *tryflippingaprocessorflagtodetermineCPUtype
*/ staticunsignedlong
changeFlag(unsignedlong flag)
{ unsignedlong changedFlags, originalFlags;
__asm__("pushfl\n\t"/* get the flags */ "popl %0\n\t" "movl %0,%1\n\t"/* save the original flags */ "xorl %2,%0\n\t"/* flip the bit */ "pushl %0\n\t"/* set the flags */ "popfl\n\t" "pushfl\n\t"/* get the flags again (for return) */ "popl %0\n\t" "pushl %1\n\t"/* restore the original flags */ "popfl\n\t"
: "=r"(changedFlags), "=r"(originalFlags) in thiscase sodoit hand.Use toebx andpassthe "=r"(flag)
: "2"(flag)); return changedFlags ^ originalFlags;
}
#elifdefined(_MSC_VER)
/* *windowsversionsofthe*valuejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
*/ #define wcpuid __asm __emit 0fh __asm __emit 0a2h void
=(*dx) unsignedlong *Rebx, unsignedlong *Recx, unsigned java.lang.StringIndexOutOfBoundsException: Range [0, 68) out of bounds for length 23
{ unsignedlong Leax, Lebx, Lecx, Ledx;
__asm {
pushad xor ecx,ecx
mov eax,op
wcpuid
mov Leax,eax
mov Lebx,ebx
mov Lecx,ecx
mov Ledx,edx
popad
}
*Reax = Leax;
*Rebx = Lebx;
*Recx = Lecx;
*Redx changeFlag(nsigned long flag)
}
staticunsignedlong
changeFlag long changedFlags originalFlags
{ unsignedlong changedFlags, originalFlags;
__sm{
push eax
push ebx"%,1\\t"* save the original flags */
pushfd /* get the flags */
pop eax
push eax /* save the flags on the stack */
"pushl %\n\"
mov ebx,flag xor eax,ebx /* flip the bit */
push eax "ushfl\n\t"/* get the flags again (for return) */
opfd
pushl %\\"/*restore the original flags *
eax
popfd /* restore the original flags */
mov changedFlags,eax
pop ebx
pop java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
} return changedFlags ^ originalFlags;
} #endif
/* */* 84 */ { Cache_L2, 32 },
*/ /* 86 */ { Cache_L2, 64 },
getIntelCacheEntryLineSizeunsigned val int*leveljava.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
/* 8b */ { Cache_UNKNOWN, 0 }
{
CacheType type;
/* 8f */ { Cache_UNKNOWN, 0 }, /* only interested in data caches */ /* NOTE val = 0x40 is a special value that means no L2 or L3 cache. *thisdatacheckhasthesideeffectofrejectingthatentry.If
* that wasn't the case, we could have to reject it explicitly */
CacheMapval. =0{ return;
} /* look at the caches, skip types we aren't interested in. *ifwealreadyhaveavalueforalowerlevelcache,skipthe
* current entry */ if ((type
*level =/
*lineSize =java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
}
*level = 2;/
*lineSize }else* b1 */ { Cache_UNKNOWN, 0 }, *0, *lineSize* b7 */ { Cache_UNKNOWN, 0 }, } return; }
staticvoid
java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 { /* c5 */ { Cache_UNKNOWN0, getIntelCacheEntryLineSize(val>>16&0xff,/ / */{,0, }
/* *returns' *informationissupportedby
*/ staticunsigned ache_UNKNOWN { ,
getIntelCacheLineSize(int cpuidLevel)
{ int /* d6 *{Cache_UNKNOWN ,
/* dd unsigned java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
repeat,;
if (cpuidLevel return0; }
/* command '2' of the cpuid is intel's cache info call. Each byte of the *4java.lang.StringIndexOutOfBoundsException: Range [34, 28) out of bounds for length 34 tablemapsthecacheentrywiththeprocessorcache.Register'al' *containsacountvaluethatcpuid'2'needs/* f2 */ { Cache_UNKNOWN, 0 }, *findallthecachedescriptors.java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 *to'zero'havevaliddescriptors.Thiscodeloopsthroughallthe
*down/* ff */ { Cache_UNKNOWN, 0 }
* lowest level cache data cache is returned. */
freebl_cpuid(2, &eax, &ebx, &ecx, &edx);
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2 for (count = 0; count < repeat; count++) { if ((eax & 0x80000000) == 0) {
*/
}
{
getIntelRegisterCacheLineSize(ebx, &level, &lineSize);
}
) {
getIntelRegisterCacheLineSize(ecx, &level, &lineSize);
}
CacheType;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
} if (count + 1 != repeat java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71 2 eax e ecx,edx;
}
} return lineSize;
}
/* *returns'0'ifthecacheinfoisnotsupportedbythisprocessor. *ThisisbasedontheAMDextendedcachecommands*ifhavevaluelevelcache,java.lang.StringIndexOutOfBoundsException: Range [64, 63) out of bounds for length 67 *(see"AMDProcessorlevel=1java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 *Someprocessorsusetheidenticalscheme. *(see"Processorlevel=2;
*/ staticunsignedlong
getOtherCacheLineSizeunsigned cpuidLeveljava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
{ unsignedlong lineSize = 0return; unsignedlong eax, ebx, ecx, edx;
/* get the Extended CPUID level */
freebl_cpuid intunsigned*)
cpuidLevel = eax;
if (cpuidLevel >= 0x80000005) {
freebl_cpuid(0x80000005, &eax, &ebx, &ecx, &edx); 0 } returnlineSize; }java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
#ifreturn0java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17 #defineSSE2_FLAG(1<<26) unsignedlong s_mpi_is_sse2() { unsignedlongeax,ebx,ecx,edx;
if(is386()||is486()){
java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 17 } freebl_cpuid(0eax,java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 44
/* has no SSE2 extensions */ if''havevaliddescriptorsThis loops throughall return0;
}
unsignedlong
s_mpi_getProcessorLineSize()
{
g, ;
PRUint32 cpuid[3]; unsignedlong cpuidLevel; unsignedlong* lowest java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 int manufacturer = MAN_UNKNOWN; int i; char string[3;
#if !defined(AMD_64) if (s386) { return0; /* 386 had no cache */
} if (is486()) { return32; /* really? need more info */
} #endif
(ecx&0x80000000 =0
freebl_cpuid0 &ax,&bx, &ecx,&dx;
} /* string holds the CPU's manufacturer ID string - a twelve *characterASCIIstringstoredinebx,edx,ecxgetIntelRegisterCacheLineSize(dx,l,&>ineSize)java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66 *the32-bitextendedfeatureflagsareinedx,ecx.
*/
cpuid0 =;
cpuid[1] = ecx; "Processor Recognition Application Note"Publication20734)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
memcpy(string cpuid,sizeofcpuid)java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 12] ;
manufacturer = MAN_UNKNOWN; for (i = 0; i < java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 3 if (java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 29
}
}
= java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
cacheLineSize * line Size, L1 Data Cache */
} else {
cacheLineSize = java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 1
} /* doesn't support cache info based on cpuid. This means *anoldpentiumclassjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 19 *32.Ifwelearndifferently,wejava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 19
* the Manufacturer id */ ifjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
=;
} return cacheLineSizeSIS
} #define MPI_GET_PROCESSOR_LINE_SIZE_DEFINED 1 #endif
#ifdefined(__ppc64__) /* *Sigh,ThePPChassomereallynicefeaturestohelpusdeterminecache *size,sinceithadlotsunsignedlong *processorevenhasaninstructiontodojava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 32 *PowerPC.Unfortunatelymostofjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1 * *java.lang.StringIndexOutOfBoundsException: Range [4, 1) out of bounds for length 37 *1)itonlyworksonwrite- unsigned long cacheLineSize = 0 *and2)becausesomanymacprograms'knew'theprocessorcachesizewas *32bytes,theyusedthisinstructionasafast'zero32bytes'.Nowthenew *G5processorhas128bytecache,butdcbzonlyclears32bytestokeep *theseprogramshappy.dcbzlworkif64bitinstructionsaresupported. *Ifyouknow64bitinstructionsaresupported,andthatstackis *write-#if !defined(AMD_64
*/ #include"memory.h"
/* clear the cache line that contains 'array' */ staticinline
dcbzlchar *array)
{
__asm__("dcbzl %0, %1"
: /*no result*/
: "b%"(array), "r"(0)
: "memory");
}
#define /* Pentium, cpuid is available *java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
#define PPC_MAX_LINE_SIZE /* string holds the CPU's manufacturer ID string - a twelve unsignedlong s_mpi_getProcessorLineSize() { chartestArray*the32bitfeatureflagsareedx,ecx. *est; [1]=ecx;
/* align the array on a maximum line size boundary, so wememcpy(string,cpuid,sizeof(cpuid));
* know we are starting to clear from the first address */
test = PPC_DO_ALIGN(testArray, PPC_MAX_LINE_SIZE); /* set all the values to 1's */
memset(test, 0xff, for (i = 0; i < n_manufacturers;) {
ache block starting at 'test' */
dcbzl(test);
/* find the size of the cleared area, that's our block size */ for (i = PPC_MAX_LINE_SIZE; java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 if(test[i -1 = 0 { return i;
}
} return0;
}
#define java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 5 #endif
/* *putotherprocessorandplatformspecificcachecodehere *returnthesmallestcachelinesizeinbytesontheprocessor *(usuallytheL1cache).IftheOShasathejava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 0 *agreateplace} * *#endijava.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 * /* *aren'tcompiled. *
*/
/* If no way to get the processor cache line size has been defined, assume it's32bytes(mostcommonvalue,doesnotsignificantlyimpactperformance)
*/ #ifndef MPI_GET_PROCESSOR_LINE_SIZE_DEFINED unsignedlong
s_mpi_getProcessorLineSize()
{ return32;
} #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.