tkchia / gcc-ia16

Fork of Lambertsen & Jenner (& al.)'s IA-16 (Intel 16-bit x86) port of GNU compilers ― added far pointers & more • use https://github.com/tkchia/build-ia16 to build • Ubuntu binaries at https://launchpad.net/%7Etkchia/+archive/ubuntu/build-ia16/ • DJGPP/MS-DOS binaries at https://gitlab.com/tkchia/build-ia16/-/releases • mirror of https://gitlab.com/tkchia/gcc-ia16
GNU General Public License v2.0
173 stars 13 forks source link

Inline assembly constraint "=@cc<cond>" is broken #85

Open iucoen opened 2 years ago

iucoen commented 2 years ago

gcc for i386 and x86_64 support setting output of inline assembly block based on condition flags.

For example

int is_zero;
asm("test %1, %1" : "=@ccz"(is_zero) : "=r"(0));

would set is_zero to 1. On i386 that assembly block would be equivalent to:

asm("test %1, %1\n ""setz %0\n" : "=r"(is_zero) : "=r"(0));

With gcc-ia16, "=@cc" would get parsed as just "c", and the compiler emits a "mov %cx, %0" instead, which is wrong. If "=@cc" is not supported, the compiler should at least fail with an error, not interpret the constraint to mean %cx.

tkchia commented 2 years ago

Hello @iucoen,

OK, I will look into how to handle "=@cc..." constraints more properly.

From what I see, GCC in general basically skips over unrecognized characters (e.g. @) in constraints. The i386 back-end actually implements an extra TARGET_MD_ASM_ADJUST hook to specially parse and handle "=@cc..." constraints. Perhaps the IA-16 back-end can do something similar.

Thank you!

tkchia commented 2 years ago

Hello @iucoen,

In the meantime, you can get your code to test for the __GCC_ASM_FLAG_OUTPUTS__ macro — as described in the gcc info file — to see if the compiler supports "=@cc...".

Thank you!