[libc-commits] [PATCH] D105153: [libc] Add on float properties for precision floating point numbers in FloatProperties.h

Hedin GarcĂ­a via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jun 30 09:25:29 PDT 2021


hedingarcia updated this revision to Diff 355591.
hedingarcia added a comment.

[libc] Add on float properties for precision floating point numbers in FloatProperties.h

      

Defined constant that express the number of bits for exponent in single and double precision.
Added bit masks values and other properties for quad precision floating point numbers that
specifically targets architectures defined in PlatfromDefs.h.
The exponentWidth values were added to be used for a template struct in FPBits.h
where the implementation to set the sign component uses this and the mantissaWidth value.
The need occurred for the 80-bit quad precision implementation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D105153/new/

https://reviews.llvm.org/D105153

Files:
  libc/utils/FPUtil/FloatProperties.h


Index: libc/utils/FPUtil/FloatProperties.h
===================================================================
--- libc/utils/FPUtil/FloatProperties.h
+++ libc/utils/FPUtil/FloatProperties.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_LIBC_UTILS_FPUTIL_FLOAT_PROPERTIES_H
 #define LLVM_LIBC_UTILS_FPUTIL_FLOAT_PROPERTIES_H
 
+#include "PlatformDefs.h"
 #include <stdint.h>
 
 namespace __llvm_libc {
@@ -24,6 +25,7 @@
   static constexpr uint32_t bitWidth = sizeof(BitsType) << 3;
 
   static constexpr uint32_t mantissaWidth = 23;
+  static constexpr uint32_t exponentWidth = 8;
   static constexpr BitsType mantissaMask = 0x007fffffU;
   static constexpr BitsType signMask = 0x80000000U;
   static constexpr BitsType exponentMask = ~(signMask | mantissaMask);
@@ -43,6 +45,7 @@
   static constexpr uint32_t bitWidth = sizeof(BitsType) << 3;
 
   static constexpr uint32_t mantissaWidth = 52;
+  static constexpr uint32_t exponentWidth = 11;
   static constexpr BitsType mantissaMask = 0x000fffffffffffffU;
   static constexpr BitsType signMask = 0x8000000000000000ULL;
   static constexpr BitsType exponentMask = ~(signMask | mantissaMask);
@@ -54,6 +57,64 @@
   static constexpr BitsType quietNaNMask = 0x0008000000000000ULL;
 };
 
+#if defined(LONG_DOUBLE_IS_DOUBLE)
+// Properties for long double on Windows platform, same as double precision.
+template <> struct FloatProperties<long double> {
+  typedef uint64_t BitsType;
+  static_assert(sizeof(BitsType) == sizeof(double),
+                "Unexpected size of 'double' type.");
+
+  static constexpr uint32_t bitWidth = FloatProperties<double>::bitWidth;
+
+  static constexpr uint32_t mantissaWidth =
+      FloatProperties<double>::mantissaWidth;
+  static constexpr uint32_t exponentWidth =
+      FloatProperties<double>::exponentWidth;
+  static constexpr BitsType mantissaMask =
+      FloatProperties<double>::mantissaMask;
+  static constexpr BitsType signMask = FloatProperties<double>::signMask;
+  static constexpr BitsType exponentMask =
+      FloatProperties<double>::exponentMask;
+  static constexpr uint32_t exponentOffset =
+      FloatProperties<double>::exponentOffset;
+};
+
+#elif defined(SPECIAL_X86_LONG_DOUBLE)
+// Properties for long double on non-Windows x86 platforms.
+template <> struct FloatProperties<long double> {
+  typedef __uint128_t BitsType;
+  static_assert(sizeof(BitsType) == sizeof(long double),
+                "Unexpected size of 'long double' type.");
+
+  static constexpr uint32_t bitWidth = sizeof(BitsType) << 3;
+
+  static constexpr uint32_t mantissaWidth = 64;
+  static constexpr uint32_t exponentWidth = 15;
+  static constexpr BitsType mantissaMask = 0xffffffffffffffffULL;
+  static constexpr BitsType signMask = BitsType(0x00008000U) << 64;
+  static constexpr BitsType exponentMask = ~(signMask | mantissaMask);
+  static constexpr uint32_t exponentOffset = 16383;
+};
+
+#else
+// Properties for long double on non x86 platform.
+template <> struct FloatProperties<long double> {
+  typedef __uint128_t BitsType;
+  static_assert(sizeof(BitsType) == sizeof(long double),
+                "Unexpected size of 'long double' type.");
+
+  static constexpr uint32_t bitWidth = sizeof(BitsType) << 3;
+
+  static constexpr uint32_t mantissaWidth = 112;
+  static constexpr uint32_t exponentWidth = 15;
+  static constexpr BitsType mantissaMask =
+      (BitsType(0x0000ffffffffffffULL) << 64) | BitsType(0xffffffffffffffffULL);
+  static constexpr BitsType signMask = BitsType(0x8000000000000000U) << 64;
+  static constexpr BitsType exponentMask = ~(signMask | mantissaMask);
+  static constexpr uint32_t exponentOffset = 16383;
+};
+#endif
+
 // Define the float type corresponding to the BitsType.
 template <typename BitsType> struct FloatType;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105153.355591.patch
Type: text/x-patch
Size: 3753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210630/d4e417cb/attachment-0001.bin>


More information about the libc-commits mailing list