================
@@ -101,4 +102,17 @@ _mlir_apfloat_convert(int32_t inSemantics, int32_t 
outSemantics, uint64_t a) {
   llvm::APInt result = val.bitcastToAPInt();
   return result.getZExtValue();
 }
+
+MLIR_APFLOAT_WRAPPERS_EXPORT uint64_t _mlir_apfloat_convert_to_int(
+    int32_t semantics, int32_t resultWidth, bool isUnsigned, uint64_t a) {
+  const llvm::fltSemantics &sem = llvm::APFloatBase::EnumToSemantics(
+      static_cast<llvm::APFloatBase::Semantics>(semantics));
+  unsigned inputWidth = llvm::APFloatBase::semanticsSizeInBits(sem);
+  llvm::APFloat val(sem, llvm::APInt(inputWidth, a));
+  llvm::APSInt result(resultWidth, isUnsigned);
+  bool isExact;
+  // TODO: Custom rounding modes are not supported yet.
+  val.convertToInteger(result, llvm::RoundingMode::NearestTiesToEven, 
&isExact);
+  return result.getZExtValue();
----------------
makslevental wrote:

n00b q: shouldn't this be either a `sext` or a `zext` depending on whether we 
want `fptosi` or `fptoui` semantics?

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

Reply via email to