mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
72 lines
2.7 KiB
Plaintext
72 lines
2.7 KiB
Plaintext
// #target: macos-x64
|
|
// #opt: --fp-math=relaxed
|
|
module test;
|
|
|
|
fn float easeElasticIn(float t, float b, float c, float d) @inline // Ease: Elastic In
|
|
{
|
|
if (t == 0.0f) return b;
|
|
if ((t/=d) == 1.0f) return (b + c);
|
|
|
|
float p = d*0.3f;
|
|
float a = c;
|
|
float s = p/4.0f;
|
|
float postFix = a*$$pow(2.0f, 10.0f*(t-=1.0f));
|
|
|
|
return (-(postFix*$$sin((t*d-s)*(2.0f*3.14f)/p )) + b);
|
|
}
|
|
|
|
/* #expect: test.ll
|
|
|
|
|
|
define float @test.easeElasticIn(float %0, float %1, float %2, float %3) #0 {
|
|
entry:
|
|
%t = alloca float, align 4
|
|
%p = alloca float, align 4
|
|
%a = alloca float, align 4
|
|
%s = alloca float, align 4
|
|
%postFix = alloca float, align 4
|
|
store float %0, ptr %t, align 4
|
|
%4 = load float, ptr %t, align 4
|
|
%eq = fcmp reassoc arcp contract oeq float %4, 0.000000e+00
|
|
br i1 %eq, label %if.then, label %if.exit
|
|
if.then: ; preds = %entry
|
|
ret float %1
|
|
if.exit: ; preds = %entry
|
|
%5 = load float, ptr %t, align 4
|
|
%fdiv = fdiv reassoc arcp contract float %5, %3
|
|
store float %fdiv, ptr %t, align 4
|
|
%eq1 = fcmp reassoc arcp contract oeq float %fdiv, 1.000000e+00
|
|
br i1 %eq1, label %if.then2, label %if.exit3
|
|
if.then2: ; preds = %if.exit
|
|
%fadd = fadd reassoc arcp contract float %1, %2
|
|
ret float %fadd
|
|
if.exit3: ; preds = %if.exit
|
|
%fmul = fmul reassoc arcp contract float %3, 0x3FD3333340000000
|
|
store float %fmul, ptr %p, align 4
|
|
store float %2, ptr %a, align 4
|
|
%6 = load float, ptr %p, align 4
|
|
%fdiv4 = fdiv reassoc arcp contract float %6, 4.000000e+00
|
|
store float %fdiv4, ptr %s, align 4
|
|
%7 = load float, ptr %a, align 4
|
|
%8 = load float, ptr %t, align 4
|
|
%fsub = fsub reassoc arcp contract float %8, 1.000000e+00
|
|
store float %fsub, ptr %t, align 4
|
|
%fmul5 = fmul reassoc arcp contract float 1.000000e+01, %fsub
|
|
%9 = call reassoc arcp contract float @llvm.pow.f32(float 2.000000e+00, float %fmul5)
|
|
%fmul6 = fmul reassoc arcp contract float %7, %9
|
|
store float %fmul6, ptr %postFix, align 4
|
|
%10 = load float, ptr %postFix, align 4
|
|
%11 = load float, ptr %t, align 4
|
|
%12 = load float, ptr %s, align 4
|
|
%13 = fneg reassoc arcp contract float %12
|
|
%14 = call reassoc arcp contract float @llvm.fmuladd.f32(float %11, float %3, float %13)
|
|
%fmul7 = fmul reassoc arcp contract float %14, 0x40191EB860000000
|
|
%15 = load float, ptr %p, align 4
|
|
%fdiv8 = fdiv reassoc arcp contract float %fmul7, %15
|
|
%16 = call reassoc arcp contract float @llvm.sin.f32(float %fdiv8)
|
|
%17 = fneg reassoc arcp contract float %1
|
|
%18 = call reassoc arcp contract float @llvm.fmuladd.f32(float %10, float %16, float %17)
|
|
%19 = fneg reassoc arcp contract float %18
|
|
ret float %19
|
|
}
|