================
@@ -5865,257 +5933,2301 @@ DoubleAPFloat frexp(const DoubleAPFloat &Arg, int 
&Exp,
                        std::move(Second));
 }
 
-} // namespace detail
-
-APFloat::Storage::Storage(IEEEFloat F, const fltSemantics &Semantics) {
-  if (usesLayout<IEEEFloat>(Semantics)) {
-    new (&IEEE) IEEEFloat(std::move(F));
-    return;
-  }
-  if (usesLayout<DoubleAPFloat>(Semantics)) {
-    const fltSemantics& S = F.getSemantics();
-    new (&Double) DoubleAPFloat(Semantics, APFloat(std::move(F), S),
-                                APFloat(APFloatBase::IEEEdouble()));
-    return;
-  }
-  llvm_unreachable("Unexpected semantics");
-}
+// class HexFloatArith implements HFP arithmetic using the conventions
+// and approaches of the arith library used by the IBM XL compiler,
+// and matches the behaviour of the hardware.
+class HexFloatArith {
+public:
+  struct value_t {
+    int sign; // -1 for negative, +1 for positive
+    int exponent;
+    APInt fraction;
+  };
+  static void fetch(const HexFloat &in, value_t &out);
+  static void align(value_t &, value_t &, bool sticky = false);
+  static void add(value_t &, const value_t &);
+  static void sub(value_t &, const value_t &);
+  static void mult(value_t &, const value_t &);
+  static void divide(value_t &, const value_t &);
+  static void norm(value_t &);
+  static int putres(const value_t &, HexFloat &);
+};
 
-Expected<APFloat::opStatus> APFloat::convertFromString(StringRef Str,
-                                                       roundingMode RM) {
-  APFLOAT_DISPATCH_ON_SEMANTICS(convertFromString(Str, RM));
+unsigned int HexFloat::getNumPrecisionBits(const fltSemantics *semantics) {
+  assert(APFloat::usesLayout<HexFloat>(*semantics) && "not a HexFloat");
+  return 4 * semantics->precision;
----------------
Ariel-Burton wrote:

I've added a comment.  Basically, the precision in the fltSemantics is in terms 
of the radix.  For HexFloat the radix is 16, so the number of bits required for 
a precision base-16 places is 4 times the number of places.

https://github.com/llvm/llvm-project/pull/179771
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to