This is based on code by Jeffrey Yasskin. It has been modified to compile with MSVC and reformated to LLVM style. llvm-svn: 172512