[PATCH] Add getSizeInBits function to the APFloat class
Tamas Berghammer
tberghammer at google.com
Wed Mar 18 06:51:23 PDT 2015
Hi chandlerc,
Add getSizeInBits function to the APFloat class
The newly added function returns the size of the specified floating point semantics in bits.
http://reviews.llvm.org/D8413
Files:
include/llvm/ADT/APFloat.h
lib/Support/APFloat.cpp
Index: include/llvm/ADT/APFloat.h
===================================================================
--- include/llvm/ADT/APFloat.h
+++ include/llvm/ADT/APFloat.h
@@ -276,6 +276,10 @@
/// \param isIEEE - If 128 bit number, select between PPC and IEEE
static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE = false);
+ /// Returns the size of the floating point number (in bits) in the given
+ /// semantics.
+ static unsigned getSizeInBits(const fltSemantics &Sem);
+
/// @}
/// Used to insert APFloat objects, or objects that contain APFloat objects,
Index: lib/Support/APFloat.cpp
===================================================================
--- lib/Support/APFloat.cpp
+++ lib/Support/APFloat.cpp
@@ -3368,6 +3368,21 @@
}
}
+unsigned APFloat::getSizeInBits(const fltSemantics &Sem)
+{
+ // sign bit + mantissa
+ unsigned size = 1 + Sem.precision;
+
+ // Add size of the exponent
+ ExponentType ex = Sem.maxExponent;
+ while (ex) {
+ ex >>= 1;
+ size++;
+ }
+
+ return size;
+}
+
/// Make this number the largest magnitude normal number in the given
/// semantics.
void APFloat::makeLargest(bool Negative) {
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8413.22178.patch
Type: text/x-patch
Size: 1168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150318/c73e19ae/attachment.bin>
More information about the llvm-commits
mailing list