Original Post
Hey yall, I was wondering how would I go about optimizing my apps with things like MMX, 3Dnow!, and SSE? And another thing, how do I use ASM files in my visual studio projects?
bool mmxSupported = true;try { __asm { pxor mm0, mm0 emms }catch(...){ mmxSupported = false;}Quote:
You can find it out by trying to run SSE/SSE2/MMX/3DNOW! operations and just catching exceptions
// CPU caps (128 bits)// do not change the order!enum CpuCap{ // standard (ecx) - currently only defined by Intel SSE3 = 0+0, // Streaming SIMD Extensions 3 EST = 0+7, // Enhanced Speedstep Technology // standard (edx) TSC = 32+4, // TimeStamp Counter CMOV = 32+15, // Conditional MOVe MMX = 32+23, // MultiMedia eXtensions SSE = 32+25, // Streaming SIMD Extensions SSE2 = 32+26, // Streaming SIMD Extensions 2 HT = 32+28, // HyperThreading // extended (ecx) // extended (edx) - currently only defined by AMD AMD_MP = 96+19, // MultiProcessing capable; reserved on AMD64 AMD_3DNOW_PRO = 96+30, AMD_3DNOW = 96+31};bool ia32_cap(CpuCap cap){ // treated as 128 bit field; order: std ecx, std edx, ext ecx, ext edx // keep in sync with enum CpuCap! static u32 caps[4]; ONCE( u32 regs[4]; if(ia32_cpuid(1, regs)) { caps[0] = regs[ECX]; caps[1] = regs[EDX]; } if(ia32_cpuid(0x80000001, regs)) { caps[2] = regs[ECX]; caps[3] = regs[EDX]; } ); const uint tbl_idx = cap >> 5; const uint bit_idx = cap & 0x1f; if(tbl_idx > 3) { debug_warn("cap invalid"); return false; } return (caps[tbl_idx] & BIT(bit_idx)) != 0;} // usage example (at init-time): u32 (*ConvertRGBColorTo4ub)(const RGBColor& src); if(ia32_cap(SSE)) ConvertRGBColorTo4ub = sse_ConvertRGBColorTo4ub; else debug_printf("No SSE available. Slow fallback routines will be used.\n"); // after that, just call through the function pointer.Quote:
how do I use ASM files in my visual studio projects?
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more