From: "Jan Beulich" Subject: [PATCH 2/2] x86emul: simplify asm() constraints Date: Tue, 10 Mar 2015 16:36:20 +0000 Message-ID: <54FF2B9402000078000683B8@mail.emea.novell.com> References: <54FF2A50020000780006838B@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part4A7FEC94.1__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YVN8r-0008UV-5t for xen-devel@lists.xenproject.org; Tue, 10 Mar 2015 16:36:25 +0000 In-Reply-To: <54FF2A50020000780006838B@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Andrew Cooper , Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part4A7FEC94.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Use + on outputs instead of =3D and a matching input. Allow not just memory for the _eflags operand (it turns out that recent gcc produces worse code when also doing this for _dst.val, so the latter is being avoided). Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -428,7 +428,7 @@ typedef union { /* Before executing instruction: restore necessary bits in EFLAGS. */ #define _PRE_EFLAGS(_sav, _msk, _tmp) \ /* EFLAGS =3D (_sav & _msk) | (EFLAGS & ~_msk); _sav &=3D ~_msk; */ \ -"movl %"_sav",%"_LO32 _tmp"; " \ +"movl %"_LO32 _sav",%"_LO32 _tmp"; " \ "push %"_tmp"; " \ "push %"_tmp"; " \ "movl %"_msk",%"_LO32 _tmp"; " \ @@ -448,7 +448,7 @@ typedef union { "pushf; " \ "pop %"_tmp"; " \ "andl %"_msk",%"_LO32 _tmp"; " \ -"orl %"_LO32 _tmp",%"_sav"; " +"orl %"_LO32 _tmp",%"_LO32 _sav"; " =20 /* Raw emulation: instruction has two explicit operands. */ #define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy= )\ @@ -460,18 +460,16 @@ do{ unsigned long _tmp; =20 _PRE_EFLAGS("0","4","2") = \ _op"w %"_wx"3,%1; " = \ _POST_EFLAGS("0","4","2") = \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : _wy ((_src).val), "i" (EFLAGS_MASK), = \ - "m" (_eflags), "m" ((_dst).val) ); = \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : _wy ((_src).val), "i" (EFLAGS_MASK) ); = \ break; = \ case 4: = \ asm volatile ( = \ _PRE_EFLAGS("0","4","2") = \ _op"l %"_lx"3,%1; " = \ _POST_EFLAGS("0","4","2") = \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : _ly ((_src).val), "i" (EFLAGS_MASK), = \ - "m" (_eflags), "m" ((_dst).val) ); = \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : _ly ((_src).val), "i" (EFLAGS_MASK) ); = \ break; = \ case 8: = \ __emulate_2op_8byte(_op, _src, _dst, _eflags, _qx, _qy); = \ @@ -487,9 +485,8 @@ do{ unsigned long _tmp; =20 _PRE_EFLAGS("0","4","2") = \ _op"b %"_bx"3,%1; " = \ _POST_EFLAGS("0","4","2") = \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : _by ((_src).val), "i" (EFLAGS_MASK), = \ - "m" (_eflags), "m" ((_dst).val) ); = \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : _by ((_src).val), "i" (EFLAGS_MASK) ); = \ break; = \ default: = \ __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy= );\ @@ -519,24 +516,24 @@ do{ unsigned long _tmp; =20 _PRE_EFLAGS("0","3","2") = \ _op"b %1; " = \ _POST_EFLAGS("0","3","2") = \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : "i" (EFLAGS_MASK), "m" (_eflags), "m" ((_dst).val) ); = \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : "i" (EFLAGS_MASK) ); = \ break; = \ case 2: = \ asm volatile ( = \ _PRE_EFLAGS("0","3","2") = \ _op"w %1; " = \ _POST_EFLAGS("0","3","2") = \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : "i" (EFLAGS_MASK), "m" (_eflags), "m" ((_dst).val) ); = \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : "i" (EFLAGS_MASK) ); = \ break; = \ case 4: = \ asm volatile ( = \ _PRE_EFLAGS("0","3","2") = \ _op"l %1; " = \ _POST_EFLAGS("0","3","2") = \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : "i" (EFLAGS_MASK), "m" (_eflags), "m" ((_dst).val) ); = \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : "i" (EFLAGS_MASK) ); = \ break; = \ case 8: = \ __emulate_1op_8byte(_op, _dst, _eflags); = \ @@ -551,17 +548,16 @@ do{ asm volatile ( =20 _PRE_EFLAGS("0","4","2") \ _op"q %"_qx"3,%1; " \ _POST_EFLAGS("0","4","2") \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : _qy ((_src).val), "i" (EFLAGS_MASK), \ - "m" (_eflags), "m" ((_dst).val) ); \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : _qy ((_src).val), "i" (EFLAGS_MASK) ); \ } while (0) #define __emulate_1op_8byte(_op, _dst, _eflags) \ do{ asm volatile ( \ _PRE_EFLAGS("0","3","2") \ _op"q %1; " \ _POST_EFLAGS("0","3","2") \ - : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \ - : "i" (EFLAGS_MASK), "m" (_eflags), "m" ((_dst).val) ); \ + : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \ + : "i" (EFLAGS_MASK) ); \ } while (0) #elif defined(__i386__) #define __emulate_2op_8byte(_op, _src, _dst, _eflags, _qx, _qy) @@ -806,9 +802,9 @@ static int read_ulong( static bool_t mul_dbl(unsigned long m[2]) { bool_t rc; - asm ( "mul %4; seto %b2" - : "=3Da" (m[0]), "=3Dd" (m[1]), "=3Dq" (rc) - : "0" (m[0]), "1" (m[1]), "2" (0) ); + asm ( "mul %1; seto %b2" + : "+a" (m[0]), "+d" (m[1]), "=3Dq" (rc) + : "2" (0) ); return rc; } =20 @@ -820,9 +816,9 @@ static bool_t mul_dbl(unsigned long m[2] static bool_t imul_dbl(unsigned long m[2]) { bool_t rc; - asm ( "imul %4; seto %b2" - : "=3Da" (m[0]), "=3Dd" (m[1]), "=3Dq" (rc) - : "0" (m[0]), "1" (m[1]), "2" (0) ); + asm ( "imul %1; seto %b2" + : "+a" (m[0]), "+d" (m[1]), "=3Dq" (rc) + : "2" (0) ); return rc; } =20 @@ -836,9 +832,7 @@ static bool_t div_dbl(unsigned long u[2] { if ( (v =3D=3D 0) || (u[1] >=3D v) ) return 1; - asm ( "div %4" - : "=3Da" (u[0]), "=3Dd" (u[1]) - : "0" (u[0]), "1" (u[1]), "r" (v) ); + asm ( "div %2" : "+a" (u[0]), "+d" (u[1]) : "r" (v) ); return 0; } =20 --=__Part4A7FEC94.1__= Content-Type: text/plain; name="x86emul-asm-constraints.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86emul-asm-constraints.patch" x86emul: simplify asm() constraints=0A=0AUse + on outputs instead of =3D = and a matching input. Allow not just=0Amemory for the _eflags operand (it = turns out that recent gcc produces=0Aworse code when also doing this for = _dst.val, so the latter is being=0Aavoided).=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- a/xen/arch/x86/x86_emulate/x86_emulate= .c=0A+++ b/xen/arch/x86/x86_emulate/x86_emulate.c=0A@@ -428,7 +428,7 @@ = typedef union {=0A /* Before executing instruction: restore necessary bits = in EFLAGS. */=0A #define _PRE_EFLAGS(_sav, _msk, _tmp) = \=0A /* EFLAGS =3D (_sav & _msk) | (EFLAGS & ~_msk); _sav &=3D = ~_msk; */ \=0A-"movl %"_sav",%"_LO32 _tmp"; " = \=0A+"movl %"_LO32 _sav",%"_LO32 _tmp"; " = \=0A "push %"_tmp"; " \=0A = "push %"_tmp"; " \=0A "movl = %"_msk",%"_LO32 _tmp"; " \=0A@@ -448,7 = +448,7 @@ typedef union {=0A "pushf; " = \=0A "pop %"_tmp"; " \=0A "andl = %"_msk",%"_LO32 _tmp"; " \=0A-"orl %"_LO32 _tmp",%"_sav";= "=0A+"orl %"_LO32 _tmp",%"_LO32 _sav"; "=0A =0A /* Raw emulation: = instruction has two explicit operands. */=0A #define __emulate_2op_nobyte(_= op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy)\=0A@@ -460,18 +460,16 @@ do{ = unsigned long _tmp; =0A _PRE_EFLAGS("0","4","2"= ) \=0A _op"w %"_wx"3,%1; = " \=0A _POST_EFLAGS(= "0","4","2") \=0A- : = "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) \=0A- = : _wy ((_src).val), "i" (EFLAGS_MASK), = \=0A- "m" (_eflags), "m" ((_dst).val) ); = \=0A+ : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \=0A+ : _wy ((_src).val), "i" (EFLAGS_MASK) ); = \=0A break; = \=0A case 4: = \=0A asm volatile ( = \=0A _PRE_EFLAGS("0","4","2") = \=0A _op"l %"_lx"3,%1; " = \=0A _POST_EFLAGS("0"= ,"4","2") \=0A- : "=3Dm" = (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) \=0A- = : _ly ((_src).val), "i" (EFLAGS_MASK), \=0A- = "m" (_eflags), "m" ((_dst).val) ); = \=0A+ : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) = \=0A+ : _ly ((_src).val), "i" (EFLAGS_MASK) ); = \=0A break; = \=0A case 8: = \=0A __emulate_2op_8byte(_op, _src, _dst, = _eflags, _qx, _qy); \=0A@@ -487,9 +485,8 @@ do{ unsigned long = _tmp; =0A _PRE_EFLAGS("0","4","2") = \=0A _op"b %"_bx"3,%1; " = \=0A _POST_EFLAGS("0","4","2") = \=0A- : "=3Dm" (_eflags), = "=3Dm" ((_dst).val), "=3D&r" (_tmp) \=0A- : _by = ((_src).val), "i" (EFLAGS_MASK), \=0A- = "m" (_eflags), "m" ((_dst).val) ); \=0A+ = : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) \=0A+ = : _by ((_src).val), "i" (EFLAGS_MASK) ); = \=0A break; = \=0A default: = \=0A __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_= lx,_ly,_qx,_qy);\=0A@@ -519,24 +516,24 @@ do{ unsigned long _tmp; = =0A _PRE_EFLAGS("0","3","2") = \=0A _op"b %1; " = \=0A _POST_EFLAGS("0","3","2") = \=0A- : "=3Dm" (_eflags), "=3Dm" ((_dst).va= l), "=3D&r" (_tmp) \=0A- : "i" (EFLAGS_MASK), "m" = (_eflags), "m" ((_dst).val) ); \=0A+ : "+g" (_eflags), = "+m" ((_dst).val), "=3D&r" (_tmp) \=0A+ : "i" = (EFLAGS_MASK) ); \=0A = break; \=0A = case 2: = \=0A asm volatile ( = \=0A _PRE_EFLAGS("0","3","2") = \=0A _op"w %1; " = \=0A _POST_EFLAGS("0","3","2") = \=0A- : "=3Dm" (_eflags), "=3Dm" ((_dst).val= ), "=3D&r" (_tmp) \=0A- : "i" (EFLAGS_MASK), "m" = (_eflags), "m" ((_dst).val) ); \=0A+ : "+g" (_eflags), = "+m" ((_dst).val), "=3D&r" (_tmp) \=0A+ : "i" = (EFLAGS_MASK) ); \=0A = break; \=0A = case 4: = \=0A asm volatile ( = \=0A _PRE_EFLAGS("0","3","2") = \=0A _op"l %1; " = \=0A _POST_EFLAGS("0","3","2") = \=0A- : "=3Dm" (_eflags), "=3Dm" ((_dst).val= ), "=3D&r" (_tmp) \=0A- : "i" (EFLAGS_MASK), "m" = (_eflags), "m" ((_dst).val) ); \=0A+ : "+g" (_eflags), = "+m" ((_dst).val), "=3D&r" (_tmp) \=0A+ : "i" = (EFLAGS_MASK) ); \=0A = break; \=0A = case 8: = \=0A __emulate_1op_8byte(_op, _dst, _eflags); = \=0A@@ -551,17 +548,16 @@ do{ asm volatile ( =0A = _PRE_EFLAGS("0","4","2") = \=0A _op"q %"_qx"3,%1; " = \=0A _POST_EFLAGS("0","4","2") = \=0A- : "=3Dm" (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) = \=0A- : _qy ((_src).val), "i" (EFLAGS_MASK), = \=0A- "m" (_eflags), "m" ((_dst).val) ); = \=0A+ : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" = (_tmp) \=0A+ : _qy ((_src).val), "i" (EFLAGS_MASK) ); = \=0A } while (0)=0A #define __emulate_1op_8byte(_op,= _dst, _eflags) \=0A do{ asm volatile ( = \=0A _PRE_EFLAGS("0","3",= "2") \=0A _op"q %1; " = \=0A _POST_EFLAGS("0"= ,"3","2") \=0A- : "=3Dm" = (_eflags), "=3Dm" ((_dst).val), "=3D&r" (_tmp) \=0A- = : "i" (EFLAGS_MASK), "m" (_eflags), "m" ((_dst).val) ); \=0A+ = : "+g" (_eflags), "+m" ((_dst).val), "=3D&r" (_tmp) \=0A+ = : "i" (EFLAGS_MASK) ); \=0A = } while (0)=0A #elif defined(__i386__)=0A #define __emulate_2op_8byte(_op, = _src, _dst, _eflags, _qx, _qy)=0A@@ -806,9 +802,9 @@ static int read_ulong(= =0A static bool_t mul_dbl(unsigned long m[2])=0A {=0A bool_t rc;=0A- = asm ( "mul %4; seto %b2"=0A- : "=3Da" (m[0]), "=3Dd" (m[1]), = "=3Dq" (rc)=0A- : "0" (m[0]), "1" (m[1]), "2" (0) );=0A+ asm ( = "mul %1; seto %b2"=0A+ : "+a" (m[0]), "+d" (m[1]), "=3Dq" = (rc)=0A+ : "2" (0) );=0A return rc;=0A }=0A =0A@@ -820,9 = +816,9 @@ static bool_t mul_dbl(unsigned long m[2]=0A static bool_t = imul_dbl(unsigned long m[2])=0A {=0A bool_t rc;=0A- asm ( "imul %4; = seto %b2"=0A- : "=3Da" (m[0]), "=3Dd" (m[1]), "=3Dq" (rc)=0A- = : "0" (m[0]), "1" (m[1]), "2" (0) );=0A+ asm ( "imul %1; seto = %b2"=0A+ : "+a" (m[0]), "+d" (m[1]), "=3Dq" (rc)=0A+ : = "2" (0) );=0A return rc;=0A }=0A =0A@@ -836,9 +832,7 @@ static bool_t = div_dbl(unsigned long u[2]=0A {=0A if ( (v =3D=3D 0) || (u[1] >=3D v) = )=0A return 1;=0A- asm ( "div %4"=0A- : "=3Da" (u[0]), = "=3Dd" (u[1])=0A- : "0" (u[0]), "1" (u[1]), "r" (v) );=0A+ asm = ( "div %2" : "+a" (u[0]), "+d" (u[1]) : "r" (v) );=0A return 0;=0A = }=0A =0A --=__Part4A7FEC94.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part4A7FEC94.1__=--