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.

479 lines
14 KiB

@W = global i32 12
@H = global i32 12
@N = global i32 24
@PI = global float 0x400921FB60000000
@TWO_PI = global float 0x401921FB60000000
@MAX_STEP = global i32 10
@MAX_DISTANCE = global float 0x4000000000000000
@EPSILON = global float 0x3EB0C6F7A0000000
@RAND_MAX = global i32 100000006
@seed = global i32 0
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 i32 @rand() {
entry:
%t0 = load i32, i32* @seed
%t1 = mul i32 %t0, 19980130
%t2 = add i32 %t1, 23333
%t3 = srem i32 %t2, 100000007
store i32 %t3, i32* @seed
%t4 = load i32, i32* @seed
%t5 = icmp slt i32 %t4, 0
%t6 = zext i1 %t5 to i32
%t7 = icmp ne i32 %t6, 0
br i1 %t7, label %if.then.1, label %if.end.2
if.then.1:
%t8 = load i32, i32* @seed
%t9 = add i32 %t8, 100000007
store i32 %t9, i32* @seed
br label %if.end.2
if.end.2:
%t10 = load i32, i32* @seed
ret i32 %t10
}
define float @my_fabs(float %arg.x) {
entry:
%t11 = alloca float
store float %arg.x, float* %t11
%t12 = load float, float* %t11
%t13 = fcmp ogt float %t12, 0x0000000000000000
%t14 = zext i1 %t13 to i32
%t15 = icmp ne i32 %t14, 0
br i1 %t15, label %if.then.3, label %if.end.4
if.then.3:
%t16 = load float, float* %t11
ret float %t16
if.end.4:
%t17 = load float, float* %t11
%t18 = fsub float 0x0000000000000000, %t17
ret float %t18
}
define float @my_sqrt(float %arg.x) {
entry:
%t20 = alloca float
%t30 = alloca i32
%t19 = alloca float
store float %arg.x, float* %t19
%t21 = load float, float* %t19
%t22 = fdiv float %t21, 0x4020000000000000
%t23 = fadd float %t22, 0x3FE0000000000000
%t24 = load float, float* %t19
%t25 = fmul float 0x4000000000000000, %t24
%t26 = load float, float* %t19
%t27 = fadd float 0x4010000000000000, %t26
%t28 = fdiv float %t25, %t27
%t29 = fadd float %t23, %t28
store float %t29, float* %t20
store i32 10, i32* %t30
br label %while.cond.5
while.cond.5:
%t31 = load i32, i32* %t30
%t32 = icmp ne i32 %t31, 0
br i1 %t32, label %while.body.6, label %while.end.7
while.body.6:
%t33 = load float, float* %t20
%t34 = load float, float* %t19
%t35 = load float, float* %t20
%t36 = fdiv float %t34, %t35
%t37 = fadd float %t33, %t36
%t38 = fdiv float %t37, 0x4000000000000000
store float %t38, float* %t20
%t39 = load i32, i32* %t30
%t40 = sub i32 %t39, 1
store i32 %t40, i32* %t30
br label %while.cond.5
while.end.7:
%t41 = load float, float* %t20
ret float %t41
}
define float @p(float %arg.x) {
entry:
%t42 = alloca float
store float %arg.x, float* %t42
%t43 = load float, float* %t42
%t44 = fmul float 0x4008000000000000, %t43
%t45 = load float, float* %t42
%t46 = fmul float 0x4010000000000000, %t45
%t47 = load float, float* %t42
%t48 = fmul float %t46, %t47
%t49 = load float, float* %t42
%t50 = fmul float %t48, %t49
%t51 = fsub float %t44, %t50
ret float %t51
}
define float @my_sin_impl(float %arg.x) {
entry:
%t52 = alloca float
store float %arg.x, float* %t52
%t53 = load float, float* %t52
%t54 = call float @my_fabs(float %t53)
%t55 = load float, float* @EPSILON
%t56 = fcmp ole float %t54, %t55
%t57 = zext i1 %t56 to i32
%t58 = icmp ne i32 %t57, 0
br i1 %t58, label %if.then.8, label %if.end.9
if.then.8:
%t59 = load float, float* %t52
ret float %t59
if.end.9:
%t60 = load float, float* %t52
%t61 = fdiv float %t60, 0x4008000000000000
%t62 = call float @my_sin_impl(float %t61)
%t63 = call float @p(float %t62)
ret float %t63
}
define float @my_sin(float %arg.x) {
entry:
%t76 = alloca i32
%t64 = alloca float
store float %arg.x, float* %t64
%t65 = load float, float* %t64
%t66 = load float, float* @TWO_PI
%t67 = fcmp ogt float %t65, %t66
%t68 = zext i1 %t67 to i32
%t69 = icmp ne i32 %t68, 0
br i1 %t69, label %if.then.10, label %lor.rhs.12
if.then.10:
%t77 = load float, float* %t64
%t78 = load float, float* @TWO_PI
%t79 = fdiv float %t77, %t78
%t80 = fptosi float %t79 to i32
store i32 %t80, i32* %t76
%t81 = load float, float* %t64
%t82 = load i32, i32* %t76
%t83 = load float, float* @TWO_PI
%t84 = sitofp i32 %t82 to float
%t85 = fmul float %t84, %t83
%t86 = fsub float %t81, %t85
store float %t86, float* %t64
br label %if.end.11
if.end.11:
%t87 = load float, float* %t64
%t88 = load float, float* @PI
%t89 = fcmp ogt float %t87, %t88
%t90 = zext i1 %t89 to i32
%t91 = icmp ne i32 %t90, 0
br i1 %t91, label %if.then.13, label %if.end.14
lor.rhs.12:
%t70 = load float, float* %t64
%t71 = load float, float* @TWO_PI
%t72 = fsub float 0x0000000000000000, %t71
%t73 = fcmp olt float %t70, %t72
%t74 = zext i1 %t73 to i32
%t75 = icmp ne i32 %t74, 0
br i1 %t75, label %if.then.10, label %if.end.11
if.then.13:
%t92 = load float, float* %t64
%t93 = load float, float* @TWO_PI
%t94 = fsub float %t92, %t93
store float %t94, float* %t64
br label %if.end.14
if.end.14:
%t95 = load float, float* %t64
%t96 = load float, float* @PI
%t97 = fsub float 0x0000000000000000, %t96
%t98 = fcmp olt float %t95, %t97
%t99 = zext i1 %t98 to i32
%t100 = icmp ne i32 %t99, 0
br i1 %t100, label %if.then.15, label %if.end.16
if.then.15:
%t101 = load float, float* %t64
%t102 = load float, float* @TWO_PI
%t103 = fadd float %t101, %t102
store float %t103, float* %t64
br label %if.end.16
if.end.16:
%t104 = load float, float* %t64
%t105 = call float @my_sin_impl(float %t104)
ret float %t105
}
define float @my_cos(float %arg.x) {
entry:
%t106 = alloca float
store float %arg.x, float* %t106
%t107 = load float, float* %t106
%t108 = load float, float* @PI
%t109 = fdiv float %t108, 0x4000000000000000
%t110 = fadd float %t107, %t109
%t111 = call float @my_sin(float %t110)
ret float %t111
}
define float @circle_sdf(float %arg.x, float %arg.y, float %arg.cx, float %arg.cy, float %arg.r) {
entry:
%t117 = alloca float
%t121 = alloca float
%t112 = alloca float
store float %arg.x, float* %t112
%t113 = alloca float
store float %arg.y, float* %t113
%t114 = alloca float
store float %arg.cx, float* %t114
%t115 = alloca float
store float %arg.cy, float* %t115
%t116 = alloca float
store float %arg.r, float* %t116
%t118 = load float, float* %t112
%t119 = load float, float* %t114
%t120 = fsub float %t118, %t119
store float %t120, float* %t117
%t122 = load float, float* %t113
%t123 = load float, float* %t115
%t124 = fsub float %t122, %t123
store float %t124, float* %t121
%t125 = load float, float* %t117
%t126 = load float, float* %t117
%t127 = fmul float %t125, %t126
%t128 = load float, float* %t121
%t129 = load float, float* %t121
%t130 = fmul float %t128, %t129
%t131 = fadd float %t127, %t130
%t132 = call float @my_sqrt(float %t131)
%t133 = load float, float* %t116
%t134 = fsub float %t132, %t133
ret float %t134
}
define void @scene(float %arg.x, float %arg.y, float* %arg.ret) {
entry:
%t137 = alloca float
%t141 = alloca float
%t135 = alloca float
store float %arg.x, float* %t135
%t136 = alloca float
store float %arg.y, float* %t136
%t138 = load float, float* %t135
%t139 = load float, float* %t136
%t140 = call float @circle_sdf(float %t138, float %t139, float 0x3FD99999A0000000, float 0x3FD99999A0000000, float 0x3FB99999A0000000)
store float %t140, float* %t137
%t142 = load float, float* %t135
%t143 = load float, float* %t136
%t144 = call float @circle_sdf(float %t142, float %t143, float 0x3FE3333340000000, float 0x3FE3333340000000, float 0x3FA99999A0000000)
store float %t144, float* %t141
%t145 = load float, float* %t137
%t146 = load float, float* %t141
%t147 = fcmp olt float %t145, %t146
%t148 = zext i1 %t147 to i32
%t149 = icmp ne i32 %t148, 0
br i1 %t149, label %if.then.17, label %if.else.18
if.then.17:
%t150 = getelementptr inbounds float, float* %arg.ret, i32 0
%t151 = load float, float* %t137
store float %t151, float* %t150
%t152 = getelementptr inbounds float, float* %arg.ret, i32 1
store float 0x4008000000000000, float* %t152
br label %if.end.19
if.else.18:
%t153 = getelementptr inbounds float, float* %arg.ret, i32 0
%t154 = load float, float* %t141
store float %t154, float* %t153
%t155 = getelementptr inbounds float, float* %arg.ret, i32 1
store float 0x0000000000000000, float* %t155
br label %if.end.19
if.end.19:
ret void
}
define float @trace(float %arg.ox, float %arg.oy, float %arg.dx, float %arg.dy) {
entry:
%t160 = alloca float
%t161 = alloca i32
%t171 = alloca float, i32 2
%t156 = alloca float
store float %arg.ox, float* %t156
%t157 = alloca float
store float %arg.oy, float* %t157
%t158 = alloca float
store float %arg.dx, float* %t158
%t159 = alloca float
store float %arg.dy, float* %t159
store float 0x0000000000000000, float* %t160
store i32 0, i32* %t161
br label %while.cond.20
while.cond.20:
%t162 = load i32, i32* %t161
%t163 = icmp slt i32 %t162, 10
%t164 = zext i1 %t163 to i32
%t165 = icmp ne i32 %t164, 0
br i1 %t165, label %land.rhs.23, label %while.end.22
while.body.21:
%t172 = load float, float* %t156
%t173 = load float, float* %t158
%t174 = load float, float* %t160
%t175 = fmul float %t173, %t174
%t176 = fadd float %t172, %t175
%t177 = load float, float* %t157
%t178 = load float, float* %t159
%t179 = load float, float* %t160
%t180 = fmul float %t178, %t179
%t181 = fadd float %t177, %t180
call void @scene(float %t176, float %t181, float* %t171)
%t183 = getelementptr inbounds float, float* %t171, i32 0
%t184 = load float, float* %t183
%t185 = load float, float* @EPSILON
%t186 = fcmp olt float %t184, %t185
%t187 = zext i1 %t186 to i32
%t188 = icmp ne i32 %t187, 0
br i1 %t188, label %if.then.24, label %if.end.25
while.end.22:
ret float 0x0000000000000000
land.rhs.23:
%t166 = load float, float* %t160
%t167 = load float, float* @MAX_DISTANCE
%t168 = fcmp olt float %t166, %t167
%t169 = zext i1 %t168 to i32
%t170 = icmp ne i32 %t169, 0
br i1 %t170, label %while.body.21, label %while.end.22
if.then.24:
%t189 = getelementptr inbounds float, float* %t171, i32 1
%t190 = load float, float* %t189
ret float %t190
if.end.25:
%t191 = load float, float* %t160
%t192 = getelementptr inbounds float, float* %t171, i32 0
%t193 = load float, float* %t192
%t194 = fadd float %t191, %t193
store float %t194, float* %t160
%t195 = load i32, i32* %t161
%t196 = add i32 %t195, 1
store i32 %t196, i32* %t161
br label %while.cond.20
}
define float @sample(float %arg.x, float %arg.y) {
entry:
%t199 = alloca float
%t200 = alloca i32
%t205 = alloca float
%t208 = alloca float
%t197 = alloca float
store float %arg.x, float* %t197
%t198 = alloca float
store float %arg.y, float* %t198
store float 0x0000000000000000, float* %t199
store i32 0, i32* %t200
br label %while.cond.26
while.cond.26:
%t201 = load i32, i32* %t200
%t202 = icmp slt i32 %t201, 24
%t203 = zext i1 %t202 to i32
%t204 = icmp ne i32 %t203, 0
br i1 %t204, label %while.body.27, label %while.end.28
while.body.27:
%t206 = call i32 @rand()
%t207 = sitofp i32 %t206 to float
store float %t207, float* %t205
%t209 = load float, float* @TWO_PI
%t210 = load i32, i32* %t200
%t211 = load float, float* %t205
%t212 = fdiv float %t211, 0x4197D78420000000
%t213 = sitofp i32 %t210 to float
%t214 = fadd float %t213, %t212
%t215 = fmul float %t209, %t214
%t216 = fdiv float %t215, 0x4038000000000000
store float %t216, float* %t208
%t217 = load float, float* %t199
%t218 = load float, float* %t197
%t219 = load float, float* %t198
%t220 = load float, float* %t208
%t221 = call float @my_cos(float %t220)
%t222 = load float, float* %t208
%t223 = call float @my_sin(float %t222)
%t224 = call float @trace(float %t218, float %t219, float %t221, float %t223)
%t225 = fadd float %t217, %t224
store float %t225, float* %t199
%t226 = load i32, i32* %t200
%t227 = add i32 %t226, 1
store i32 %t227, i32* %t200
br label %while.cond.26
while.end.28:
%t228 = load float, float* %t199
%t229 = fdiv float %t228, 0x4038000000000000
ret float %t229
}
define void @write_pgm() {
entry:
%t239 = alloca i32
%t244 = alloca i32
%t249 = alloca float
%t252 = alloca float
%t255 = alloca i32
call void @putch(i32 80)
call void @putch(i32 50)
call void @putch(i32 10)
call void @putint(i32 12)
call void @putch(i32 32)
call void @putint(i32 12)
call void @putch(i32 32)
call void @putint(i32 255)
call void @putch(i32 10)
store i32 0, i32* %t239
br label %while.cond.29
while.cond.29:
%t240 = load i32, i32* %t239
%t241 = icmp slt i32 %t240, 12
%t242 = zext i1 %t241 to i32
%t243 = icmp ne i32 %t242, 0
br i1 %t243, label %while.body.30, label %while.end.31
while.body.30:
store i32 0, i32* %t244
br label %while.cond.32
while.end.31:
ret void
while.cond.32:
%t245 = load i32, i32* %t244
%t246 = icmp slt i32 %t245, 12
%t247 = zext i1 %t246 to i32
%t248 = icmp ne i32 %t247, 0
br i1 %t248, label %while.body.33, label %while.end.34
while.body.33:
%t250 = load i32, i32* %t244
%t251 = sitofp i32 %t250 to float
store float %t251, float* %t249
%t253 = load i32, i32* %t239
%t254 = sitofp i32 %t253 to float
store float %t254, float* %t252
%t256 = load float, float* %t249
%t257 = fdiv float %t256, 0x4028000000000000
%t258 = load float, float* %t252
%t259 = fdiv float %t258, 0x4028000000000000
%t260 = call float @sample(float %t257, float %t259)
%t261 = fmul float %t260, 0x406FE00000000000
%t262 = fptosi float %t261 to i32
store i32 %t262, i32* %t255
%t263 = load i32, i32* %t255
%t264 = icmp sgt i32 %t263, 255
%t265 = zext i1 %t264 to i32
%t266 = icmp ne i32 %t265, 0
br i1 %t266, label %if.then.35, label %if.end.36
while.end.34:
call void @putch(i32 10)
%t273 = load i32, i32* %t239
%t274 = add i32 %t273, 1
store i32 %t274, i32* %t239
br label %while.cond.29
if.then.35:
store i32 255, i32* %t255
br label %if.end.36
if.end.36:
%t267 = load i32, i32* %t255
call void @putint(i32 %t267)
call void @putch(i32 32)
%t270 = load i32, i32* %t244
%t271 = add i32 %t270, 1
store i32 %t271, i32* %t244
br label %while.cond.32
}
define i32 @main() {
entry:
call void @write_pgm()
ret i32 0
}