about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/arch/x86/arch.py10
-rw-r--r--miasm2/arch/x86/sem.py42
-rw-r--r--test/arch/x86/arch.py10
3 files changed, 62 insertions, 0 deletions
diff --git a/miasm2/arch/x86/arch.py b/miasm2/arch/x86/arch.py
index daa68ced..af79ea97 100644
--- a/miasm2/arch/x86/arch.py
+++ b/miasm2/arch/x86/arch.py
@@ -4230,6 +4230,16 @@ addop("pextrw", [bs8(0x0f), bs8(0xc5), pref_66] +
       rmmod(xmm_reg, rm_arg_reg_m16) + [u08], [rm_arg_reg_m16, xmm_reg, u08])
 
 
+addop("sqrtpd", [bs8(0x0f), bs8(0x51), pref_66] +
+      rmmod(xmm_reg, rm_arg_xmm))
+addop("sqrtps", [bs8(0x0f), bs8(0x51), no_xmm_pref] +
+      rmmod(xmm_reg, rm_arg_xmm))
+addop("sqrtsd", [bs8(0x0f), bs8(0x51), pref_f2] +
+      rmmod(xmm_reg, rm_arg_xmm_m64))
+addop("sqrtss", [bs8(0x0f), bs8(0x51), pref_f3] +
+      rmmod(xmm_reg, rm_arg_xmm_m32))
+
+
 mn_x86.bintree = factor_one_bit(mn_x86.bintree)
 # mn_x86.bintree = factor_fields_all(mn_x86.bintree)
 """
diff --git a/miasm2/arch/x86/sem.py b/miasm2/arch/x86/sem.py
index b4b03ac7..d3927821 100644
--- a/miasm2/arch/x86/sem.py
+++ b/miasm2/arch/x86/sem.py
@@ -3890,11 +3890,49 @@ def movhps(ir, instr, a, b):
     e.append(m2_expr.ExprAff(a[64:128], b[:64]))
     return e, []
 
+
 def movdq2q(ir, instr, a, b):
     e = []
     e.append(m2_expr.ExprAff(a, b[:64]))
     return e, []
 
+
+def sqrt_gen(ir, instr, a, b, size):
+    e = []
+    out = []
+    for i in b.size / size:
+        out.append((m2_expr.ExprOp('fsqrt' % size,
+                                   b[i * size: (i + 1) * size]),
+                    i * size, (i + 1) * size))
+    src = m2_expr.ExprCompose(out)
+    e.append(m2_expr.ExprAff(a, src))
+    return e, []
+
+
+def sqrtpd(ir, instr, a, b):
+    return sqrt_gen(ir, instr, a, b, 64)
+
+
+def sqrtps(ir, instr, a, b):
+    return sqrt_gen(ir, instr, a, b, 32)
+
+
+def sqrtsd(ir, instr, a, b):
+    e = []
+    e.append(m2_expr.ExprAff(a[:64],
+                             m2_expr.ExprOp('fsqrt',
+                                            b[:64])))
+    return e, []
+
+
+def sqrtss(ir, instr, a, b):
+    e = []
+    e.append(m2_expr.ExprAff(a[:32],
+                             m2_expr.ExprOp('fsqrt',
+                                            b[:32])))
+    return e, []
+
+
 mnemo_func = {'mov': mov,
               'xchg': xchg,
               'movzx': movzx,
@@ -4364,6 +4402,10 @@ mnemo_func = {'mov': mov,
               "movhlps": movlps,
               "movdq2q": movdq2q,
 
+              "sqrtpd": sqrtpd,
+              "sqrtps": sqrtps,
+              "sqrtsd": sqrtsd,
+              "sqrtss": sqrtss,
 
               }
 
diff --git a/test/arch/x86/arch.py b/test/arch/x86/arch.py
index 93668fd0..76d376d0 100644
--- a/test/arch/x86/arch.py
+++ b/test/arch/x86/arch.py
@@ -2837,6 +2837,16 @@ reg_tests = [
     (m32, "00000000    UNPCKLPD   XMM2, XMMWORD PTR [EDX]",
      "660f1412"),
 
+    (m32, "00000000    SQRTPD     XMM2, XMMWORD PTR [EDX]",
+     "660f5112"),
+    (m32, "00000000    SQRTPS     XMM2, XMMWORD PTR [EDX]",
+     "0f5112"),
+    (m32, "00000000    SQRTSD     XMM2, QWORD PTR [EDX]",
+     "F20f5112"),
+    (m32, "00000000    SQRTSS     XMM2, DWORD PTR [EDX]",
+     "F30f5112"),
+
+
 ]