Last active
July 11, 2020 01:59
-
-
Save s5bug/4e13632c45591871b153f4f4679b58bd to your computer and use it in GitHub Desktop.
C vs LLVM vs MCFASM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int gcd(int x, int y) { | |
if(x == y) { | |
return x; | |
} else if(x < y) { | |
return gcd(x, y - x); | |
} else { | |
return gcd(x - y, y); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define i32 @gcd(i32 %x, i32 %y) { | |
entry: | |
%tmp3 = icmp eq i32 %x, %y | |
br i1 %tmp3, label %return, label %cond_false | |
return: | |
ret i32 %x | |
cond_false: | |
%tmp9 = icmp ult i32 %x, %y | |
br i1 %tmp9, label %cond_true12, label %cond_false19 | |
cond_true12: | |
%tmp15 = sub i32 %y, %x | |
%tmp17 = call i32 @gcd(i32 %x, i32 %tmp15) | |
ret i32 %tmp17 | |
cond_false19: | |
%tmp22 = sub i32 %x, %y | |
%tmp24 = call i32 @gcd(i32 %tmp22, i32 %y) | |
ret i32 %tmp24 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gcd_entry.mcfunction | |
execute store result score y llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result score x llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute unless score x llmcf_scope = y llmcf_scope run scoreboard players set tmp3 llmcf_scope 0 | |
execute if score x llmcf_scope = y llmcf_scope run scoreboard players set tmp3 llmcf_scope 1 | |
execute if score tmp3 llmcf_scope matches 0 run function llmcf:gcd_cond_false | |
execute if score tmp3 llmcf_scope matches 1 run function llmcf:gcd_return | |
# gcd_return.mcfunction | |
execute store result storage llmcf register int 1 run scoreboard players get x llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
# gcd_cond_false.mcfunction | |
execute unless score x llmcf_scope < y llmcf_scope run scoreboard players set tmp9 llmcf_scope 0 | |
execute if score x llmcf_scope < y llmcf_scope run scoreboard players set tmp9 llmcf_scope 1 | |
execute if score tmp9 llmcf_scope matches 0 run function llmcf:gcd_cond_false19 | |
execute if score tmp9 llmcf_scope matches 1 run function llmcf:gcd_cond_true12 | |
# gcd_cond_true12.mcfunction | |
scoreboard players operation tmp15 llmcf_scope = y llmcf_scope | |
scoreboard players operation tmp15 llmcf_scope -= x llmcf_scope | |
execute store result storage llmcf register int 1 run scoreboard players get tmp3 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
execute store result storage llmcf register int 1 run scoreboard players get tmp9 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
execute store result storage llmcf register int 1 run scoreboard players get x llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
execute store result storage llmcf register int 1 run scoreboard players get tmp15 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
function llmcf:gcd_entry | |
execute store result score tmp17 llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result score tmp9 llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result score tmp3 llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result storage llmcf register int 1 run scoreboard players get tmp17 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
# gcd_cond_false19.mcfunction | |
scoreboard players operation tmp22 llmcf_scope = x llmcf_scope | |
scoreboard players operation tmp22 llmcf_scope -= y llmcf_scope | |
execute store result storage llmcf register int 1 run scoreboard players get tmp3 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
execute store result storage llmcf register int 1 run scoreboard players get tmp9 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
execute store result storage llmcf register int 1 run scoreboard players get tmp22 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
execute store result storage llmcf register int 1 run scoreboard players get y llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register | |
function llmcf:gcd_entry | |
execute store result score tmp24 llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result score tmp9 llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result score tmp3 llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result storage llmcf register int 1 run scoreboard players get tmp24 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int mul_add(int x, int y, int z) { | |
return x * y + z; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define i32 @mul_add(i32 %x, i32 %y, i32 %z) { | |
entry: | |
%tmp = mul i32 %x, %y | |
%tmp2 = add i32 %tmp, %z | |
ret i32 %tmp2 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
execute store result score z llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result score y llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
execute store result score x llmcf_scope run data get storage llmcf stack[-1] | |
data remove storage llmcf stack[-1] | |
scoreboard players operation tmp llmcf_scope = x llmcf_scope | |
scoreboard players operation tmp llmcf_scope *= y llmcf_scope | |
scoreboard players operation tmp2 llmcf_scope = tmp llmcf_scope | |
scoreboard players operation tmp2 llmcf_scope += z llmcf_scope | |
execute store result storage llmcf register int 1 run scoreboard players get tmp2 llmcf_scope | |
data modify storage llmcf stack append from storage llmcf register |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment