You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.0 KiB

@i_buf = global [10000000 x float] zeroinitializer
@o_buf = global [10000000 x float] zeroinitializer
declare i32 @getint()
declare float @getfloat()
declare i32 @getarray(i32* %arg.a)
declare i32 @getfarray(float* %arg.a)
declare i32 @getch()
declare void @putint(i32 %arg.x)
declare void @putfloat(float %arg.x)
declare void @putarray(i32 %arg.n, i32* %arg.a)
declare void @putfarray(i32 %arg.n, float* %arg.a)
declare void @putch(i32 %arg.x)
declare void @starttime()
declare void @stoptime()
define float @newtons_sqrt_recursive(float %arg.n, float %arg.x, float %arg.prec) {
entry:
%t3 = alloca float
%t10 = alloca float
%t0 = alloca float
store float %arg.n, float* %t0
%t1 = alloca float
store float %arg.x, float* %t1
%t2 = alloca float
store float %arg.prec, float* %t2
%t4 = load float, float* %t1
%t5 = load float, float* %t0
%t6 = load float, float* %t1
%t7 = fdiv float %t5, %t6
%t8 = fadd float %t4, %t7
%t9 = fmul float %t8, 0x3FE0000000000000
store float %t9, float* %t3
store float 0x0000000000000000, float* %t10
%t11 = load float, float* %t1
%t12 = load float, float* %t3
%t13 = fcmp olt float %t11, %t12
%t14 = zext i1 %t13 to i32
%t15 = icmp ne i32 %t14, 0
br i1 %t15, label %if.then.1, label %if.else.2
if.then.1:
%t16 = load float, float* %t3
%t17 = load float, float* %t1
%t18 = fsub float %t16, %t17
store float %t18, float* %t10
br label %if.end.3
if.else.2:
%t19 = load float, float* %t1
%t20 = load float, float* %t3
%t21 = fsub float %t19, %t20
store float %t21, float* %t10
br label %if.end.3
if.end.3:
%t22 = load float, float* %t10
%t23 = load float, float* %t2
%t24 = fcmp ole float %t22, %t23
%t25 = zext i1 %t24 to i32
%t26 = icmp ne i32 %t25, 0
br i1 %t26, label %if.then.4, label %if.else.5
if.then.4:
%t27 = load float, float* %t3
ret float %t27
if.else.5:
%t28 = load float, float* %t0
%t29 = load float, float* %t3
%t30 = load float, float* %t2
%t31 = call float @newtons_sqrt_recursive(float %t28, float %t29, float %t30)
ret float %t31
if.end.6:
ret float 0x0000000000000000
}
define float @newtons_sqrt(float %arg.n) {
entry:
%t38 = alloca float
%t32 = alloca float
store float %arg.n, float* %t32
%t33 = alloca float
store float 0x3DDB7CDFE0000000, float* %t33
%t34 = load float, float* %t32
%t35 = fcmp ole float %t34, 0x0000000000000000
%t36 = zext i1 %t35 to i32
%t37 = icmp ne i32 %t36, 0
br i1 %t37, label %if.then.7, label %if.end.8
if.then.7:
ret float 0x0000000000000000
if.end.8:
%t39 = load float, float* %t32
%t40 = fadd float %t39, 0x3FF0000000000000
%t41 = fmul float %t40, 0x3FE0000000000000
store float %t41, float* %t38
%t42 = load float, float* %t32
%t43 = load float, float* %t38
%t44 = load float, float* %t33
%t45 = call float @newtons_sqrt_recursive(float %t42, float %t43, float %t44)
ret float %t45
}
define i32 @main() {
entry:
%t46 = alloca i32
%t50 = alloca i32
%t47 = getelementptr inbounds [10000000 x float], [10000000 x float]* @i_buf, i32 0, i32 0
%t48 = call i32 @getfarray(float* %t47)
store i32 %t48, i32* %t46
call void @starttime()
store i32 0, i32* %t50
br label %while.cond.9
while.cond.9:
%t51 = load i32, i32* %t50
%t52 = load i32, i32* %t46
%t53 = icmp slt i32 %t51, %t52
%t54 = zext i1 %t53 to i32
%t55 = icmp ne i32 %t54, 0
br i1 %t55, label %while.body.10, label %while.end.11
while.body.10:
%t56 = load i32, i32* %t50
%t57 = getelementptr inbounds [10000000 x float], [10000000 x float]* @o_buf, i32 0, i32 %t56
%t58 = load i32, i32* %t50
%t59 = getelementptr inbounds [10000000 x float], [10000000 x float]* @i_buf, i32 0, i32 %t58
%t60 = load float, float* %t59
%t61 = call float @newtons_sqrt(float %t60)
store float %t61, float* %t57
%t62 = load i32, i32* %t50
%t63 = add i32 %t62, 1
store i32 %t63, i32* %t50
br label %while.cond.9
while.end.11:
call void @stoptime()
%t65 = load i32, i32* %t46
%t66 = getelementptr inbounds [10000000 x float], [10000000 x float]* @o_buf, i32 0, i32 0
call void @putfarray(i32 %t65, float* %t66)
ret i32 0
}