Xiph needs someone to help with assembly for MSVC! 2007-10-03

Hello again! Theora, the open video format from the makers of Ogg Vorbis and other great open media formats, is in need for someone with solid understanding of x86 inline assembler in MSVC syntax. At Xiph we have people fluent with GCC-style assembly, people familiar with Windows and Visual Studio, but we don’t have anybody who can write x86 assembly compilable with Visual Studio. Yes, assembly for one and the same processor can look very different from compiler to compiler. These two lines are equivalents from both worlds:

GCC syntax: “add $16, %2\n\t”
MSVC syntax: add ecx, 16

Semantics are mostly the same but even the argument order differs.
So while we do have assembly code compiling with GCC, an equivalent for MSVC is missing. In general there are several possible ways to solve this code-twice problem:

  1. Code everything twice, sync manually
  2. Code in one syntax, generate the other using a tool
  3. Add an abstraction layer that resolves to either syntax

Approach (1) obviously has big drawbacks like waste of time and error-proneness – it’s a maintanance hell. We created base code for both (2) and (3) that proved to work for the tested (simple) subset of assembly commands. While (2) was done using a sed-based shell-script, (3) was implemented using preprocessor-macros, e.g. instead of

“add $16, %2\n\t”

we could now write

TIS_CMD(add, TIS_NUM(16), TIS_ECX)

and get the MSVC syntax as a “fall-out”. The reason we currently cannot finish either approaches is we don’t have an MSVC assembly consultant ensuring we do the right thing, which is… what we want you for! You don’t need to be an expert and even can have a real life beside us… in case you want to. :-) If that sounds interesting to you please contact Timothy (tterribe) or me (sping) via mail at xiph.org directly or through the theora-dev mailing list. Btw going larger is always possible, e.g. you could extend (3) to a Bison-based assembly converter if you want to. We’ll be there to your support of course.

Questions? Ideas?

What are you waiting for!

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-No Derivative Works 3.0 Germany License.
12 Comments
HRB October 3rd, 2007

Well, you could try using RUNTAS, a runtime-assembler for C++ (i.e. the C++ program pokes asm code into memory and accesses it through a function pointer).

On the other hand, RUNTAS was not developed to solve this kind of problem, written by a hobbyist and has therefore not been very well tested.

Currently RUNTAS only supports an intel-like syntax, but parts of at&t-style could be supported by simply switching the order of the function arguments and adding expression templates for the different style of register indexing…

The code is GPL’d and available at http://www.arithmex.com

Fred P. October 3rd, 2007

This script might help a bit converting stuff.

The main difference is that GCC use AT&T format,
while MSVC, BCC32, MASM, TASM use Intel format.

See some of these links might help:
http://www.codeproject.com/cpp/gccasm.asp
http://www.w00w00.org/files/articles/att-vs-intel.txt
http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/gnu-assembler/i386-syntax.html
http://tldp.org/HOWTO/html_single/Assembly-HOWTO/
http://www.codeproject.com/useritems/edujini_inline_asm.asp

# Short perl script to help you
# converting some trivial code…
$_ = ‘”add $16, %2\n\t” // asm’;

print “\n$_\n”;

if (m/asm/mi && m/”(\w+)\s+([^,]+)\s*,\s*([^,\\]+)\s*(?:\\t|\\n)*\s*”([^\n]*)/m) {
$before = $` . “TIS_CMD(”. lc($1) .”,”;
$after = “)” . $4;
$left = lc($2);
$right = lc($3);
$left =~ s/\s*\$\s*([0-9])+\s*/ TIS_NUM(\1) /gm;
$right =~ s/\s*\$\s*([0-9])+\s*/ TIS_NUM(\1) /gm;

$left =~ s/\s*\%\s*([0-9])+\s*/ TIS_REG(\1) /gm;
$right =~ s/\s*\%\s*([0-9])+\s*/ TIS_REG(\1) /gm;

$_ = $before . $left .”,”. $right . $after;
}

print “\n$_\n”;

Laerte October 3rd, 2007

Do you really have to use inline assembly?

Why don’t use separated files that can be assembled with nasm or another free assembler, avaiable to many diferent OS on x86 (Windows, Linux, *BSD, Solaris)?

I think some of them can use AT&T format.

chehrlic October 3rd, 2007

I also think that nasm would be much better than maintaining two sources.

Fred P. October 4th, 2007

After looking at the documentation, YASM is what you want, it compiles assembly code from AT&T/gas style
and can produce .OBJ files for Win32 and Win64 compatible with MSVC.

See -f format in:
http://www.tortall.net/projects/yasm/manual/html/manual.html#running-objfmt

Here’s the complete manual:
http://www.tortall.net/projects/yasm/manual/html/manual.html

The only thing is your code must not have inline assembly, the assembly must be in a seperate file.

berkus October 4th, 2007

I wonder why not use nasm, which has the same syntax on all x86 platforms.
Then you will only need to maintain C interface, which is pretty stable between all releases of GCC and MSVC.

LeDude October 7th, 2007

You could also try gas2masm. Converts gnu assembly code into microsoft-compatible assembly code.
I know it from the Quake source code, therefore I don’t know whether it supports the latest and greatest assembly features (SSE etc.).

Thiago Macieira October 8th, 2007

You can also tell gcc to generate Intel-syntax assembly. And then you can have your inline assembly in your .c files in the Intel style as well.

It might be even possible to do that on-the-fly in the inline assembly.

berkus October 10th, 2007

As an other interesting approach you can use Bernstein’s qhasm :)
http://cr.yp.to/qhasm.html

gmxtrqd nxdpajkuz January 10th, 2008

knvpy mqouigr icmoqzspa xmivuctnb uzsgfjvd rnegjbpxh ancxif

Uk Landfill March 25th, 2009

why not translate gnu into a bill gates compatible format?

Leave a Reply

 

Bad Behavior has blocked 933 access attempts in the last 7 days.