diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-11-06 23:46:46 +0100 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-11-06 23:46:46 +0100 |
| commit | b191b499fee5a9c992432213a18e9114c70bd9d4 (patch) | |
| tree | a24c9e0df282ef3998a421d59fcc40dcd21e3152 | |
| parent | 5f2fbf712e222258d5e939dcf474e8039a93fa87 (diff) | |
| download | focaccia-b191b499fee5a9c992432213a18e9114c70bd9d4.tar.gz focaccia-b191b499fee5a9c992432213a18e9114c70bd9d4.zip | |
Add helper to convert single precision to double precision
Needed for CVTPS2PD instruction
| -rw-r--r-- | src/focaccia/miasm_util.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/focaccia/miasm_util.py b/src/focaccia/miasm_util.py index 8e9d1ed..878683b 100644 --- a/src/focaccia/miasm_util.py +++ b/src/focaccia/miasm_util.py @@ -86,10 +86,27 @@ def simp_fsub(expr_simp, expr: ExprOp): return expr_simp(ExprInt(res, expr.size)) return expr +def simp_fpconvert_fp64(expr_simp, expr: ExprOp): + from .utils import float_bits_to_uint, uint_bits_to_float, \ + double_bits_to_uint, uint_bits_to_double + + if expr.op != 'fpconvert_fp64': + return expr + + assert(len(expr.args) == 1) + operand = expr.args[0] + if operand.is_int(): + if not operand.size == 32: + raise NotImplementedError('fpconvert_fp64 on values of size not in 64') + + res = double_bits_to_uint(uint_bits_to_double(float_bits_to_uint(operand.arg))) + return expr_simp(ExprInt(res, 64)) + return expr + # The expression simplifier used in this module expr_simp = expr_simp_explicit expr_simp.enable_passes({ - ExprOp: [simp_segm, simp_fadd, simp_fsub], + ExprOp: [simp_segm, simp_fadd, simp_fsub, simp_fpconvert_fp64], }) class MiasmSymbolResolver: |