Subject: port-i386/6218: as generates wrong code for cmov
To: None <gnats-bugs@gnats.netbsd.org>
From: None <Anders.Hjalmarsson@economics.gu.se>
List: netbsd-bugs
Date: 10/01/1998 01:51:02
>Number:         6218
>Category:       port-i386
>Synopsis:       as generates wrong code for cmov
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 30 17:05:01 1998
>Last-Modified:
>Originator:     Anders Hjalmarsson
>Organization:
>Release:        current-19980928
>Environment:
System: NetBSD econahja.econ.gu.se 1.3H NetBSD 1.3H (ECONAHJA) #131: Wed Sep 30 02:31:35 CEST 1998 econahja@econahja.econ.gu.se:/usr/src/sys/arch/i386/compile/ECONAHJA i386


>Description:
	as (the old one, which is used on i386) assembles the cmov
	instructions incorrectly
>How-To-Repeat:
	Assemble the following progam with 'as -a p.s' and look at the listing

	cmovo %edx,%eax
	cmovno %edx,%eax
	cmovb  %edx,%eax
	cmovae %edx,%eax
	cmove  %edx,%eax
	cmovne %edx,%eax
	cmovbe %edx,%eax
	cmova  %edx,%eax
	cmovs  %edx,%eax
	cmovns %edx,%eax
	cmovp  %edx,%eax
	cmovnp %edx,%eax
	cmovl  %edx,%eax
	cmovge %edx,%eax
	cmovle %edx,%eax
	cmovg  %edx,%eax

Here is the output from the broken assembler:
GAS LISTING p.s 			page 1


   1 0000 0F41C2   		cmovo %edx,%eax
   2 0003 0F41C2   		cmovno %edx,%eax
   3 0006 0F43C2   		cmovb  %edx,%eax
   4 0009 0F43C2   		cmovae %edx,%eax
   5 000c 0F45C2   		cmove  %edx,%eax
   6 000f 0F45C2   		cmovne %edx,%eax
   7 0012 0F47C2   		cmovbe %edx,%eax
   8 0015 0F47C2   		cmova  %edx,%eax
   9 0018 0F49C2   		cmovs  %edx,%eax
  10 001b 0F49C2   		cmovns %edx,%eax
  11 001e 0F4BC2   		cmovp  %edx,%eax
  12 0021 0F4BC2   		cmovnp %edx,%eax
  13 0024 0F4DC2   		cmovl  %edx,%eax
  14 0027 0F4DC2   		cmovge %edx,%eax
  15 002a 0F4FC2   		cmovle %edx,%eax
  16 002d 0F4FC2   		cmovg  %edx,%eax
GAS LISTING p.s 			page 2


NO DEFINED SYMBOLS

NO UNDEFINED SYMBOLS

Note that the same code is generated for each pair of lines

>Fix:
The problem is the W flag, there is no word version of cmov.
I took a quick look at the new gas and it seems to agree with me.
(See src/gnu/dist/include/opcode/i386.h)

--- src/gnu/usr.bin/gas/opcode/i386.h.old	Sat Sep  6 13:09:17 1997
+++ src/gnu/usr.bin/gas/opcode/i386.h	Tue Sep 29 03:45:57 1998
@@ -741,22 +741,22 @@
 /* Pentium Pro extensions */
 {"rdpmc", 0, 0x0f33, _, NoModrm, 0, 0, 0},
 
-{"cmovo",  2, 0x0f40, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovno", 2, 0x0f41, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovb",  2, 0x0f42, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovae", 2, 0x0f43, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmove",  2, 0x0f44, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovne", 2, 0x0f45, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovbe", 2, 0x0f46, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmova",  2, 0x0f47, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovs",  2, 0x0f48, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovns", 2, 0x0f49, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovp",  2, 0x0f4a, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovnp", 2, 0x0f4b, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovl",  2, 0x0f4c, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovge", 2, 0x0f4d, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovle", 2, 0x0f4e, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
-{"cmovg",  2, 0x0f4f, _, W|Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovo",  2, 0x0f40, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovno", 2, 0x0f41, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovb",  2, 0x0f42, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovae", 2, 0x0f43, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmove",  2, 0x0f44, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovne", 2, 0x0f45, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovbe", 2, 0x0f46, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmova",  2, 0x0f47, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovs",  2, 0x0f48, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovns", 2, 0x0f49, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovp",  2, 0x0f4a, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovnp", 2, 0x0f4b, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovl",  2, 0x0f4c, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovge", 2, 0x0f4d, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovle", 2, 0x0f4e, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
+{"cmovg",  2, 0x0f4f, _, Modrm|ReverseRegRegmem, WordReg|WordMem, WordReg, 0},
 
 {"fcmovb", 2, 0xdac0, _, ShortForm, FloatReg, FloatAcc, 0},
 {"fcmove", 2, 0xdac8, _, ShortForm, FloatReg, FloatAcc, 0},
>Audit-Trail:
>Unformatted: