@@ -7,6 +7,8 @@ const __METAL_OS_LOG_TYPE_DEFAULT__ = Int32(0)
7
7
const __METAL_OS_LOG_TYPE_ERROR__ = Int32 (16 )
8
8
const __METAL_OS_LOG_TYPE_FAULT__ = Int32 (17 )
9
9
10
+ const ALLOW_DOUBLE_META = " allowdouble"
11
+
10
12
export @mtlprintf
11
13
12
14
@generated function promote_c_argument (arg)
@@ -18,13 +20,39 @@ export @mtlprintf
18
20
19
21
if arg == Cchar || arg == Cshort
20
22
return :(Cint (arg))
21
- elseif arg == Cfloat
22
- return :(Cdouble (arg))
23
23
else
24
24
return :(arg)
25
25
end
26
26
end
27
27
28
+ @generated function tag_doubles (arg)
29
+ @dispose ctx= Context () begin
30
+ ret = arg == Cfloat ? Cdouble : arg
31
+ T_arg = convert (LLVMType, arg)
32
+ T_ret = convert (LLVMType, ret)
33
+
34
+ f, ft = create_function (T_ret, [T_arg])
35
+
36
+ @dispose builder= IRBuilder () begin
37
+ entry = BasicBlock (f, " entry" )
38
+ position! (builder, entry)
39
+
40
+ p1 = parameters (f)[1 ]
41
+
42
+ if arg == Cfloat
43
+ res = fpext! (builder, p1, LLVM. DoubleType ())
44
+ metadata (res)[" ir_check_ignore" ] = MDNode ([])
45
+ ret! (builder, res)
46
+ else
47
+ ret! (builder, p1)
48
+ end
49
+ end
50
+
51
+ call_function (f, ret, Tuple{arg}, :arg )
52
+ end
53
+ end
54
+
55
+
28
56
"""
29
57
@mtlprintf("%Fmt", args...)
30
58
@@ -33,7 +61,7 @@ Print a formatted string in device context on the host standard output.
33
61
macro mtlprintf (fmt:: String , args... )
34
62
fmt_val = Val (Symbol (fmt))
35
63
36
- return :(_mtlprintf ($ fmt_val, $ (map (arg -> :(promote_c_argument ($ arg)), esc .(args))... )))
64
+ return :(_mtlprintf ($ fmt_val, $ (map (arg -> :(tag_doubles ( promote_c_argument ($ arg) )), esc .(args))... )))
37
65
end
38
66
39
67
@generated function _mtlprintf (:: Val{fmt} , argspec... ) where {fmt}
0 commit comments