refactor(includes): vipersimd c.LLVMIR 改 LOut 模式 + 文档同步新语义
vipersimd.vp 16 处 simd_* 数学 intrinsic 改 c.LLVMIR(f"{c.LOut(out)} = call ...")
+ return out 模式;TestFBProject 2 处同步;c.py stub 与 wiki 文档
更新为"无返回值直接嵌入原始 IR 文本"语义。
This commit is contained in:
1 parent
44ff0d551f
commit
29b18af60c
4 files changed
+64
-29
No files matched your search
+48
-16
@@ -378,42 +378,58 @@ vzeroupper""",
|
||||
|
||||
def simd_sqrt(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: sqrt(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.sqrt.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.sqrt.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_fabs(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: |x|"""
|
||||
return c.LLVMIR(f"call double @llvm.fabs.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.fabs.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_floor(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: floor(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.floor.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.floor.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_ceil(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: ceil(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.ceil.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.ceil.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_round(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: round(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.round.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.round.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_trunc(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: trunc(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.trunc.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.trunc.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_fma(a: t.CDouble, b: t.CDouble, c_val: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: a*b + c (single rounding)"""
|
||||
return c.LLVMIR(f"call double @llvm.fma.f64(double {c.LInp(a)}, double {c.LInp(b)}, double {c.LInp(c_val)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.fma.f64(double {c.LInp(a)}, double {c.LInp(b)}, double {c.LInp(c_val)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_copysign(mag: t.CDouble, sign: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: copysign(mag, sign)"""
|
||||
return c.LLVMIR(f"call double @llvm.copysign.f64(double {c.LInp(mag)}, double {c.LInp(sign)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.copysign.f64(double {c.LInp(mag)}, double {c.LInp(sign)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_neg(x: t.CDouble) -> t.CDouble:
|
||||
@@ -422,39 +438,55 @@ def simd_neg(x: t.CDouble) -> t.CDouble:
|
||||
copysign(x, -1.0) is wrong for x < 0 (returns -|x| instead of +|x|).
|
||||
copysign(x, -x) = |x| * sign(-x) = -x is correct for all IEEE 754 values.
|
||||
"""
|
||||
return c.LLVMIR(f"call double @llvm.copysign.f64(double {c.LInp(x)}, double {c.LInp(t.CDouble(0.0) - x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.copysign.f64(double {c.LInp(x)}, double {c.LInp(t.CDouble(0.0) - x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_minnum(a: t.CDouble, b: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: min(a, b) (NaN-aware)"""
|
||||
return c.LLVMIR(f"call double @llvm.minnum.f64(double {c.LInp(a)}, double {c.LInp(b)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.minnum.f64(double {c.LInp(a)}, double {c.LInp(b)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_maxnum(a: t.CDouble, b: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: max(a, b) (NaN-aware)"""
|
||||
return c.LLVMIR(f"call double @llvm.maxnum.f64(double {c.LInp(a)}, double {c.LInp(b)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.maxnum.f64(double {c.LInp(a)}, double {c.LInp(b)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_exp(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: e^x"""
|
||||
return c.LLVMIR(f"call double @llvm.exp.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.exp.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_log(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: ln(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.log.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.log.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_sin(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: sin(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.sin.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.sin.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_cos(x: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: cos(x)"""
|
||||
return c.LLVMIR(f"call double @llvm.cos.f64(double {c.LInp(x)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.cos.f64(double {c.LInp(x)})")
|
||||
return out
|
||||
|
||||
|
||||
def simd_pow(x: t.CDouble, y: t.CDouble) -> t.CDouble:
|
||||
"""LLVM intrinsic: x^y"""
|
||||
return c.LLVMIR(f"call double @llvm.pow.f64(double {c.LInp(x)}, double {c.LInp(y)})", t.CDouble)
|
||||
out: t.CDouble
|
||||
c.LLVMIR(f"{c.LOut(out)} = call double @llvm.pow.f64(double {c.LInp(x)}, double {c.LInp(y)})")
|
||||
return out
|
||||
Reference in new issue
Block a user