SSE42 & STTNI - PcmpEstrM é duas vezes mais lento que PcmpIstrM, é verdade?
Estou experimentando as instruções SSE42 e STTNI e obtive um resultado estranho -PcmpEstrM (funciona com cadeias de comprimento explícitas) é executadoduas vezes mais lento que PcmpIstrM (cadeias de comprimento implícitas).
No meui7 3610QM a diferença é2366,2 ms vs. 1202,3 ms - 97%.Emi5 3470 diferença não é tão grande, mas ainda é significativa =3206,2 ms vs. 2623,2 ms - 22%.Ambos são "Ivy Bridge" - é estranho que tenham uma "diferença" tão diferente (pelo menos não vejo diferenças técnicas em suas especificações -http://www.cpu-world.com/Compare_CPUs/Intel_AW8063801013511,Intel_CM8063701093302/)
O Manual de referência da otimização de arquiteturas Intel 64 e IA-32 menciona a mesma taxa de transferência = 11 e latência = 3 para PcmpEstrM e PcmpIstrM. Portanto, espero um desempenho semelhante para ambos.
Q: A diferença que eu praticamente projetei / esperava ou estou usando essas instruções de maneira errada?
Abaixo está o meu cenário de teste fictício (VS 2012). A lógica é bastante simples - digitalize 16 MB de texto para encontrar caracteres correspondentes. Como nenhuma pilha de palheiro e agulha contém zero terminadores - espero que E e I tenham desempenho semelhante.
PS: Tentei postar esta pergunta emfórum de desenvolvimento da intel, mas eles o identificam como spam :(
#include "stdafx.h"
#include <windows.h>
#define BEGIN_TIMER(NAME) \
{ \
LARGE_INTEGER __freq; \
LARGE_INTEGER __t0; \
LARGE_INTEGER __t1; \
double __tms; \
const char* __tname = NAME; \
char __tbuf[0xff]; \
\
QueryPerformanceFrequency(&__freq); \
QueryPerformanceCounter(&__t0);
#define END_TIMER() \
QueryPerformanceCounter(&__t1); \
__tms = (__t1.QuadPart - __t0.QuadPart) * 1000.0 / __freq.QuadPart; \
sprintf_s(__tbuf, sizeof(__tbuf), "%-32s = %6.1f ms\n", __tname, __tms ); \
OutputDebugStringA(__tbuf); \
printf(__tbuf); \
}
// 4.1.3 Aggregation Operation
#define SSE42_AGGOP_BITBASE 2
#define SSE42_AGGOP_EQUAL_ANY (00b << SSE42_AGGOP_BITBASE)
#define SSE42_AGGOP_RANGES (01b << SSE42_AGGOP_BITBASE)
#define SSE42_AGGOP_EQUAL_EACH (10b << SSE42_AGGOP_BITBASE)
#define SSE42_AGGOP_EQUAL_ORDERED (11b << SSE42_AGGOP_BITBASE)
int _tmain(int argc, _TCHAR* argv[])
{
int cIterations = 1000000;
int cCycles = 1000;
int cchData = 16 * cIterations;
char* testdata = new char[cchData + 16];
memset(testdata, '*', cchData);
testdata[cchData - 1] = '+';
testdata[cchData] = '\0';
BEGIN_TIMER("PcmpIstrI") {
for( int i = 0; i < cCycles; i++ ) {
__asm {
push ecx
push edx
push ebx
mov edi, testdata
mov ebx, cIterations
mov al, '+'
mov ah, al
movd xmm1, eax // fill low word with pattern
pshuflw xmm1, xmm1, 0 // fill low dqword with pattern
movlhps xmm1, xmm1 // ... and copy it hi dqword
loop_pcmpistri:
PcmpIstrM xmm1, [edi], SSE42_AGGOP_EQUAL_EACH
add edi, 16
sub ebx, 1
jnz loop_pcmpistri
pop ebx
pop edx
pop ecx
}
}
} END_TIMER();
BEGIN_TIMER("PcmpEstrI") {
for( int i = 0; i < cCycles; i++ ) {
__asm {
push ecx
push edx
push ebx
mov edi, testdata
mov ebx, cIterations
mov al, '+'
mov ah, al
movd xmm1, eax // fill low word with pattern
pshuflw xmm1, xmm1, 0 // fill low dqword with pattern
movlhps xmm1, xmm1 // ... and copy it hi dqword
mov eax, 15
mov edx, 15
loop_pcmpestri:
PcmpEstrM xmm1, [edi], SSE42_AGGOP_EQUAL_EACH
add edi, 16
sub ebx, 1
jnz loop_pcmpestri
pop ebx
pop edx
pop ecx
}
}
} END_TIMER();
return 0;
}