What is VirtualDub?
VirtualDub is a video capture/processing utility for 32-bit Windows platforms (95/98/ME/NT4/2000/XP), licensed under the GNU General Public License (GPL). It lacks the editing power of a general-purpose editor such as Adobe Premiere, but is streamlined for fast linear operations over video. It has batch-processing capabilities for processing large numbers of files and can be extended with third-party video filters. VirtualDub is mainly geared toward processing AVI files, although it can read (not write) MPEG-1 and also handle sets of BMP images.
I basically started VirtualDub in college to do some quick capture-and-encoding that I wanted done; from there it's basically grown into a more general utility that can trim and clean up video before exporting to tape or processing with another program. I released it on the web and others found it useful, so I've been tinkering around with its code ever since. If you have the time, please download and enjoy.
§ ¶Good approximation, bad approximation
Numerical approximations are a bit of an art. There are frequently tradeoffs available between speed and accuracy, and knowing how much you can skimp on one to improve the other takes a lot of careful study.
Take the humble reciprocal operation, for instance.
The reciprocal, y = 1/x, is a fairly basic operation, but it's also an expensive one. It can easily be implemented in terms of a divide, but division is itself a very expensive operation — it can't be parallelized as easily as addition or multiplication and typically takes on the order of 10-20 times longer. There are algorithms to compute the reciprocal directly to varying levels of precision, and some CPUs provide acceleration for that. x86 CPUs are among them, providing the RCPSS and RCPPS opcodes to compute scalar and vectorized reciprocal approximations, respectively.
However, there is a gotcha.
For any approximation, the first question you should ask is how accurate it is. RCPSS and RCPPS are documented as having a relative error no greater than 1.5*2^-12, or approximately 12 bits of precision. That's fine, and good enough for a lot of purposes, especially with refinement. The second question you should ask is whether there are any special values involved that deserve special attention. I can think of five that ideally should be exact:
RCPSS/RCPPS do handle zero and infinity correctly, which is good. Sadly, 1.0 is handled less gracefully, as it comes out as 0.999756 (3F7FF000), at least on Core 2 CPUs. Even worse, if you attempt to refine the result using Newton-Raphson iterations:
x' = x * (2 - x*c)
...the result converges to 0.99999994039535522 (3F7FFFFF), a value just barely off from 1.0 that in many cases it will be printed as 1.0, such as in the VC++ debugger. This leads to lots of fun tracking down why calculations are slewing away from unity when they shouldn't, only to discover that the innocuous little 1.0 in the corner is actually an impostor, and then having to slow down an otherwise speedy routine to handle this special case. Argh!
If I had to take a guess as to why Intel did this, it's probably to avoid the need to propagate carries from the mantissa to the exponent, because otherwise the top 12 bits of the mantissa can go through a lookup table and the exponent can produce the result exponent and top bit of new mantissa. It's still really annoying, though. I have to go fix the rcp instruction in my shader engine, for instance, because the DirectX docs explicitly require that rcp of 1.0 stays 1.0. Curiously, they don't mention -1.0. I guess it just goes to show how hard it is to specify a good approximation.
(Read more....)
§ ¶VS2010 CTP, first impressions
I downloaded and tried out the Visual Studio 2010 CTP a couple of days ago. My experience from the VS2005 and VS2008 betas is that there's a narrow window in time where you can actually get anything fixed, since the CTPs are already released so late in the cycle and a project like Visual Studio has a ton of inertia. The new mantra for VS2010 is apparently "10 is the new 6," which is a reference to the fact that a lot of people still consider Visual C++ 6.0 to be superior to the subsequent releases, including me.
How is it, then?
VS2010 CTP comes as a rather large virtual hard drive (VHD) for Virtual PC 2007 SP1, approximately 26GB. This is because it includes a full Windows Server 2008 evaluation installation as well as a full VS2010 Team Edition CTP install. I ran it on a laptop with 2GB of memory and gave the VM 1GB, which I thought would be sufficient just to try it out. Oh no. The VM absolutely crawled, even before I launched VS2010. I ended up having to disable a bunch of unnecessary services, most notably SQL Server, just to stop the swap death. That got the memory usage of the system down by about 200-300MB, which helped things considerably. It's safe to say, though, that any performance conclusions drawn from this CTP should be taken with a grain of salt... or perhaps a salt lick.
(Read more....)