From f2b9817e66686f162a2aafc989795eee424861d5 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 14 May 2021 18:28:31 +0100 Subject: [PATCH] add very quick float convert to SelectableInt --- src/openpower/decoder/selectable_int.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/openpower/decoder/selectable_int.py b/src/openpower/decoder/selectable_int.py index 1481f289..c997acd5 100644 --- a/src/openpower/decoder/selectable_int.py +++ b/src/openpower/decoder/selectable_int.py @@ -1,4 +1,5 @@ import unittest +import struct from copy import copy from openpower.decoder.power_fields import BitRange from operator import (add, sub, mul, floordiv, truediv, mod, or_, and_, xor, @@ -416,6 +417,14 @@ class SelectableInt: def asint(self): return self.value + def __float__(self): + """convert to double-precision float. TODO, properly convert + rather than a hack-job: must actually support Power IEEE754 FP + """ + assert self.bits == 64 # must be 64-bit + data = self.value.to_bytes(8, byteorder='little') + return struct.unpack('