Advertisement

gcc forum - -masm issue

Started by September 05, 2004 11:33 AM
2 comments, last by Winograd 20 years, 3 months ago
Sounds noobish, but after some googling I could not find a serious site dedicated to www discussions about gcc à la GameDev. I know gcc has mailing lists, but they are not as convenient as a forum. Contextual precisions : - I use DevC++ (WinXP), no Linux user but I am coding cross platform stuff, valid for Linux. - my concerns are around compatibility, multiplatform software and low level programming such mixing and macro functions in assembly. For instance my current issue is how to be sure my assembly macros (defined in headers of course) won't bug if a user changes the default asm dialect (-masm=att) to -masm=intel. As this reverses the operand order in the asm instructions output, it's quite vicious. I found no macro defined by gcc (with -D) when -masm=intel is set. Thus I can't test the dialect at preprocess time and at least trigger an #error in this case. Edit : found this .intel_syntax noprefix tip ... at Gamedev of course. http://www.gamedev.net/reference/articles/article1987.asp [Edited by - Charles B on September 5, 2004 12:08:11 PM]
"Coding math tricks in asm is more fun than Java"
As far as I know, gcc uses ALWAYS AT&T syntax in inline assembly. -masm switches the _output_ syntax not the input. So the difference is only visible for user when gcc outputs assembly code i.e. with -S flag. Thus, if your macros are written in AT&T syntax that gcc understands, you should be ok.
Advertisement
It's what I thought but it's not true, it changes both the way source code is interpreted AND how asm code is output when the -S option is used. This is maybe a bug because the docs are unclear about masm.

Example :

// asm macro written in ATT style since it's the default
// It does r+=s; (3DNow)
#define _add_2f(r, s)asm{ "pfadd %2, %0" : "=y"(r) : "0"(r), "y"(r) }

In case -masm=att, no problem of course. But in case -masm=intel, in the end, for the processor, %2 will be the input/output and %0 the input, while the compiler thought %0 was read/write and %2 read only. The result is of course catastrophic.

GCC produces (intel dialect) :

mm0 <- r
mm1 <- s
pfadd mm1, mm0 ; mm1 modified, mm0 unchanged
r <- mm0
s <- mm1

r is unchanged and s is modified !!!


The problem is that I found no way to be informed that the user set -masm=intel and react appropriately.

The only thing I have atm is that the instructions "shift MMX register with an immediate (0-63)" will generate an error. You can't modify a constant ! I can thus inform the user of the problem in the comments of the header at this location. But generally I prefer cleaner ways !
"Coding math tricks in asm is more fun than Java"
Usually when one compiles software under linux, the software comes with configure script (autogenerated.. partly) that could check which syntax is used (you would have to provide the test of course). It does several other tests where pieces of code is compiled and the result is checked. Then configure script creates config.h file that contains macros according to test results.

This topic is closed to new replies.

Advertisement