Script C++

elhajjajireda Messages postés 34 Date d'inscription mercredi 3 juin 2009 Statut Membre Dernière intervention 20 juin 2011 - 15 avril 2011 à 22:16
cs_patatalo Messages postés 1466 Date d'inscription vendredi 2 janvier 2004 Statut Modérateur Dernière intervention 14 février 2014 - 16 avril 2011 à 16:26
Bonjour
si le vous plait est ce qu'il y a quelqu'un qui peut m'aider à comprendre ce code et surtout celui de la fonction MCheckCpu() et MCpuid()



#include "MUtils.h"

//~ static int WithMmxSseUse= 0;

using namespace std;

namespace local_vis_eric
{
void Memms() { // ==> should be done after MMX and before FPU calculations <==
#ifdef ARCH_X86
emms();
#endif
}


int MExists(const char* FileName) {
FILE* File;
if ((File=fopen(FileName,"r"))== NULL) return 0;
fclose(File);
return 1;
}
const char* MExistingFileName(const char* PrefixSuffix, int Number) {
static char FileName[1024];
if (PrefixSuffix== NULL || !strlen(PrefixSuffix))
return NULL;
int i, iMax= strlen(PrefixSuffix);
for (i=0; i< iMax; i++)
if (PrefixSuffix[i]=='*')
break;
if (i== iMax)
return NULL;
sprintf(FileName,"%s", PrefixSuffix);
sprintf(FileName+i,"%d%s", int(Number), PrefixSuffix+i+1);
if (MExists(FileName)) return FileName;
sprintf(FileName+i,"0%d%s", int(Number), PrefixSuffix+i+1);
if (MExists(FileName)) return FileName;
sprintf(FileName+i,"00%d%s", int(Number), PrefixSuffix+i+1);
if (MExists(FileName)) return FileName;
sprintf(FileName+i,"000%d%s", int(Number), PrefixSuffix+i+1);
if (MExists(FileName)) return FileName;
sprintf(FileName+i,"0000%d%s", int(Number), PrefixSuffix+i+1);
if (MExists(FileName)) return FileName;
return NULL;
}


#include <sys/time.h>

double MTime() {
//struct timeval tv;
//gettimeofday(&tv, (struct timezone *)NULL);
return 0.0;
}

double MTime2()
{
//struct tms buffer;
//(void) times(&buffer);
//double NbClkTck=sysconf(_SC_CLK_TCK);
return 0.0;
}





int MCpuid() { // This function is from the GNU mpeg2dec source.
// Copyright (C) 1999-2001 Aaron Holtzman
#ifdef ARCH_X86
uint32_t eax, ebx, ecx, edx;
int AMD;
uint32_t caps;

#define cpuid(op,eax,ebx,ecx,edx) \
asm ("cpuid" \
: "=a" (eax), \
"=b" (ebx), \
"=c" (ecx), \
"=d" (edx) \
: "a" (op) \
: "cc")

asm ("pushfl\n\t"
"popl %0\n\t"
"movl %0,%1\n\t"
"xorl $0x200000,%0\n\t"
"pushl %0\n\t"
"popfl\n\t"
"pushfl\n\t"
"popl %0"
: "=a" (eax),
"=b" (ebx)
:
: "cc");

if (eax == ebx) /* no cpuid */
return 0;
cpuid (0x0000int MCpuid() { // This function is from the GNU mpeg2dec source.
// Copyright (C) 1999-2001 Aaron Holtzman
#ifdef ARCH_X86
uint32_t eax, ebx, ecx, edx;
int AMD;
uint32_t caps;

#define cpuid(op,eax,ebx,ecx,edx) \
asm ("cpuid" \
: "=a" (eax), \
"=b" (ebx), \
"=c" (ecx), \
"=d" (edx) \
: "a" (op) \
: "cc")

asm ("pushfl\n\t"
"popl %0\n\t"
"movl %0,%1\n\t"
"xorl $0x200000,%0\n\t"
"pushl %0\n\t"
"popfl\n\t"
"pushfl\n\t"
"popl %0"
: "=a" (eax),
"=b" (ebx)
:
: "cc");

if (eax == ebx) /* no cpuid */
return 0;
cpuid (0x00000000, eax, ebx, ecx, edx);
if (!eax) /* vendor string only */
return 0;
AMD (ebx 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
cpuid (0x00000001, eax, ebx, ecx, edx);
if (! (edx & 0x00800000)) /* no MMX */
return 0;
caps = M_MM_ACCEL_X86_MMX;
if (edx & 0x02000000) /* SSE - identical to AMD MMX extensions */
caps = M_MM_ACCEL_X86_MMX | M_MM_ACCEL_X86_MMXEXT;
cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001) /* no extended capabilities */
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & 0x80000000)
caps |= M_MM_ACCEL_X86_3DNOW;
if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
caps |= M_MM_ACCEL_X86_MMXEXT;
return caps;
#endif
return 0;
};

void MCheckCpu() {
assert(sizeof(char)== 1);
assert(sizeof(short)== 2);
assert(sizeof(int)== 4);
assert(sizeof*/00000, eax, ebx, ecx, edx);
if (eax < 0x80000001) /* no extended capabilities */
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & 0x80000000)
caps |= M_MM_ACCEL_X86_3DNOW;
if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
caps |= M_MM_ACCEL_X86_MMXEXT;
return caps;
#endif
return 0;
};

void MCheckCpu() {
assert(sizeof(char)== 1);
assert(sizeof(short)== 2);
assert(sizeof(int)== 4);
assert(sizeof(float)== 4);
assert(sizeof(double)== 8);
assert(sizeof(long long)== 8);
assert((MCpuid()&(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT))==
(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT));
(float)== 4);
assert(sizeof(double)== 8);
assert(sizeof(long long)== 8);
assert((MCpuid()&(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT))==
(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT));
0000, eax, ebx, ecx, edx);
if (!eax) /* vendor string only */
return 0;
AMD (ebx 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
cpuid (0x00000001, eax, ebx, ecx, edx);
if (! (edx & 0x00800000)) /* no MMX */
return 0;
caps = M_MM_ACCEL_X86_MMX;
if (edx & 0x02000000) /* SSE - identical to AMD MMX extensions */
caps = M_MM_ACCEL_X86_MMX | M_MM_ACCEL_X86_MMXEXT;
cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001) /* no extended capabilities */
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & 0x80000000)
caps |= M_MM_ACCEL_X86_3DNOW;
if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
caps |= M_MM_ACCEL_X86_MMXEXT;
return caps;
#endif
return 0;
};

void MCheckCpu() {
assert(sizeof(char)== 1);
assert(sizeof(short)== 2);
assert(sizeof(int)== 4);
assert(sizeof(float)== 4);
assert(sizeof(double)== 8);
assert(sizeof(long long)== 8);
assert((MCpuid()&(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT))==
(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT));

return 0;
caps = M_MM_ACCEL_X86_MMX;
if (edx & 0x02000000) /* SSE - identical to AMD MMX extensions */
caps = M_MM_ACCEL_X86_MMX | M_MM_ACCEL_X86_MMXEXT;
cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001) /* no extended capabilities */
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & 0x80000000)
caps |= M_MM_ACCEL_X86_3DNOW;
if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
caps |= M_MM_ACCEL_X86_MMXEXT;
return caps;
#endif
return 0;
};

void MCheckCpu() {
assert(sizeof(char)== 1);
assert(sizeof(short)== 2);
assert(sizeof(int)== 4);
assert(sizeof(float)== 4);
assert(sizeof(double)== 8);
assert(sizeof(long long)== 8);
assert((MCpuid()&(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT))==
(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT));
0000, eax, ebx, ecx, edx);
if (!eax) /* vendor string only */
return 0;
AMD (ebx 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
cpuid (0x00000001, eax, ebx, ecx, edx);
if (! (edx & 0x00800000)) /* no MMX */
return 0;
caps = M_MM_ACCEL_X86_MMX;
if (edx & 0x02000000) /* SSE - identical to AMD MMX extensions */
caps = M_MM_ACCEL_X86_MMX | M_MM_ACCEL_X86_MMXEXT;
cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001) /* no extended capabilities */
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & 0x80000000)
caps |= M_MM_ACCEL_X86_3DNOW;
if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
caps |= M_MM_ACCEL_X86_MMXEXT;
return caps;
#endif
return 0;
};

void MCheckCpu() {
assert(sizeof(char)== 1);
assert(sizeof(short)== 2);
assert(sizeof(int)== 4);
assert(sizeof(float)== 4);
assert(sizeof(double)== 8);
assert(sizeof(long long)== 8);
assert((MCpuid()&(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT))==
(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT));
(float)== 4);
assert(sizeof(double)== 8);
assert(sizeof(long long)== 8);
assert((MCpuid()&(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT))==
(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT));
0000, eax, ebx, ecx, edx);
if (!eax) /* vendor string only */
return 0;
AMD (ebx 0x68747541) && (ecx == 0x444d4163) && (edx == 0x69746e65);
cpuid (0x00000001, eax, ebx, ecx, edx);
if (! (edx & 0x00800000)) /* no MMX */
return 0;
caps = M_MM_ACCEL_X86_MMX;
if (edx & 0x02000000) /* SSE - identical to AMD MMX extensions */
caps = M_MM_ACCEL_X86_MMX | M_MM_ACCEL_X86_MMXEXT;
cpuid (0x80000000, eax, ebx, ecx, edx);
if (eax < 0x80000001) /* no extended capabilities */
return caps;
cpuid (0x80000001, eax, ebx, ecx, edx);
if (edx & 0x80000000)
caps |= M_MM_ACCEL_X86_3DNOW;
if (AMD && (edx & 0x00400000)) /* AMD MMX extensions */
caps |= M_MM_ACCEL_X86_MMXEXT;
return caps;
#endif
return 0;
};

void MCheckCpu() {
assert(sizeof(char)== 1);
assert(sizeof(short)== 2);
assert(sizeof(int)== 4);
assert(sizeof(float)== 4);
assert(sizeof(double)== 8);
assert(sizeof(long long)== 8);
assert((MCpuid()&(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT))==
(M_MM_ACCEL_X86_MMX|M_MM_ACCEL_X86_MMXEXT));
//assert(sseUse==2);
//~ WithMmxSseUse= 1;
}
//~ int MWithMmxSseUse() {return WithMmxSseUse; };
int MWithMmxSseUse() {return sseUse; };
//~ void MSetWithMmxSseUse(int w) { std::cout << " Settings SSE " << w << std::endl;WithMmxSseUse=w;}

}

1 réponse

cs_patatalo Messages postés 1466 Date d'inscription vendredi 2 janvier 2004 Statut Modérateur Dernière intervention 14 février 2014 2
16 avril 2011 à 16:26
salut,

CptPingu a vu juste sur cppfrance.

Sous cette forme, c'est trop imbuvable pour être détaillé:
des #endif sans #if préàlables, des utilisation eax,ebx, ... qui ne sont pas déclarées:

void MCheckCpu() {
assert(sizeof(char)== 1);
assert(sizeof(short)== 2);
assert(sizeof(int)== 4);
assert(sizeof*/00000, eax, ebx, ecx, edx); // mais où va-t-il cherhcher tout ça...

des recopies sauvages:

cpuid (0x0000int MCpuid() { // This function is from the GNU mpeg2dec source.
// Copyright (C) 1999-2001 Aaron Holtzman
#ifdef ARCH_X86
uint32_t eax, ebx, ecx, edx;
int AMD;
uint32_t caps;

Eh non, il n'y a pas marqué La Poste...
@++
0
Rejoignez-nous