[flang-commits] [flang] [flang][cuda] Add interfaces for double_as_longlong and longlong_as_double (PR #153719)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Thu Aug 14 17:34:30 PDT 2025
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/153719
None
>From 8750e48c18a46c237298730d24eb0a1c8b30364f Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 14 Aug 2025 17:33:00 -0700
Subject: [PATCH] [flang][cuda] Add interfaces for double_as_longlong and
longlong_as_double
---
flang/module/cudadevice.f90 | 14 ++++++++++++++
flang/test/Lower/CUDA/cuda-libdevice.cuf | 18 ++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index ffc3a3b170ca6..18a68b0465768 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -569,6 +569,20 @@ attributes(device) real(8) function sinpi(x) bind(c,name='__nv_sinpi')
end function
end interface
+ interface double_as_longlong
+ attributes(device) integer(8) function __double_as_longlong(i) bind(c, name='__nv_double_as_longlong')
+ !dir$ ignore_tkr (d) i
+ real(8), value :: i
+ end function
+ end interface
+
+ interface longlong_as_double
+ attributes(device) real(8) function __longlong_as_double(i) bind(c, name='__nv_longlong_as_double')
+ !dir$ ignore_tkr (d) i
+ integer(8), value :: i
+ end function
+ end interface
+
interface __double2int_rd
attributes(device) integer function __double2int_rd(r) bind(c, name='__nv_double2int_rd')
!dir$ ignore_tkr (d) r
diff --git a/flang/test/Lower/CUDA/cuda-libdevice.cuf b/flang/test/Lower/CUDA/cuda-libdevice.cuf
index f9c5dcc5fc4c3..f9d929a9027c6 100644
--- a/flang/test/Lower/CUDA/cuda-libdevice.cuf
+++ b/flang/test/Lower/CUDA/cuda-libdevice.cuf
@@ -244,3 +244,21 @@ end subroutine
! CHECK: %{{.*}} = fir.call @__nv_float2uint_rn(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> i32
! CHECK: %{{.*}} = fir.call @__nv_float2uint_ru(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> i32
! CHECK: %{{.*}} = fir.call @__nv_float2uint_rz(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f32) -> i32
+
+attributes(global) subroutine test_double_as_longlong()
+ integer(8) :: res
+ real(8) :: r
+ res = double_as_longlong(r)
+end subroutine
+
+! CHECK-LABEL: _QPtest_double_as_longlong
+! CHECK: %{{.*}} = fir.call @__nv_double_as_longlong(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (f64) -> i64
+
+attributes(global) subroutine test_longlong_as_double()
+ integer(8) :: i
+ real(8) :: res
+ res = longlong_as_double(i)
+end subroutine
+
+! CHECK-LABEL: _QPtest_longlong_as_double
+! CHECK: %{{.*}} = fir.call @__nv_longlong_as_double(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i64) -> f64
More information about the flang-commits
mailing list