Commit cce66456 authored by John Zhang's avatar John Zhang

added million sum test; added TRUNC, SEXT, ZEXT tests

parent 327fcb9d
// Compile with flag -std=c99
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include "muapi.h"
#include "mu-fastimpl.h"
int main(int argc, char** argv) {
MuVM* mu;
MuCtx* ctx;
MuIRBuilder* bldr;
MuID id;
MuID id_2;
MuID id_3;
MuID id_4;
MuID id_5;
MuID id_6;
MuID id_7;
MuID id_8;
MuID id_9;
MuID id_10;
MuID id_11;
MuID id_12;
MuID id_13;
MuID id_14;
MuID id_15;
MuID id_16;
MuID id_17;
MuID id_18;
MuID id_19;
MuID id_20;
MuID id_21;
MuID id_22;
MuID id_23;
MuID id_24;
MuID id_25;
MuID id_26;
MuID id_27;
MuID id_28;
MuID id_29;
MuID id_30;
MuID id_31;
MuID id_32;
mu = mu_fastimpl_new();
ctx = mu->new_context(mu);
bldr = ctx->new_ir_builder(ctx);
id = bldr->gen_sym(bldr, "@i64");
bldr->new_type_int(bldr, id, 64);
id_2 = bldr->gen_sym(bldr, "@0_i64");
bldr->new_const_int(bldr, id_2, id, 0);
id_3 = bldr->gen_sym(bldr, "@1_i64");
bldr->new_const_int(bldr, id_3, id, 1);
id_4 = bldr->gen_sym(bldr, "@sig_i64_i64");
bldr->new_funcsig(bldr, id_4, (MuTypeNode [1]){id}, 1, (MuTypeNode [1]){id}, 1);
id_5 = bldr->gen_sym(bldr, "@milsum");
bldr->new_func(bldr, id_5, id_4);
id_6 = bldr->gen_sym(bldr, "@milsum.v1");
id_7 = bldr->gen_sym(bldr, "@milsum.v1.blk0");
id_8 = bldr->gen_sym(bldr, "@milsum.v1.blk1");
id_9 = bldr->gen_sym(bldr, "@milsum.v1.blk2");
id_10 = bldr->gen_sym(bldr, "@milsum.v1.blk3");
id_11 = bldr->gen_sym(bldr, "@milsum.v1.blk0.k");
id_12 = bldr->gen_sym(bldr, NULL);
bldr->new_dest_clause(bldr, id_12, id_8, (MuVarNode [3]){id_2, id_2, id_11}, 3);
id_13 = bldr->gen_sym(bldr, NULL);
bldr->new_branch(bldr, id_13, id_12);
bldr->new_bb(bldr, id_7, (MuID [1]){id_11}, (MuTypeNode [1]){id}, 1, MU_NO_ID, (MuInstNode [1]){id_13}, 1);
id_14 = bldr->gen_sym(bldr, "@milsum.v1.blk1.acc");
id_15 = bldr->gen_sym(bldr, "@milsum.v1.blk1.i");
id_16 = bldr->gen_sym(bldr, "@milsum.v1.blk1.end");
id_17 = bldr->gen_sym(bldr, "@milsum.v1.blk1.cmpres");
id_18 = bldr->gen_sym(bldr, NULL);
bldr->new_cmp(bldr, id_18, id_17, MU_CMP_EQ, id, id_15, id_16);
id_19 = bldr->gen_sym(bldr, NULL);
id_20 = bldr->gen_sym(bldr, NULL);
bldr->new_dest_clause(bldr, id_20, id_10, (MuVarNode [1]){id_14}, 1);
id_21 = bldr->gen_sym(bldr, NULL);
bldr->new_dest_clause(bldr, id_21, id_9, (MuVarNode [3]){id_14, id_15, id_16}, 3);
bldr->new_branch2(bldr, id_19, id_17, id_20, id_21);
bldr->new_bb(bldr, id_8, (MuID [3]){id_14, id_15, id_16}, (MuTypeNode [3]){id, id, id}, 3, MU_NO_ID, (MuInstNode [2]){id_18, id_19}, 2);
id_22 = bldr->gen_sym(bldr, "@milsum.v1.blk2.acc");
id_23 = bldr->gen_sym(bldr, "@milsum.v1.blk2.i");
id_24 = bldr->gen_sym(bldr, "@milsum.v1.blk2.end");
id_25 = bldr->gen_sym(bldr, "@milsum.v1.blk2.acc_res");
id_26 = bldr->gen_sym(bldr, "@milsum.v1.blk2.i_res");
id_27 = bldr->gen_sym(bldr, NULL);
bldr->new_binop(bldr, id_27, id_26, MU_BINOP_ADD, id, id_23, id_3, MU_NO_ID);
id_28 = bldr->gen_sym(bldr, NULL);
bldr->new_binop(bldr, id_28, id_25, MU_BINOP_ADD, id, id_22, id_26, MU_NO_ID);
id_29 = bldr->gen_sym(bldr, NULL);
bldr->new_dest_clause(bldr, id_29, id_8, (MuVarNode [3]){id_25, id_26, id_24}, 3);
id_30 = bldr->gen_sym(bldr, NULL);
bldr->new_branch(bldr, id_30, id_29);
bldr->new_bb(bldr, id_9, (MuID [3]){id_22, id_23, id_24}, (MuTypeNode [3]){id, id, id}, 3, MU_NO_ID, (MuInstNode [3]){id_27, id_28, id_30}, 3);
id_31 = bldr->gen_sym(bldr, "@milsum.v1.blk3.rtn");
id_32 = bldr->gen_sym(bldr, NULL);
bldr->new_ret(bldr, id_32, (MuVarNode [1]){id_31}, 1);
bldr->new_bb(bldr, id_10, (MuID [1]){id_31}, (MuTypeNode [1]){id}, 1, MU_NO_ID, (MuInstNode [1]){id_32}, 1);
bldr->new_func_ver(bldr, id_6, id_5, (MuBBNode [4]){id_7, id_8, id_9, id_10}, 4);
mu->compile_to_sharedlib(mu, "test_milsum.dylib", NULL, 0);
printf("%s\n", "test_milsum.dylib");
return 0;
// Compile with flag -std=c99
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include "muapi.h"
#include "mu-fastimpl.h"
int main(int argc, char** argv) {
MuVM* mu_20;
MuCtx* ctx_20;
MuIRBuilder* bldr_20;
MuID id_242;
MuID id_243;
MuID id_244;
MuID id_245;
MuID id_246;
MuID id_247;
MuID id_248;
MuID id_249;
MuID id_250;
MuID id_251;
mu_20 = mu_fastimpl_new();
ctx_20 = mu_20->new_context(mu_20);
bldr_20 = ctx_20->new_ir_builder(ctx_20);
id_242 = bldr_20->gen_sym(bldr_20, "@i32");
bldr_20->new_type_int(bldr_20, id_242, 32);
id_243 = bldr_20->gen_sym(bldr_20, "@i64");
bldr_20->new_type_int(bldr_20, id_243, 64);
id_244 = bldr_20->gen_sym(bldr_20, "@0xa8324b55_i32");
bldr_20->new_const_int(bldr_20, id_244, id_243, 2821868373);
id_245 = bldr_20->gen_sym(bldr_20, "@sig__i64");
bldr_20->new_funcsig(bldr_20, id_245, NULL, 0, (MuTypeNode [1]){id_243}, 1);
id_246 = bldr_20->gen_sym(bldr_20, "@test_fnc");
bldr_20->new_func(bldr_20, id_246, id_245);
id_247 = bldr_20->gen_sym(bldr_20, "@test_fnc_v1");
id_248 = bldr_20->gen_sym(bldr_20, "@test_fnc_v1.blk0");
id_249 = bldr_20->gen_sym(bldr_20, "@test_fnc_v1.blk0.res");
id_250 = bldr_20->gen_sym(bldr_20, NULL);
bldr_20->new_conv(bldr_20, id_250, id_249, MU_CONV_SEXT, id_242, id_243, id_244);
id_251 = bldr_20->gen_sym(bldr_20, NULL);
bldr_20->new_ret(bldr_20, id_251, (MuVarNode [1]){id_249}, 1);
bldr_20->new_bb(bldr_20, id_248, NULL, NULL, 0, MU_NO_ID, (MuInstNode [2]){id_250, id_251}, 2);
bldr_20->new_func_ver(bldr_20, id_247, id_246, (MuBBNode [1]){id_248}, 1);
mu_20->compile_to_sharedlib(mu_20, "test_sext.dylib", NULL, 0);
printf("%s\n", "test_sext.dylib");
return 0;
// Compile with flag -std=c99
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include "muapi.h"
#include "mu-fastimpl.h"
int main(int argc, char** argv) {
MuVM* mu_19;
MuCtx* ctx_19;
MuIRBuilder* bldr_19;
MuID id_232;
MuID id_233;
MuID id_234;
MuID id_235;
MuID id_236;
MuID id_237;
MuID id_238;
MuID id_239;
MuID id_240;
MuID id_241;
mu_19 = mu_fastimpl_new();
ctx_19 = mu_19->new_context(mu_19);
bldr_19 = ctx_19->new_ir_builder(ctx_19);
id_232 = bldr_19->gen_sym(bldr_19, "@i32");
bldr_19->new_type_int(bldr_19, id_232, 32);
id_233 = bldr_19->gen_sym(bldr_19, "@i64");
bldr_19->new_type_int(bldr_19, id_233, 64);
id_234 = bldr_19->gen_sym(bldr_19, "@0x6d9f9c1d58324b55_i64");
bldr_19->new_const_int(bldr_19, id_234, id_233, 7899203921278815061);
id_235 = bldr_19->gen_sym(bldr_19, "@sig__i32");
bldr_19->new_funcsig(bldr_19, id_235, NULL, 0, (MuTypeNode [1]){id_232}, 1);
id_236 = bldr_19->gen_sym(bldr_19, "@test_fnc");
bldr_19->new_func(bldr_19, id_236, id_235);
id_237 = bldr_19->gen_sym(bldr_19, "@test_fnc_v1");
id_238 = bldr_19->gen_sym(bldr_19, "@test_fnc_v1.blk0");
id_239 = bldr_19->gen_sym(bldr_19, "@test_fnc_v1.blk0.res");
id_240 = bldr_19->gen_sym(bldr_19, NULL);
bldr_19->new_conv(bldr_19, id_240, id_239, MU_CONV_TRUNC, id_233, id_232, id_234);
id_241 = bldr_19->gen_sym(bldr_19, NULL);
bldr_19->new_ret(bldr_19, id_241, (MuVarNode [1]){id_239}, 1);
bldr_19->new_bb(bldr_19, id_238, NULL, NULL, 0, MU_NO_ID, (MuInstNode [2]){id_240, id_241}, 2);
bldr_19->new_func_ver(bldr_19, id_237, id_236, (MuBBNode [1]){id_238}, 1);
mu_19->compile_to_sharedlib(mu_19, "test_trunc.dylib", NULL, 0);
printf("%s\n", "test_trunc.dylib");
return 0;
// Compile with flag -std=c99
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <dlfcn.h>
#include "muapi.h"
#include "mu-fastimpl.h"
int main(int argc, char** argv) {
MuVM* mu_21;
MuCtx* ctx_21;
MuIRBuilder* bldr_21;
MuID id_252;
MuID id_253;
MuID id_254;
MuID id_255;
MuID id_256;
MuID id_257;
MuID id_258;
MuID id_259;
MuID id_260;
MuID id_261;
mu_21 = mu_fastimpl_new();
ctx_21 = mu_21->new_context(mu_21);
bldr_21 = ctx_21->new_ir_builder(ctx_21);
id_252 = bldr_21->gen_sym(bldr_21, "@i32");
bldr_21->new_type_int(bldr_21, id_252, 32);
id_253 = bldr_21->gen_sym(bldr_21, "@i64");
bldr_21->new_type_int(bldr_21, id_253, 64);
id_254 = bldr_21->gen_sym(bldr_21, "@0xa8324b55_i32");
bldr_21->new_const_int(bldr_21, id_254, id_253, 2821868373);
id_255 = bldr_21->gen_sym(bldr_21, "@sig__i64");
bldr_21->new_funcsig(bldr_21, id_255, NULL, 0, (MuTypeNode [1]){id_253}, 1);
id_256 = bldr_21->gen_sym(bldr_21, "@test_fnc");
bldr_21->new_func(bldr_21, id_256, id_255);
id_257 = bldr_21->gen_sym(bldr_21, "@test_fnc_v1");
id_258 = bldr_21->gen_sym(bldr_21, "@test_fnc_v1.blk0");
id_259 = bldr_21->gen_sym(bldr_21, "@test_fnc_v1.blk0.res");
id_260 = bldr_21->gen_sym(bldr_21, NULL);
bldr_21->new_conv(bldr_21, id_260, id_259, MU_CONV_ZEXT, id_252, id_253, id_254);
id_261 = bldr_21->gen_sym(bldr_21, NULL);
bldr_21->new_ret(bldr_21, id_261, (MuVarNode [1]){id_259}, 1);
bldr_21->new_bb(bldr_21, id_258, NULL, NULL, 0, MU_NO_ID, (MuInstNode [2]){id_260, id_261}, 2);
bldr_21->new_func_ver(bldr_21, id_257, id_256, (MuBBNode [1]){id_258}, 1);
mu_21->compile_to_sharedlib(mu_21, "test_zext.dylib", NULL, 0);
printf("%s\n", "test_zext.dylib");
return 0;
from test_milestones import get_fncptr
def test_trunc():
fn = get_fncptr("test_trunc", "test_fnc")
assert fn() == 0x58324b55
def test_sext():
fn = get_fncptr("test_sext", "test_fnc")
assert fn() == 0xffffffffa8324b55
def test_zext():
fn = get_fncptr("test_zext", "test_fnc")
assert fn() == 0x00000000a8324b55
......@@ -55,6 +55,10 @@ def test_constant_function():
fn = get_fncptr("test_constfunc", 'test_fnc')
assert fn() == 0
def test_milsum():
fn = get_fncptr("test_milsum", "milsum")
assert fn(1000000) == 500000500000
def test_fibonacci():
fn = get_fncptr("test_fib", "fib")
assert fn(20) == 6765
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment