Mark Wielaard c858e5
From 04cdc29b007594a0e58ffef0c9dd87df3ea595ea Mon Sep 17 00:00:00 2001
Mark Wielaard c858e5
From: Mark Wielaard <mark@klomp.org>
Mark Wielaard c858e5
Date: Wed, 14 Oct 2020 06:11:34 -0400
Mark Wielaard c858e5
Subject: [PATCH] arm64 VEX frontend and backend support for
Mark Wielaard c858e5
 Iop_M{Add,Sub}F{32,64}
Mark Wielaard c858e5
Mark Wielaard c858e5
The arm64 frontend used to implement the scalar fmadd, fmsub, fnmadd
Mark Wielaard c858e5
and fnmsub iinstructions into separate addition/substraction and
Mark Wielaard c858e5
multiplication instructions, which caused rounding issues.
Mark Wielaard c858e5
Mark Wielaard c858e5
This patch turns them into Iop_M{Add,Sub}F{32,64} instructions
Mark Wielaard c858e5
(with some arguments negated). And the backend now emits fmadd or fmsub
Mark Wielaard c858e5
instructions.
Mark Wielaard c858e5
Mark Wielaard c858e5
Alexandra Hajkova <ahajkova@redhat.com> added tests and fixed up the
Mark Wielaard c858e5
implementation to make sure rounding (and sign) are correct now.
Mark Wielaard c858e5
Mark Wielaard c858e5
https://bugs.kde.org/show_bug.cgi?id=426014
Mark Wielaard c858e5
---
Mark Wielaard c858e5
 VEX/priv/guest_arm64_toIR.c           |  58 ++++++++---
Mark Wielaard c858e5
 VEX/priv/host_arm64_defs.c            | 136 +++++++++++++++++++++++++-
Mark Wielaard c858e5
 VEX/priv/host_arm64_defs.h            |  30 ++++++
Mark Wielaard c858e5
 VEX/priv/host_arm64_isel.c            |  39 ++++++++
Mark Wielaard c858e5
 none/tests/arm64/Makefile.am          |   6 +-
Mark Wielaard c858e5
 none/tests/arm64/fmadd_sub.c          |  98 +++++++++++++++++++
Mark Wielaard c858e5
 none/tests/arm64/fmadd_sub.stderr.exp |   0
Mark Wielaard c858e5
 none/tests/arm64/fmadd_sub.stdout.exp | 125 +++++++++++++++++++++++
Mark Wielaard c858e5
 none/tests/arm64/fmadd_sub.vgtest     |   3 +
Mark Wielaard c858e5
 9 files changed, 479 insertions(+), 16 deletions(-)
Mark Wielaard c858e5
 create mode 100644 none/tests/arm64/fmadd_sub.c
Mark Wielaard c858e5
 create mode 100644 none/tests/arm64/fmadd_sub.stderr.exp
Mark Wielaard c858e5
 create mode 100644 none/tests/arm64/fmadd_sub.stdout.exp
Mark Wielaard c858e5
 create mode 100644 none/tests/arm64/fmadd_sub.vgtest
Mark Wielaard c858e5
Mark Wielaard c858e5
diff --git a/VEX/priv/guest_arm64_toIR.c b/VEX/priv/guest_arm64_toIR.c
Mark Wielaard c858e5
index 556b85a6a..d242d43c0 100644
Mark Wielaard c858e5
--- a/VEX/priv/guest_arm64_toIR.c
Mark Wielaard c858e5
+++ b/VEX/priv/guest_arm64_toIR.c
Mark Wielaard c858e5
@@ -286,6 +286,12 @@ static IRExpr* triop ( IROp op, IRExpr* a1, IRExpr* a2, IRExpr* a3 )
Mark Wielaard c858e5
    return IRExpr_Triop(op, a1, a2, a3);
Mark Wielaard c858e5
 }
Mark Wielaard c858e5
 
Mark Wielaard c858e5
+static IRExpr* qop ( IROp op, IRExpr* a1, IRExpr* a2,
Mark Wielaard c858e5
+                              IRExpr* a3, IRExpr* a4 )
Mark Wielaard c858e5
+{
Mark Wielaard c858e5
+   return IRExpr_Qop(op, a1, a2, a3, a4);
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
 static IRExpr* loadLE ( IRType ty, IRExpr* addr )
Mark Wielaard c858e5
 {
Mark Wielaard c858e5
    return IRExpr_Load(Iend_LE, ty, addr);
Mark Wielaard c858e5
@@ -532,6 +538,22 @@ static IROp mkADDF ( IRType ty ) {
Mark Wielaard c858e5
    }
Mark Wielaard c858e5
 }
Mark Wielaard c858e5
 
Mark Wielaard c858e5
+static IROp mkFMADDF ( IRType ty ) {
Mark Wielaard c858e5
+   switch (ty) {
Mark Wielaard c858e5
+      case Ity_F32: return Iop_MAddF32;
Mark Wielaard c858e5
+      case Ity_F64: return Iop_MAddF64;
Mark Wielaard c858e5
+      default: vpanic("mkFMADDF");
Mark Wielaard c858e5
+   }
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+static IROp mkFMSUBF ( IRType ty ) {
Mark Wielaard c858e5
+   switch (ty) {
Mark Wielaard c858e5
+      case Ity_F32: return Iop_MSubF32;
Mark Wielaard c858e5
+      case Ity_F64: return Iop_MSubF64;
Mark Wielaard c858e5
+      default: vpanic("mkFMSUBF");
Mark Wielaard c858e5
+   }
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
 static IROp mkSUBF ( IRType ty ) {
Mark Wielaard c858e5
    switch (ty) {
Mark Wielaard c858e5
       case Ity_F32: return Iop_SubF32;
Mark Wielaard c858e5
@@ -14368,30 +14390,40 @@ Bool dis_AdvSIMD_fp_data_proc_3_source(/*MB_OUT*/DisResult* dres, UInt insn)
Mark Wielaard c858e5
          where Fx=Dx when sz=1, Fx=Sx when sz=0
Mark Wielaard c858e5
 
Mark Wielaard c858e5
                   -----SPEC------    ----IMPL----
Mark Wielaard c858e5
-         fmadd       a +    n * m    a + n * m
Mark Wielaard c858e5
-         fmsub       a + (-n) * m    a - n * m
Mark Wielaard c858e5
-         fnmadd   (-a) + (-n) * m    -(a + n * m)
Mark Wielaard c858e5
-         fnmsub   (-a) +    n * m    -(a - n * m)
Mark Wielaard c858e5
+         fmadd       a +    n * m    fmadd (a, n, m)
Mark Wielaard c858e5
+         fmsub       a + (-n) * m    fmsub (a, n, m)
Mark Wielaard c858e5
+         fnmadd   (-a) + (-n) * m    fmadd (-a, -n, m)
Mark Wielaard c858e5
+         fnmsub   (-a) +    n * m    fmadd (-a, n, m)
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+         Note Iop_MAdd/SubF32/64 take arguments in the order: rm, N, M, A
Mark Wielaard c858e5
       */
Mark Wielaard c858e5
       Bool    isD   = (ty & 1) == 1;
Mark Wielaard c858e5
       UInt    ix    = (bitO1 << 1) | bitO0;
Mark Wielaard c858e5
       IRType  ity   = isD ? Ity_F64 : Ity_F32;
Mark Wielaard c858e5
-      IROp    opADD = mkADDF(ity);
Mark Wielaard c858e5
-      IROp    opSUB = mkSUBF(ity);
Mark Wielaard c858e5
-      IROp    opMUL = mkMULF(ity);
Mark Wielaard c858e5
+      IROp    opFMADD = mkFMADDF(ity);
Mark Wielaard c858e5
+      IROp    opFMSUB = mkFMSUBF(ity);
Mark Wielaard c858e5
       IROp    opNEG = mkNEGF(ity);
Mark Wielaard c858e5
       IRTemp  res   = newTemp(ity);
Mark Wielaard c858e5
       IRExpr* eA    = getQRegLO(aa, ity);
Mark Wielaard c858e5
       IRExpr* eN    = getQRegLO(nn, ity);
Mark Wielaard c858e5
       IRExpr* eM    = getQRegLO(mm, ity);
Mark Wielaard c858e5
       IRExpr* rm    = mkexpr(mk_get_IR_rounding_mode());
Mark Wielaard c858e5
-      IRExpr* eNxM  = triop(opMUL, rm, eN, eM);
Mark Wielaard c858e5
       switch (ix) {
Mark Wielaard c858e5
-         case 0:  assign(res, triop(opADD, rm, eA, eNxM)); break;
Mark Wielaard c858e5
-         case 1:  assign(res, triop(opSUB, rm, eA, eNxM)); break;
Mark Wielaard c858e5
-         case 2:  assign(res, unop(opNEG, triop(opADD, rm, eA, eNxM))); break;
Mark Wielaard c858e5
-         case 3:  assign(res, unop(opNEG, triop(opSUB, rm, eA, eNxM))); break;
Mark Wielaard c858e5
-         default: vassert(0);
Mark Wielaard c858e5
+         case 0: /* FMADD */
Mark Wielaard c858e5
+            assign(res, qop(opFMADD, rm, eN, eM, eA));
Mark Wielaard c858e5
+            break;
Mark Wielaard c858e5
+         case 1: /* FMSUB */
Mark Wielaard c858e5
+            assign(res, qop(opFMSUB, rm, eN, eM, eA));
Mark Wielaard c858e5
+            break;
Mark Wielaard c858e5
+         case 2: /* FNMADD */
Mark Wielaard c858e5
+            assign(res, qop(opFMADD, rm, unop(opNEG, eN), eM,
Mark Wielaard c858e5
+                            unop(opNEG,eA)));
Mark Wielaard c858e5
+            break;
Mark Wielaard c858e5
+         case 3: /* FNMSUB */
Mark Wielaard c858e5
+            assign(res, qop(opFMADD, rm, eN, eM, unop(opNEG, eA)));
Mark Wielaard c858e5
+            break;
Mark Wielaard c858e5
+         default:
Mark Wielaard c858e5
+            vassert(0);
Mark Wielaard c858e5
       }
Mark Wielaard c858e5
       putQReg128(dd, mkV128(0x0000));
Mark Wielaard c858e5
       putQRegLO(dd, mkexpr(res));
Mark Wielaard c858e5
diff --git a/VEX/priv/host_arm64_defs.c b/VEX/priv/host_arm64_defs.c
Mark Wielaard c858e5
index e4ef56986..13b497f60 100644
Mark Wielaard c858e5
--- a/VEX/priv/host_arm64_defs.c
Mark Wielaard c858e5
+++ b/VEX/priv/host_arm64_defs.c
Mark Wielaard c858e5
@@ -546,6 +546,14 @@ static const HChar* showARM64FpBinOp ( ARM64FpBinOp op ) {
Mark Wielaard c858e5
    }
Mark Wielaard c858e5
 }
Mark Wielaard c858e5
 
Mark Wielaard c858e5
+static const HChar* showARM64FpTriOp ( ARM64FpTriOp op ) {
Mark Wielaard c858e5
+   switch (op) {
Mark Wielaard c858e5
+      case ARM64fpt_FMADD: return "fmadd";
Mark Wielaard c858e5
+      case ARM64fpt_FMSUB: return "fmsub";
Mark Wielaard c858e5
+      default: vpanic("showARM64FpTriOp");
Mark Wielaard c858e5
+   }
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
 static const HChar* showARM64FpUnaryOp ( ARM64FpUnaryOp op ) {
Mark Wielaard c858e5
    switch (op) {
Mark Wielaard c858e5
       case ARM64fpu_NEG:   return "neg  ";
Mark Wielaard c858e5
@@ -1154,6 +1162,28 @@ ARM64Instr* ARM64Instr_VBinS ( ARM64FpBinOp op,
Mark Wielaard c858e5
    i->ARM64in.VBinS.argR = argR;
Mark Wielaard c858e5
    return i;
Mark Wielaard c858e5
 }
Mark Wielaard c858e5
+ARM64Instr* ARM64Instr_VTriD ( ARM64FpTriOp op,
Mark Wielaard c858e5
+                               HReg dst, HReg arg1, HReg arg2, HReg arg3 ) {
Mark Wielaard c858e5
+   ARM64Instr* i = LibVEX_Alloc_inline(sizeof(ARM64Instr));
Mark Wielaard c858e5
+   i->tag                = ARM64in_VTriD;
Mark Wielaard c858e5
+   i->ARM64in.VTriD.op   = op;
Mark Wielaard c858e5
+   i->ARM64in.VTriD.dst  = dst;
Mark Wielaard c858e5
+   i->ARM64in.VTriD.arg1 = arg1;
Mark Wielaard c858e5
+   i->ARM64in.VTriD.arg2 = arg2;
Mark Wielaard c858e5
+   i->ARM64in.VTriD.arg3 = arg3;
Mark Wielaard c858e5
+   return i;
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+ARM64Instr* ARM64Instr_VTriS ( ARM64FpTriOp op,
Mark Wielaard c858e5
+                               HReg dst, HReg arg1, HReg arg2, HReg arg3 ) {
Mark Wielaard c858e5
+   ARM64Instr* i = LibVEX_Alloc_inline(sizeof(ARM64Instr));
Mark Wielaard c858e5
+   i->tag                = ARM64in_VTriS;
Mark Wielaard c858e5
+   i->ARM64in.VTriS.op   = op;
Mark Wielaard c858e5
+   i->ARM64in.VTriS.dst  = dst;
Mark Wielaard c858e5
+   i->ARM64in.VTriS.arg1 = arg1;
Mark Wielaard c858e5
+   i->ARM64in.VTriS.arg2 = arg2;
Mark Wielaard c858e5
+   i->ARM64in.VTriS.arg3 = arg3;
Mark Wielaard c858e5
+   return i;
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
 ARM64Instr* ARM64Instr_VCmpD ( HReg argL, HReg argR ) {
Mark Wielaard c858e5
    ARM64Instr* i = LibVEX_Alloc_inline(sizeof(ARM64Instr));
Mark Wielaard c858e5
    i->tag                = ARM64in_VCmpD;
Mark Wielaard c858e5
@@ -1756,6 +1786,26 @@ void ppARM64Instr ( const ARM64Instr* i ) {
Mark Wielaard c858e5
          vex_printf(", ");
Mark Wielaard c858e5
          ppHRegARM64asSreg(i->ARM64in.VBinS.argR);
Mark Wielaard c858e5
          return;
Mark Wielaard c858e5
+      case ARM64in_VTriD:
Mark Wielaard c858e5
+         vex_printf("f%s   ", showARM64FpTriOp(i->ARM64in.VTriD.op));
Mark Wielaard c858e5
+         ppHRegARM64(i->ARM64in.VTriD.dst);
Mark Wielaard c858e5
+         vex_printf(", ");
Mark Wielaard c858e5
+         ppHRegARM64(i->ARM64in.VTriD.arg1);
Mark Wielaard c858e5
+         vex_printf(", ");
Mark Wielaard c858e5
+         ppHRegARM64(i->ARM64in.VTriD.arg2);
Mark Wielaard c858e5
+         vex_printf(", ");
Mark Wielaard c858e5
+         ppHRegARM64(i->ARM64in.VTriD.arg3);
Mark Wielaard c858e5
+         return;
Mark Wielaard c858e5
+      case ARM64in_VTriS:
Mark Wielaard c858e5
+         vex_printf("f%s   ", showARM64FpTriOp(i->ARM64in.VTriS.op));
Mark Wielaard c858e5
+         ppHRegARM64asSreg(i->ARM64in.VTriS.dst);
Mark Wielaard c858e5
+         vex_printf(", ");
Mark Wielaard c858e5
+         ppHRegARM64asSreg(i->ARM64in.VTriS.arg1);
Mark Wielaard c858e5
+         vex_printf(", ");
Mark Wielaard c858e5
+         ppHRegARM64asSreg(i->ARM64in.VTriS.arg2);
Mark Wielaard c858e5
+         vex_printf(", ");
Mark Wielaard c858e5
+         ppHRegARM64asSreg(i->ARM64in.VTriS.arg3);
Mark Wielaard c858e5
+         return;
Mark Wielaard c858e5
       case ARM64in_VCmpD:
Mark Wielaard c858e5
          vex_printf("fcmp   ");
Mark Wielaard c858e5
          ppHRegARM64(i->ARM64in.VCmpD.argL);
Mark Wielaard c858e5
@@ -2197,6 +2247,18 @@ void getRegUsage_ARM64Instr ( HRegUsage* u, const ARM64Instr* i, Bool mode64 )
Mark Wielaard c858e5
          addHRegUse(u, HRmRead, i->ARM64in.VBinS.argL);
Mark Wielaard c858e5
          addHRegUse(u, HRmRead, i->ARM64in.VBinS.argR);
Mark Wielaard c858e5
          return;
Mark Wielaard c858e5
+      case ARM64in_VTriD:
Mark Wielaard c858e5
+         addHRegUse(u, HRmWrite, i->ARM64in.VTriD.dst);
Mark Wielaard c858e5
+         addHRegUse(u, HRmRead, i->ARM64in.VTriD.arg1);
Mark Wielaard c858e5
+         addHRegUse(u, HRmRead, i->ARM64in.VTriD.arg2);
Mark Wielaard c858e5
+         addHRegUse(u, HRmRead, i->ARM64in.VTriD.arg3);
Mark Wielaard c858e5
+         return;
Mark Wielaard c858e5
+      case ARM64in_VTriS:
Mark Wielaard c858e5
+         addHRegUse(u, HRmWrite, i->ARM64in.VTriS.dst);
Mark Wielaard c858e5
+         addHRegUse(u, HRmRead, i->ARM64in.VTriS.arg1);
Mark Wielaard c858e5
+         addHRegUse(u, HRmRead, i->ARM64in.VTriS.arg2);
Mark Wielaard c858e5
+         addHRegUse(u, HRmRead, i->ARM64in.VTriS.arg3);
Mark Wielaard c858e5
+         return;
Mark Wielaard c858e5
       case ARM64in_VCmpD:
Mark Wielaard c858e5
          addHRegUse(u, HRmRead, i->ARM64in.VCmpD.argL);
Mark Wielaard c858e5
          addHRegUse(u, HRmRead, i->ARM64in.VCmpD.argR);
Mark Wielaard c858e5
@@ -2454,6 +2516,18 @@ void mapRegs_ARM64Instr ( HRegRemap* m, ARM64Instr* i, Bool mode64 )
Mark Wielaard c858e5
          i->ARM64in.VBinS.argL = lookupHRegRemap(m, i->ARM64in.VBinS.argL);
Mark Wielaard c858e5
          i->ARM64in.VBinS.argR = lookupHRegRemap(m, i->ARM64in.VBinS.argR);
Mark Wielaard c858e5
          return;
Mark Wielaard c858e5
+      case ARM64in_VTriD:
Mark Wielaard c858e5
+         i->ARM64in.VTriD.dst  = lookupHRegRemap(m, i->ARM64in.VTriD.dst);
Mark Wielaard c858e5
+         i->ARM64in.VTriD.arg1 = lookupHRegRemap(m, i->ARM64in.VTriD.arg1);
Mark Wielaard c858e5
+         i->ARM64in.VTriD.arg2 = lookupHRegRemap(m, i->ARM64in.VTriD.arg2);
Mark Wielaard c858e5
+         i->ARM64in.VTriD.arg3 = lookupHRegRemap(m, i->ARM64in.VTriD.arg3);
Mark Wielaard c858e5
+         return;
Mark Wielaard c858e5
+      case ARM64in_VTriS:
Mark Wielaard c858e5
+         i->ARM64in.VTriS.dst  = lookupHRegRemap(m, i->ARM64in.VTriS.dst);
Mark Wielaard c858e5
+         i->ARM64in.VTriS.arg1 = lookupHRegRemap(m, i->ARM64in.VTriS.arg1);
Mark Wielaard c858e5
+         i->ARM64in.VTriS.arg2 = lookupHRegRemap(m, i->ARM64in.VTriS.arg2);
Mark Wielaard c858e5
+         i->ARM64in.VTriS.arg3 = lookupHRegRemap(m, i->ARM64in.VTriS.arg3);
Mark Wielaard c858e5
+         return;
Mark Wielaard c858e5
       case ARM64in_VCmpD:
Mark Wielaard c858e5
          i->ARM64in.VCmpD.argL = lookupHRegRemap(m, i->ARM64in.VCmpD.argL);
Mark Wielaard c858e5
          i->ARM64in.VCmpD.argR = lookupHRegRemap(m, i->ARM64in.VCmpD.argR);
Mark Wielaard c858e5
@@ -2812,7 +2886,8 @@ static inline UInt qregEnc ( HReg r )
Mark Wielaard c858e5
 #define X11110011  BITS8(1,1,1,1,0,0,1,1)
Mark Wielaard c858e5
 #define X11110101  BITS8(1,1,1,1,0,1,0,1)
Mark Wielaard c858e5
 #define X11110111  BITS8(1,1,1,1,0,1,1,1)
Mark Wielaard c858e5
-
Mark Wielaard c858e5
+#define X11111000  BITS8(1,1,1,1,1,0,0,0)
Mark Wielaard c858e5
+#define X11111010  BITS8(1,1,1,1,1,0,1,0)
Mark Wielaard c858e5
 
Mark Wielaard c858e5
 /* --- 4 fields --- */
Mark Wielaard c858e5
 
Mark Wielaard c858e5
@@ -2972,6 +3047,27 @@ static inline UInt X_3_6_1_6_6_5_5 ( UInt f1, UInt f2, UInt f3,
Mark Wielaard c858e5
 }
Mark Wielaard c858e5
 
Mark Wielaard c858e5
 
Mark Wielaard c858e5
+static inline UInt X_3_8_5_1_5_5_5 ( UInt f1, UInt f2, UInt f3, UInt f4,
Mark Wielaard c858e5
+                                     UInt f5, UInt f6, UInt f7 ) {
Mark Wielaard c858e5
+   vassert(3+8+5+1+5+5+5 == 32);
Mark Wielaard c858e5
+   vassert(f1 < (1<<3));
Mark Wielaard c858e5
+   vassert(f2 < (1<<8));
Mark Wielaard c858e5
+   vassert(f3 < (1<<5));
Mark Wielaard c858e5
+   vassert(f4 < (1<<1));
Mark Wielaard c858e5
+   vassert(f5 < (1<<5));
Mark Wielaard c858e5
+   vassert(f6 < (1<<5));
Mark Wielaard c858e5
+   vassert(f7 < (1<<5));
Mark Wielaard c858e5
+   UInt w = 0;
Mark Wielaard c858e5
+   w = (w << 3) | f1;
Mark Wielaard c858e5
+   w = (w << 8) | f2;
Mark Wielaard c858e5
+   w = (w << 5) | f3;
Mark Wielaard c858e5
+   w = (w << 1) | f4;
Mark Wielaard c858e5
+   w = (w << 5) | f5;
Mark Wielaard c858e5
+   w = (w << 5) | f6;
Mark Wielaard c858e5
+   w = (w << 5) | f7;
Mark Wielaard c858e5
+   return w;
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
 //ZZ #define X0000  BITS4(0,0,0,0)
Mark Wielaard c858e5
 //ZZ #define X0001  BITS4(0,0,0,1)
Mark Wielaard c858e5
 //ZZ #define X0010  BITS4(0,0,1,0)
Mark Wielaard c858e5
@@ -4339,6 +4435,44 @@ Int emit_ARM64Instr ( /*MB_MOD*/Bool* is_profInc,
Mark Wielaard c858e5
             = X_3_8_5_6_5_5(X000, X11110001, sM, (b1512 << 2) | X10, sN, sD);
Mark Wielaard c858e5
          goto done;
Mark Wielaard c858e5
       }
Mark Wielaard c858e5
+      case ARM64in_VTriD: {
Mark Wielaard c858e5
+         /* 31            20 15 14 9 4
Mark Wielaard c858e5
+            000 11111 010 m  0  a  n d FMADD  Dd,Dn,Dm,Da
Mark Wielaard c858e5
+            ---------------- 1  ------ FMSUB  -----------
Mark Wielaard c858e5
+         */
Mark Wielaard c858e5
+         UInt dD = dregEnc(i->ARM64in.VTriD.dst);
Mark Wielaard c858e5
+         UInt dN = dregEnc(i->ARM64in.VTriD.arg1);
Mark Wielaard c858e5
+         UInt dM = dregEnc(i->ARM64in.VTriD.arg2);
Mark Wielaard c858e5
+         UInt dA = dregEnc(i->ARM64in.VTriD.arg3);
Mark Wielaard c858e5
+         UInt b15 = 2; /* impossible */
Mark Wielaard c858e5
+         switch (i->ARM64in.VTriD.op) {
Mark Wielaard c858e5
+            case ARM64fpt_FMADD: b15 = 0; break;
Mark Wielaard c858e5
+            case ARM64fpt_FMSUB: b15 = 1; break;
Mark Wielaard c858e5
+            default: goto bad;
Mark Wielaard c858e5
+         }
Mark Wielaard c858e5
+         vassert(b15 < 2);
Mark Wielaard c858e5
+         *p++ = X_3_8_5_1_5_5_5(X000, X11111010, dM, b15, dA, dN, dD);
Mark Wielaard c858e5
+         goto done;
Mark Wielaard c858e5
+      }
Mark Wielaard c858e5
+      case ARM64in_VTriS: {
Mark Wielaard c858e5
+         /* 31            20 15 14 9 4
Mark Wielaard c858e5
+            000 11111 000 m  0  a  n d FMADD  Dd,Dn,Dm,Da
Mark Wielaard c858e5
+            ---------------- 1  ------ FMSUB  -----------
Mark Wielaard c858e5
+         */
Mark Wielaard c858e5
+         UInt dD = dregEnc(i->ARM64in.VTriD.dst);
Mark Wielaard c858e5
+         UInt dN = dregEnc(i->ARM64in.VTriD.arg1);
Mark Wielaard c858e5
+         UInt dM = dregEnc(i->ARM64in.VTriD.arg2);
Mark Wielaard c858e5
+         UInt dA = dregEnc(i->ARM64in.VTriD.arg3);
Mark Wielaard c858e5
+         UInt b15 = 2; /* impossible */
Mark Wielaard c858e5
+         switch (i->ARM64in.VTriD.op) {
Mark Wielaard c858e5
+            case ARM64fpt_FMADD: b15 = 0; break;
Mark Wielaard c858e5
+            case ARM64fpt_FMSUB: b15 = 1; break;
Mark Wielaard c858e5
+            default: goto bad;
Mark Wielaard c858e5
+         }
Mark Wielaard c858e5
+         vassert(b15 < 2);
Mark Wielaard c858e5
+         *p++ = X_3_8_5_1_5_5_5(X000, X11111000, dM, b15, dA, dN, dD);
Mark Wielaard c858e5
+         goto done;
Mark Wielaard c858e5
+      }
Mark Wielaard c858e5
       case ARM64in_VCmpD: {
Mark Wielaard c858e5
          /* 000 11110 01 1 m 00 1000 n 00 000  FCMP Dn, Dm */
Mark Wielaard c858e5
          UInt dN = dregEnc(i->ARM64in.VCmpD.argL);
Mark Wielaard c858e5
diff --git a/VEX/priv/host_arm64_defs.h b/VEX/priv/host_arm64_defs.h
Mark Wielaard c858e5
index 05dba7ab8..5a82564ce 100644
Mark Wielaard c858e5
--- a/VEX/priv/host_arm64_defs.h
Mark Wielaard c858e5
+++ b/VEX/priv/host_arm64_defs.h
Mark Wielaard c858e5
@@ -289,6 +289,14 @@ typedef
Mark Wielaard c858e5
    }
Mark Wielaard c858e5
    ARM64FpBinOp;
Mark Wielaard c858e5
 
Mark Wielaard c858e5
+typedef
Mark Wielaard c858e5
+   enum {
Mark Wielaard c858e5
+      ARM64fpt_FMADD=105,
Mark Wielaard c858e5
+      ARM64fpt_FMSUB,
Mark Wielaard c858e5
+      ARM64fpt_INVALID
Mark Wielaard c858e5
+   }
Mark Wielaard c858e5
+   ARM64FpTriOp;
Mark Wielaard c858e5
+
Mark Wielaard c858e5
 typedef
Mark Wielaard c858e5
    enum {
Mark Wielaard c858e5
       ARM64fpu_NEG=110,
Mark Wielaard c858e5
@@ -498,6 +506,8 @@ typedef
Mark Wielaard c858e5
       ARM64in_VUnaryS,
Mark Wielaard c858e5
       ARM64in_VBinD,
Mark Wielaard c858e5
       ARM64in_VBinS,
Mark Wielaard c858e5
+      ARM64in_VTriD,
Mark Wielaard c858e5
+      ARM64in_VTriS,
Mark Wielaard c858e5
       ARM64in_VCmpD,
Mark Wielaard c858e5
       ARM64in_VCmpS,
Mark Wielaard c858e5
       ARM64in_VFCSel,
Mark Wielaard c858e5
@@ -799,6 +809,22 @@ typedef
Mark Wielaard c858e5
             HReg         argL;
Mark Wielaard c858e5
             HReg         argR;
Mark Wielaard c858e5
          } VBinS;
Mark Wielaard c858e5
+         /* 64-bit FP ternary arithmetic */
Mark Wielaard c858e5
+         struct {
Mark Wielaard c858e5
+            ARM64FpTriOp op;
Mark Wielaard c858e5
+            HReg         dst;
Mark Wielaard c858e5
+            HReg         arg1;
Mark Wielaard c858e5
+            HReg         arg2;
Mark Wielaard c858e5
+            HReg         arg3;
Mark Wielaard c858e5
+         } VTriD;
Mark Wielaard c858e5
+         /* 32-bit FP ternary arithmetic */
Mark Wielaard c858e5
+         struct {
Mark Wielaard c858e5
+            ARM64FpTriOp op;
Mark Wielaard c858e5
+            HReg         dst;
Mark Wielaard c858e5
+            HReg         arg1;
Mark Wielaard c858e5
+            HReg         arg2;
Mark Wielaard c858e5
+            HReg         arg3;
Mark Wielaard c858e5
+         } VTriS;
Mark Wielaard c858e5
          /* 64-bit FP compare */
Mark Wielaard c858e5
          struct {
Mark Wielaard c858e5
             HReg argL;
Mark Wielaard c858e5
@@ -970,6 +996,10 @@ extern ARM64Instr* ARM64Instr_VUnaryD ( ARM64FpUnaryOp op, HReg dst, HReg src );
Mark Wielaard c858e5
 extern ARM64Instr* ARM64Instr_VUnaryS ( ARM64FpUnaryOp op, HReg dst, HReg src );
Mark Wielaard c858e5
 extern ARM64Instr* ARM64Instr_VBinD   ( ARM64FpBinOp op, HReg, HReg, HReg );
Mark Wielaard c858e5
 extern ARM64Instr* ARM64Instr_VBinS   ( ARM64FpBinOp op, HReg, HReg, HReg );
Mark Wielaard c858e5
+extern ARM64Instr* ARM64Instr_VTriD   ( ARM64FpTriOp op, HReg dst,
Mark Wielaard c858e5
+                                        HReg, HReg, HReg );
Mark Wielaard c858e5
+extern ARM64Instr* ARM64Instr_VTriS   ( ARM64FpTriOp op, HReg dst,
Mark Wielaard c858e5
+                                        HReg, HReg, HReg );
Mark Wielaard c858e5
 extern ARM64Instr* ARM64Instr_VCmpD   ( HReg argL, HReg argR );
Mark Wielaard c858e5
 extern ARM64Instr* ARM64Instr_VCmpS   ( HReg argL, HReg argR );
Mark Wielaard c858e5
 extern ARM64Instr* ARM64Instr_VFCSel  ( HReg dst, HReg argL, HReg argR,
Mark Wielaard c858e5
diff --git a/VEX/priv/host_arm64_isel.c b/VEX/priv/host_arm64_isel.c
Mark Wielaard c858e5
index 2f19eab81..da1218715 100644
Mark Wielaard c858e5
--- a/VEX/priv/host_arm64_isel.c
Mark Wielaard c858e5
+++ b/VEX/priv/host_arm64_isel.c
Mark Wielaard c858e5
@@ -3255,6 +3255,25 @@ static HReg iselDblExpr_wrk ( ISelEnv* env, IRExpr* e )
Mark Wielaard c858e5
       }
Mark Wielaard c858e5
    }
Mark Wielaard c858e5
 
Mark Wielaard c858e5
+   if (e->tag == Iex_Qop) {
Mark Wielaard c858e5
+      IRQop*       qop = e->Iex.Qop.details;
Mark Wielaard c858e5
+      ARM64FpTriOp triop = ARM64fpt_INVALID;
Mark Wielaard c858e5
+      switch (qop->op) {
Mark Wielaard c858e5
+         case Iop_MAddF64: triop = ARM64fpt_FMADD; break;
Mark Wielaard c858e5
+         case Iop_MSubF64: triop = ARM64fpt_FMSUB; break;
Mark Wielaard c858e5
+         default: break;
Mark Wielaard c858e5
+      }
Mark Wielaard c858e5
+      if (triop != ARM64fpt_INVALID) {
Mark Wielaard c858e5
+         HReg N = iselDblExpr(env, qop->arg2);
Mark Wielaard c858e5
+         HReg M = iselDblExpr(env, qop->arg3);
Mark Wielaard c858e5
+         HReg A = iselDblExpr(env, qop->arg4);
Mark Wielaard c858e5
+         HReg dst  = newVRegD(env);
Mark Wielaard c858e5
+         set_FPCR_rounding_mode(env, qop->arg1);
Mark Wielaard c858e5
+         addInstr(env, ARM64Instr_VTriD(triop, dst, N, M, A));
Mark Wielaard c858e5
+         return dst;
Mark Wielaard c858e5
+      }
Mark Wielaard c858e5
+   }
Mark Wielaard c858e5
+
Mark Wielaard c858e5
    if (e->tag == Iex_ITE) {
Mark Wielaard c858e5
       /* ITE(ccexpr, iftrue, iffalse) */
Mark Wielaard c858e5
       ARM64CondCode cc;
Mark Wielaard c858e5
@@ -3450,6 +3469,26 @@ static HReg iselFltExpr_wrk ( ISelEnv* env, IRExpr* e )
Mark Wielaard c858e5
       return dst;
Mark Wielaard c858e5
    }
Mark Wielaard c858e5
 
Mark Wielaard c858e5
+   if (e->tag == Iex_Qop) {
Mark Wielaard c858e5
+      IRQop*       qop = e->Iex.Qop.details;
Mark Wielaard c858e5
+      ARM64FpTriOp triop = ARM64fpt_INVALID;
Mark Wielaard c858e5
+      switch (qop->op) {
Mark Wielaard c858e5
+         case Iop_MAddF32: triop = ARM64fpt_FMADD; break;
Mark Wielaard c858e5
+         case Iop_MSubF32: triop = ARM64fpt_FMSUB; break;
Mark Wielaard c858e5
+      default: break;
Mark Wielaard c858e5
+      }
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+      if (triop != ARM64fpt_INVALID) {
Mark Wielaard c858e5
+         HReg N = iselFltExpr(env, qop->arg2);
Mark Wielaard c858e5
+         HReg M = iselFltExpr(env, qop->arg3);
Mark Wielaard c858e5
+         HReg A = iselFltExpr(env, qop->arg4);
Mark Wielaard c858e5
+         HReg dst  = newVRegD(env);
Mark Wielaard c858e5
+         set_FPCR_rounding_mode(env, qop->arg1);
Mark Wielaard c858e5
+         addInstr(env, ARM64Instr_VTriS(triop, dst, N, M, A));
Mark Wielaard c858e5
+         return dst;
Mark Wielaard c858e5
+      }
Mark Wielaard c858e5
+   }
Mark Wielaard c858e5
+
Mark Wielaard c858e5
    ppIRExpr(e);
Mark Wielaard c858e5
    vpanic("iselFltExpr_wrk");
Mark Wielaard c858e5
 }
Mark Wielaard c858e5
diff --git a/none/tests/arm64/Makefile.am b/none/tests/arm64/Makefile.am
Mark Wielaard c858e5
index 7b3ebbdca..4ecab36ad 100644
Mark Wielaard c858e5
--- a/none/tests/arm64/Makefile.am
Mark Wielaard c858e5
+++ b/none/tests/arm64/Makefile.am
Mark Wielaard c858e5
@@ -10,14 +10,16 @@ EXTRA_DIST = \
Mark Wielaard c858e5
 	integer.stdout.exp integer.stderr.exp integer.vgtest \
Mark Wielaard c858e5
 	memory.stdout.exp memory.stderr.exp memory.vgtest \
Mark Wielaard c858e5
 	atomics_v81.stdout.exp atomics_v81.stderr.exp atomics_v81.vgtest \
Mark Wielaard c858e5
-	simd_v81.stdout.exp simd_v81.stderr.exp simd_v81.vgtest
Mark Wielaard c858e5
+	simd_v81.stdout.exp simd_v81.stderr.exp simd_v81.vgtest \
Mark Wielaard c858e5
+        fmadd_sub.stdout.exp fmadd_sub.stderr.exp fmadd_sub.vgtest
Mark Wielaard c858e5
 
Mark Wielaard c858e5
 check_PROGRAMS = \
Mark Wielaard c858e5
 	allexec \
Mark Wielaard c858e5
         cvtf_imm \
Mark Wielaard c858e5
 	fp_and_simd \
Mark Wielaard c858e5
 	integer \
Mark Wielaard c858e5
-	memory
Mark Wielaard c858e5
+	memory \
Mark Wielaard c858e5
+	fmadd_sub
Mark Wielaard c858e5
 
Mark Wielaard c858e5
 if BUILD_ARMV8_CRC_TESTS
Mark Wielaard c858e5
   check_PROGRAMS += crc32
Mark Wielaard c858e5
diff --git a/none/tests/arm64/fmadd_sub.c b/none/tests/arm64/fmadd_sub.c
Mark Wielaard c858e5
new file mode 100644
Mark Wielaard c858e5
index 000000000..dcab22d1b
Mark Wielaard c858e5
--- /dev/null
Mark Wielaard c858e5
+++ b/none/tests/arm64/fmadd_sub.c
Mark Wielaard c858e5
@@ -0,0 +1,98 @@
Mark Wielaard c858e5
+#include <math.h>
Mark Wielaard c858e5
+#include <stdint.h>
Mark Wielaard c858e5
+#include <stdio.h>
Mark Wielaard c858e5
+#include <stdlib.h>
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+#define COUNT 5
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+static void
Mark Wielaard c858e5
+print_float(const char *ident, float x)
Mark Wielaard c858e5
+{
Mark Wielaard c858e5
+  union
Mark Wielaard c858e5
+  {
Mark Wielaard c858e5
+    float f;
Mark Wielaard c858e5
+    uint32_t i;
Mark Wielaard c858e5
+  } u;
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+  u.f = x;
Mark Wielaard c858e5
+  printf("%s = %08x = %.17g\n", ident, u.i, x);
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+static void
Mark Wielaard c858e5
+print_double(const char *ident, double x)
Mark Wielaard c858e5
+{
Mark Wielaard c858e5
+  union
Mark Wielaard c858e5
+  {
Mark Wielaard c858e5
+    double f;
Mark Wielaard c858e5
+    uint64_t i;
Mark Wielaard c858e5
+  } u;
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+  u.f = x;
Mark Wielaard c858e5
+  printf("%s = %016lx = %.17g\n", ident, u.i, x);
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+int
Mark Wielaard c858e5
+main(int argc, char **argv)
Mark Wielaard c858e5
+{
Mark Wielaard c858e5
+  float x[] = { 55,                  0.98076171874999996, 0, 1, 0xFFFFFFFF } ;
Mark Wielaard c858e5
+  float y[] = { 0.69314718055994529, 1.015625,            0, 1, 0xFFFFFFFF };
Mark Wielaard c858e5
+  float z[] = { 38.123094930796988,  1,                   0, 1, 0xFFFFFFFF };
Mark Wielaard c858e5
+  float dst = -5;
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+  double dx[] = { 55,                  0.98076171874999996, 0, 1, 0xFFFFFFFF } ;
Mark Wielaard c858e5
+  double dy[] = { 0.69314718055994529, 1.015625,            0, 1, 0xFFFFFFFF };
Mark Wielaard c858e5
+  double dz[] = { 38.123094930796988,  1,                   0, 1, 0xFFFFFFFF };
Mark Wielaard c858e5
+  double ddst= -5;
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+  int i;
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+  for (i = 0; i < COUNT; i++) {
Mark Wielaard c858e5
+	  //32bit variant
Mark Wielaard c858e5
+	  asm("fmadd %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
Mark Wielaard c858e5
+	  printf("FMADD 32bit: dst = z + x * y\n");
Mark Wielaard c858e5
+	  printf("%f = %f + %f * %f\n", dst, z[i], x[i], y[i]);
Mark Wielaard c858e5
+	  print_float("dst", dst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  // Floating-point negated fused multiply-add
Mark Wielaard c858e5
+	  asm("fnmadd %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
Mark Wielaard c858e5
+	  printf("FNMADD 32bit: dst = -z + (-x) * y\n");
Mark Wielaard c858e5
+	  printf("%f = -%f + (-%f) * %f\n", dst, z[i], x[i], y[i]);
Mark Wielaard c858e5
+	  print_float("dst", dst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  asm("fmsub %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
Mark Wielaard c858e5
+	  printf("FMSUB 32bit: dst = z + (-x) * y\n");
Mark Wielaard c858e5
+	  printf("%f = %f + (-%f) * %f\n", dst, z[i], x[i], y[i]);
Mark Wielaard c858e5
+	  print_float("dst", dst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  asm("fnmsub %s0, %s1, %s2, %s3\n;" : "=w"(dst) : "w"(x[i]), "w"(y[i]), "w"(z[i]));
Mark Wielaard c858e5
+	  printf("FNMSUB 32bit: dst = -z + x * y\n");
Mark Wielaard c858e5
+	  printf("%f = -%f + %f * %f\n", dst, z[i], x[i], y[i]);
Mark Wielaard c858e5
+	  print_float("dst", dst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  //64bit variant
Mark Wielaard c858e5
+	  asm("fmadd %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
Mark Wielaard c858e5
+	  printf("FMADD 64bit: dst = z + x * y\n");
Mark Wielaard c858e5
+	  printf("%f = %f + %f * %f\n", ddst, dz[i], dx[i], dy[i]);
Mark Wielaard c858e5
+	  print_double("dst", ddst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  asm("fnmadd %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
Mark Wielaard c858e5
+	  printf("FNMADD 64bit: dst = -z + (-x) * y\n");
Mark Wielaard c858e5
+	  printf("%f = -%f - %f * %f\n", ddst, dz[i], dx[i], dy[i]);
Mark Wielaard c858e5
+	  print_double("dst", ddst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  asm("fmsub %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
Mark Wielaard c858e5
+	  printf("FMSUB 64bit: dst = z + (-x) * y\n");
Mark Wielaard c858e5
+	  printf("%f = %f + (-%f) * %f\n", ddst, dz[i], dx[i], dy[i]);
Mark Wielaard c858e5
+	  print_double("dst", ddst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  asm("fnmsub %d0, %d1, %d2, %d3\n;" : "=w"(ddst) : "w"(dx[i]), "w"(dy[i]), "w"(dz[i]));
Mark Wielaard c858e5
+	  printf("FNMSUB 64bit: dst = -z + x * y\n");
Mark Wielaard c858e5
+	  printf("%f = -%f + %f * %f\n", ddst, dz[i], dx[i], dy[i]);
Mark Wielaard c858e5
+	  print_double("dst", ddst);
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+	  printf("\n");
Mark Wielaard c858e5
+  }
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+  return 0;
Mark Wielaard c858e5
+}
Mark Wielaard c858e5
+
Mark Wielaard c858e5
diff --git a/none/tests/arm64/fmadd_sub.stderr.exp b/none/tests/arm64/fmadd_sub.stderr.exp
Mark Wielaard c858e5
new file mode 100644
Mark Wielaard c858e5
index 000000000..e69de29bb
Mark Wielaard c858e5
diff --git a/none/tests/arm64/fmadd_sub.stdout.exp b/none/tests/arm64/fmadd_sub.stdout.exp
Mark Wielaard c858e5
new file mode 100644
Mark Wielaard c858e5
index 000000000..f1824b12b
Mark Wielaard c858e5
--- /dev/null
Mark Wielaard c858e5
+++ b/none/tests/arm64/fmadd_sub.stdout.exp
Mark Wielaard c858e5
@@ -0,0 +1,125 @@
Mark Wielaard c858e5
+FMADD 32bit: dst = z + x * y
Mark Wielaard c858e5
+76.246193 = 38.123096 + 55.000000 * 0.693147
Mark Wielaard c858e5
+dst = 42987e0d = 76.246192932128906
Mark Wielaard c858e5
+FNMADD 32bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-76.246193 = -38.123096 + (-55.000000) * 0.693147
Mark Wielaard c858e5
+dst = c2987e0d = -76.246192932128906
Mark Wielaard c858e5
+FMSUB 32bit: dst = z + (-x) * y
Mark Wielaard c858e5
+0.000001 = 38.123096 + (-55.000000) * 0.693147
Mark Wielaard c858e5
+dst = 35c00000 = 1.430511474609375e-06
Mark Wielaard c858e5
+FNMSUB 32bit: dst = -z + x * y
Mark Wielaard c858e5
+-0.000001 = -38.123096 + 55.000000 * 0.693147
Mark Wielaard c858e5
+dst = b5c00000 = -1.430511474609375e-06
Mark Wielaard c858e5
+FMADD 64bit: dst = z + x * y
Mark Wielaard c858e5
+76.246190 = 38.123095 + 55.000000 * 0.693147
Mark Wielaard c858e5
+dst = 40530fc1931f09c9 = 76.246189861593976
Mark Wielaard c858e5
+FNMADD 64bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-76.246190 = -38.123095 - 55.000000 * 0.693147
Mark Wielaard c858e5
+dst = c0530fc1931f09c9 = -76.246189861593976
Mark Wielaard c858e5
+FMSUB 64bit: dst = z + (-x) * y
Mark Wielaard c858e5
+-0.000000 = 38.123095 + (-55.000000) * 0.693147
Mark Wielaard c858e5
+dst = bce9000000000000 = -2.7755575615628914e-15
Mark Wielaard c858e5
+FNMSUB 64bit: dst = -z + x * y
Mark Wielaard c858e5
+0.000000 = -38.123095 + 55.000000 * 0.693147
Mark Wielaard c858e5
+dst = 3ce9000000000000 = 2.7755575615628914e-15
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+FMADD 32bit: dst = z + x * y
Mark Wielaard c858e5
+1.996086 = 1.000000 + 0.980762 * 1.015625
Mark Wielaard c858e5
+dst = 3fff7fc0 = 1.9960861206054688
Mark Wielaard c858e5
+FNMADD 32bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-1.996086 = -1.000000 + (-0.980762) * 1.015625
Mark Wielaard c858e5
+dst = bfff7fc0 = -1.9960861206054688
Mark Wielaard c858e5
+FMSUB 32bit: dst = z + (-x) * y
Mark Wielaard c858e5
+0.003914 = 1.000000 + (-0.980762) * 1.015625
Mark Wielaard c858e5
+dst = 3b80401a = 0.00391389150172472
Mark Wielaard c858e5
+FNMSUB 32bit: dst = -z + x * y
Mark Wielaard c858e5
+-0.003914 = -1.000000 + 0.980762 * 1.015625
Mark Wielaard c858e5
+dst = bb80401a = -0.00391389150172472
Mark Wielaard c858e5
+FMADD 64bit: dst = z + x * y
Mark Wielaard c858e5
+1.996086 = 1.000000 + 0.980762 * 1.015625
Mark Wielaard c858e5
+dst = 3fffeff800000000 = 1.9960861206054688
Mark Wielaard c858e5
+FNMADD 64bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-1.996086 = -1.000000 - 0.980762 * 1.015625
Mark Wielaard c858e5
+dst = bfffeff800000000 = -1.9960861206054688
Mark Wielaard c858e5
+FMSUB 64bit: dst = z + (-x) * y
Mark Wielaard c858e5
+0.003914 = 1.000000 + (-0.980762) * 1.015625
Mark Wielaard c858e5
+dst = 3f70080000000034 = 0.0039138793945312951
Mark Wielaard c858e5
+FNMSUB 64bit: dst = -z + x * y
Mark Wielaard c858e5
+-0.003914 = -1.000000 + 0.980762 * 1.015625
Mark Wielaard c858e5
+dst = bf70080000000034 = -0.0039138793945312951
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+FMADD 32bit: dst = z + x * y
Mark Wielaard c858e5
+0.000000 = 0.000000 + 0.000000 * 0.000000
Mark Wielaard c858e5
+dst = 00000000 = 0
Mark Wielaard c858e5
+FNMADD 32bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-0.000000 = -0.000000 + (-0.000000) * 0.000000
Mark Wielaard c858e5
+dst = 80000000 = -0
Mark Wielaard c858e5
+FMSUB 32bit: dst = z + (-x) * y
Mark Wielaard c858e5
+0.000000 = 0.000000 + (-0.000000) * 0.000000
Mark Wielaard c858e5
+dst = 00000000 = 0
Mark Wielaard c858e5
+FNMSUB 32bit: dst = -z + x * y
Mark Wielaard c858e5
+0.000000 = -0.000000 + 0.000000 * 0.000000
Mark Wielaard c858e5
+dst = 00000000 = 0
Mark Wielaard c858e5
+FMADD 64bit: dst = z + x * y
Mark Wielaard c858e5
+0.000000 = 0.000000 + 0.000000 * 0.000000
Mark Wielaard c858e5
+dst = 0000000000000000 = 0
Mark Wielaard c858e5
+FNMADD 64bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-0.000000 = -0.000000 - 0.000000 * 0.000000
Mark Wielaard c858e5
+dst = 8000000000000000 = -0
Mark Wielaard c858e5
+FMSUB 64bit: dst = z + (-x) * y
Mark Wielaard c858e5
+0.000000 = 0.000000 + (-0.000000) * 0.000000
Mark Wielaard c858e5
+dst = 0000000000000000 = 0
Mark Wielaard c858e5
+FNMSUB 64bit: dst = -z + x * y
Mark Wielaard c858e5
+0.000000 = -0.000000 + 0.000000 * 0.000000
Mark Wielaard c858e5
+dst = 0000000000000000 = 0
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+FMADD 32bit: dst = z + x * y
Mark Wielaard c858e5
+2.000000 = 1.000000 + 1.000000 * 1.000000
Mark Wielaard c858e5
+dst = 40000000 = 2
Mark Wielaard c858e5
+FNMADD 32bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-2.000000 = -1.000000 + (-1.000000) * 1.000000
Mark Wielaard c858e5
+dst = c0000000 = -2
Mark Wielaard c858e5
+FMSUB 32bit: dst = z + (-x) * y
Mark Wielaard c858e5
+0.000000 = 1.000000 + (-1.000000) * 1.000000
Mark Wielaard c858e5
+dst = 00000000 = 0
Mark Wielaard c858e5
+FNMSUB 32bit: dst = -z + x * y
Mark Wielaard c858e5
+0.000000 = -1.000000 + 1.000000 * 1.000000
Mark Wielaard c858e5
+dst = 00000000 = 0
Mark Wielaard c858e5
+FMADD 64bit: dst = z + x * y
Mark Wielaard c858e5
+2.000000 = 1.000000 + 1.000000 * 1.000000
Mark Wielaard c858e5
+dst = 4000000000000000 = 2
Mark Wielaard c858e5
+FNMADD 64bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-2.000000 = -1.000000 - 1.000000 * 1.000000
Mark Wielaard c858e5
+dst = c000000000000000 = -2
Mark Wielaard c858e5
+FMSUB 64bit: dst = z + (-x) * y
Mark Wielaard c858e5
+0.000000 = 1.000000 + (-1.000000) * 1.000000
Mark Wielaard c858e5
+dst = 0000000000000000 = 0
Mark Wielaard c858e5
+FNMSUB 64bit: dst = -z + x * y
Mark Wielaard c858e5
+0.000000 = -1.000000 + 1.000000 * 1.000000
Mark Wielaard c858e5
+dst = 0000000000000000 = 0
Mark Wielaard c858e5
+
Mark Wielaard c858e5
+FMADD 32bit: dst = z + x * y
Mark Wielaard c858e5
+18446744073709551616.000000 = 4294967296.000000 + 4294967296.000000 * 4294967296.000000
Mark Wielaard c858e5
+dst = 5f800000 = 1.8446744073709552e+19
Mark Wielaard c858e5
+FNMADD 32bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-18446744073709551616.000000 = -4294967296.000000 + (-4294967296.000000) * 4294967296.000000
Mark Wielaard c858e5
+dst = df800000 = -1.8446744073709552e+19
Mark Wielaard c858e5
+FMSUB 32bit: dst = z + (-x) * y
Mark Wielaard c858e5
+-18446744073709551616.000000 = 4294967296.000000 + (-4294967296.000000) * 4294967296.000000
Mark Wielaard c858e5
+dst = df800000 = -1.8446744073709552e+19
Mark Wielaard c858e5
+FNMSUB 32bit: dst = -z + x * y
Mark Wielaard c858e5
+18446744073709551616.000000 = -4294967296.000000 + 4294967296.000000 * 4294967296.000000
Mark Wielaard c858e5
+dst = 5f800000 = 1.8446744073709552e+19
Mark Wielaard c858e5
+FMADD 64bit: dst = z + x * y
Mark Wielaard c858e5
+18446744069414584320.000000 = 4294967295.000000 + 4294967295.000000 * 4294967295.000000
Mark Wielaard c858e5
+dst = 43efffffffe00000 = 1.8446744069414584e+19
Mark Wielaard c858e5
+FNMADD 64bit: dst = -z + (-x) * y
Mark Wielaard c858e5
+-18446744069414584320.000000 = -4294967295.000000 - 4294967295.000000 * 4294967295.000000
Mark Wielaard c858e5
+dst = c3efffffffe00000 = -1.8446744069414584e+19
Mark Wielaard c858e5
+FMSUB 64bit: dst = z + (-x) * y
Mark Wielaard c858e5
+-18446744060824649728.000000 = 4294967295.000000 + (-4294967295.000000) * 4294967295.000000
Mark Wielaard c858e5
+dst = c3efffffffa00000 = -1.844674406082465e+19
Mark Wielaard c858e5
+FNMSUB 64bit: dst = -z + x * y
Mark Wielaard c858e5
+18446744060824649728.000000 = -4294967295.000000 + 4294967295.000000 * 4294967295.000000
Mark Wielaard c858e5
+dst = 43efffffffa00000 = 1.844674406082465e+19
Mark Wielaard c858e5
+
Mark Wielaard c858e5
diff --git a/none/tests/arm64/fmadd_sub.vgtest b/none/tests/arm64/fmadd_sub.vgtest
Mark Wielaard c858e5
new file mode 100644
Mark Wielaard c858e5
index 000000000..b4c53eea4
Mark Wielaard c858e5
--- /dev/null
Mark Wielaard c858e5
+++ b/none/tests/arm64/fmadd_sub.vgtest
Mark Wielaard c858e5
@@ -0,0 +1,3 @@
Mark Wielaard c858e5
+prog: fmadd_sub
Mark Wielaard c858e5
+prereq: test -x fmadd_sub
Mark Wielaard c858e5
+vgopts: -q
Mark Wielaard c858e5
-- 
Mark Wielaard c858e5
2.18.4
Mark Wielaard c858e5
Mark Wielaard 14c0a5
diff --git a/VEX/priv/guest_generic_bb_to_IR.c b/VEX/priv/guest_generic_bb_to_IR.c
Mark Wielaard 14c0a5
index 0cee970e4..1e72ddacd 100644
Mark Wielaard 14c0a5
--- a/VEX/priv/guest_generic_bb_to_IR.c
Mark Wielaard 14c0a5
+++ b/VEX/priv/guest_generic_bb_to_IR.c
Mark Wielaard 14c0a5
@@ -422,6 +422,8 @@ static Bool expr_is_guardable ( const IRExpr* e )
Mark Wielaard 14c0a5
          return !primopMightTrap(e->Iex.Binop.op);
Mark Wielaard 14c0a5
       case Iex_Triop:
Mark Wielaard 14c0a5
          return !primopMightTrap(e->Iex.Triop.details->op);
Mark Wielaard 14c0a5
+      case Iex_Qop:
Mark Wielaard 14c0a5
+         return !primopMightTrap(e->Iex.Qop.details->op);
Mark Wielaard 14c0a5
       case Iex_ITE:
Mark Wielaard 14c0a5
       case Iex_CCall:
Mark Wielaard 14c0a5
       case Iex_Get: