general_cpuextensions - shekh/VirtualDub2 GitHub Wiki

VirtualDub Plugin SDK 1.2

Using CPU instruction set extensions

Vector instruction sets can greatly accelerate plugin operations, particularly video decoding, and it is worthwhile to use them whenever possible. Unfortunately, all vector instructions are part of instruction set extensions in the IA-32 instruction set architecture (ISA), and thus are not always available, depending on the CPU. Attempting to use an instruction set that is not available results in a crash and is very sloppy, so it is required that plugins check for CPU instruction set extensions before using them.

Checking for instruction set extensions

The 32-bit plugin API only guarantees an 80486 CPU, so the only optional instructions that are guaranteed are XADD and CMPXCHG; none of the vector instruction sets, such as MMX or SSE, are guaranteed. Therefore, before using any of those instruction sets, the plugin should call the GetCPUFeatureFlags() method first, and fall back gracefully or fail if instruction set support is missing.

On a 64-bit (X64) system, the minimum feature set supported by the ISA is considerably higher. Plugins can assume that the MMX, SSE, and SSE2 instruction set extensions are always available. Support for 3DNow! cannot be assumed, as it is not available on all X64-capable processors.

You don't have to use the CPU detection offered by the host — you can use your own detection instead. This can be handy if your compiler offers code generation that can take advantage of instruction set extensions. However, this does mean that users cannot easily override the detection through the host's user interface if something goes wrong with the CPU detection.

Using instruction set extensions

As some instruction set extensions conflict, care must be used when using such extensions. In particular, any plugins that use MMX must always ensure that the MMX state is cleared with an EMMS or FEMMS instruction prior to returning to the operating system or to the host in order to avoid corrupting floating point (x87) calculations. It is guaranteed that the host will do the same before calling into plugins. This is required by the cdecl and stdcall calling conventions.

While this is not required or guaranteed by the API, VirtualDub guards all control transfers in and out of plugins against MMX state mistakes. It ensures that bad MMX state never leaks in or out of a plugin, and will display warnings if it has detected a plugin leaking MMX state.

Overriding VirtualDub's CPU detection

Invoking VirtualDub with the /safecpu command line switch causes it to disable use of all enhanced instruction sets, and to report none available to all plugins. CPU feature detection can also be disabled or overridden in Options, Preferences, CPU.


Copyright (C) 2007-2012 Avery Lee.

⚠️ **GitHub.com Fallback** ⚠️