|
1 | 1 |
|
2 | | -@generated function saturated_add(x::I, y::I) where {I<:IntegerTypesHW} |
| 2 | +@generated function saturated(::F, x::I, y::I) where {I<:IntegerTypesHW,F} |
3 | 3 | typ = "i$(8sizeof(I))" |
4 | 4 | s = I <: Signed ? 's' : 'u' |
5 | | - f = "@llvm.$(s)add.sat.$typ" |
| 5 | + op = F === typeof(+) ? "add" : "sub" |
| 6 | + f = "@llvm.$(s)$(op).sat.$typ" |
6 | 7 | decl = "declare $typ $f($typ, $typ)" |
7 | 8 | instrs = """ |
8 | 9 | %res = call $typ $f($typ %0, $typ %1) |
|
18 | 19 | [:x, :y] |
19 | 20 | ) |
20 | 21 | end |
21 | | -@generated function saturated_add(x::Vec{W,I}, y::Vec{W,I}) where {W,I} |
| 22 | +@generated function saturated(::F, x::Vec{W,I}, y::Vec{W,I}) where {W,I,F} |
22 | 23 | typ = "i$(8sizeof(I))" |
23 | 24 | vtyp = "<$W x $(typ)>" |
24 | 25 | s = I <: Signed ? 's' : 'u' |
25 | | - f = "@llvm.$(s)add.sat.$(suffix(W,typ))" |
| 26 | + op = F === typeof(+) ? "add" : "sub" |
| 27 | + f = "@llvm.$(s)$(op).sat.$(suffix(W,typ))" |
26 | 28 | decl = "declare $vtyp $f($vtyp, $vtyp)" |
27 | 29 | instrs = """ |
28 | 30 | %res = call $vtyp $f($vtyp %0, $vtyp %1) |
|
38 | 40 | [:(data(x)), :(data(y))] |
39 | 41 | ) |
40 | 42 | end |
| 43 | +@inline saturated_add(x, y) = saturated(+, x, y) |
| 44 | +@inline saturated_sub(x, y) = saturated(-, x, y) |
41 | 45 |
|
42 | 46 | @eval @inline function assume(b::Bool) |
43 | 47 | $(llvmcall_expr( |
|
0 commit comments