Commit 3fce5a32 authored by John Zhang's avatar John Zhang

double precision floating point and integer conversion

parent d01fd2c5
Pipeline #189 failed with stage
in 24 minutes and 34 seconds
// 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_38;
MuCtx* ctx_38;
MuIRBuilder* bldr_38;
MuID id_478;
MuID id_479;
MuID id_480;
MuID id_481;
MuID id_482;
MuID id_483;
MuID id_484;
MuID id_485;
MuID id_486;
MuID id_487;
MuID id_488;
mu_38 = mu_fastimpl_new_with_opts("init_mu --log-level=none --aot-emit-dir=emit");
ctx_38 = mu_38->new_context(mu_38);
bldr_38 = ctx_38->new_ir_builder(ctx_38);
id_478 = bldr_38->gen_sym(bldr_38, "@dbl");
bldr_38->new_type_double(bldr_38, id_478);
id_479 = bldr_38->gen_sym(bldr_38, "@i1");
bldr_38->new_type_int(bldr_38, id_479, 1);
id_480 = bldr_38->gen_sym(bldr_38, "@i64");
bldr_38->new_type_int(bldr_38, id_480, 64);
id_481 = bldr_38->gen_sym(bldr_38, "@npi");
bldr_38->new_const_double(bldr_38, id_481, id_478, -3.14159260000000006841);
id_482 = bldr_38->gen_sym(bldr_38, "@sig__i64");
bldr_38->new_funcsig(bldr_38, id_482, NULL, 0, (MuTypeNode [1]){id_480}, 1);
id_483 = bldr_38->gen_sym(bldr_38, "@test_fnc");
bldr_38->new_func(bldr_38, id_483, id_482);
id_484 = bldr_38->gen_sym(bldr_38, "@test_fnc.v1");
id_485 = bldr_38->gen_sym(bldr_38, "@test_fnc.v1.blk0");
id_486 = bldr_38->gen_sym(bldr_38, "@test_fnc.v1.blk0.res");
id_487 = bldr_38->gen_sym(bldr_38, NULL);
bldr_38->new_conv(bldr_38, id_487, id_486, MU_CONV_FPTOSI, id_478, id_480, id_481);
id_488 = bldr_38->gen_sym(bldr_38, NULL);
bldr_38->new_ret(bldr_38, id_488, (MuVarNode [1]){id_486}, 1);
bldr_38->new_bb(bldr_38, id_485, NULL, NULL, 0, MU_NO_ID, (MuInstNode [2]){id_487, id_488}, 2);
bldr_38->new_func_ver(bldr_38, id_484, id_483, (MuBBNode [1]){id_485}, 1);
mu_38->compile_to_sharedlib(mu_38, "test_double_fptosi.dylib", NULL, 0);
printf("%s\n", "test_double_fptosi.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_40;
MuCtx* ctx_40;
MuIRBuilder* bldr_40;
MuID id_500;
MuID id_501;
MuID id_502;
MuID id_503;
MuID id_504;
MuID id_505;
MuID id_506;
MuID id_507;
MuID id_508;
MuID id_509;
MuID id_510;
mu_40 = mu_fastimpl_new_with_opts("init_mu --log-level=none --aot-emit-dir=emit");
ctx_40 = mu_40->new_context(mu_40);
bldr_40 = ctx_40->new_ir_builder(ctx_40);
id_500 = bldr_40->gen_sym(bldr_40, "@dbl");
bldr_40->new_type_double(bldr_40, id_500);
id_501 = bldr_40->gen_sym(bldr_40, "@i1");
bldr_40->new_type_int(bldr_40, id_501, 1);
id_502 = bldr_40->gen_sym(bldr_40, "@i64");
bldr_40->new_type_int(bldr_40, id_502, 64);
id_503 = bldr_40->gen_sym(bldr_40, "@pi");
bldr_40->new_const_double(bldr_40, id_503, id_500, 3.14159260000000006841);
id_504 = bldr_40->gen_sym(bldr_40, "@sig__i64");
bldr_40->new_funcsig(bldr_40, id_504, NULL, 0, (MuTypeNode [1]){id_502}, 1);
id_505 = bldr_40->gen_sym(bldr_40, "@test_fnc");
bldr_40->new_func(bldr_40, id_505, id_504);
id_506 = bldr_40->gen_sym(bldr_40, "@test_fnc.v1");
id_507 = bldr_40->gen_sym(bldr_40, "@test_fnc.v1.blk0");
id_508 = bldr_40->gen_sym(bldr_40, "@test_fnc.v1.blk0.res");
id_509 = bldr_40->gen_sym(bldr_40, NULL);
bldr_40->new_conv(bldr_40, id_509, id_508, MU_CONV_FPTOUI, id_500, id_502, id_503);
id_510 = bldr_40->gen_sym(bldr_40, NULL);
bldr_40->new_ret(bldr_40, id_510, (MuVarNode [1]){id_508}, 1);
bldr_40->new_bb(bldr_40, id_507, NULL, NULL, 0, MU_NO_ID, (MuInstNode [2]){id_509, id_510}, 2);
bldr_40->new_func_ver(bldr_40, id_506, id_505, (MuBBNode [1]){id_507}, 1);
mu_40->compile_to_sharedlib(mu_40, "test_double_fptoui.dylib", NULL, 0);
printf("%s\n", "test_double_fptoui.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_37;
MuCtx* ctx_37;
MuIRBuilder* bldr_37;
MuID id_467;
MuID id_468;
MuID id_469;
MuID id_470;
MuID id_471;
MuID id_472;
MuID id_473;
MuID id_474;
MuID id_475;
MuID id_476;
MuID id_477;
mu_37 = mu_fastimpl_new_with_opts("init_mu --log-level=none --aot-emit-dir=emit");
ctx_37 = mu_37->new_context(mu_37);
bldr_37 = ctx_37->new_ir_builder(ctx_37);
id_467 = bldr_37->gen_sym(bldr_37, "@dbl");
bldr_37->new_type_double(bldr_37, id_467);
id_468 = bldr_37->gen_sym(bldr_37, "@i1");
bldr_37->new_type_int(bldr_37, id_468, 1);
id_469 = bldr_37->gen_sym(bldr_37, "@i64");
bldr_37->new_type_int(bldr_37, id_469, 64);
id_470 = bldr_37->gen_sym(bldr_37, "@k");
bldr_37->new_const_int(bldr_37, id_470, id_469, -42);
id_471 = bldr_37->gen_sym(bldr_37, "@sig__dbl");
bldr_37->new_funcsig(bldr_37, id_471, NULL, 0, (MuTypeNode [1]){id_467}, 1);
id_472 = bldr_37->gen_sym(bldr_37, "@test_fnc");
bldr_37->new_func(bldr_37, id_472, id_471);
id_473 = bldr_37->gen_sym(bldr_37, "@test_fnc.v1");
id_474 = bldr_37->gen_sym(bldr_37, "@test_fnc.v1.blk0");
id_475 = bldr_37->gen_sym(bldr_37, "@test_fnc.v1.blk0.res");
id_476 = bldr_37->gen_sym(bldr_37, NULL);
bldr_37->new_conv(bldr_37, id_476, id_475, MU_CONV_SITOFP, id_469, id_467, id_470);
id_477 = bldr_37->gen_sym(bldr_37, NULL);
bldr_37->new_ret(bldr_37, id_477, (MuVarNode [1]){id_475}, 1);
bldr_37->new_bb(bldr_37, id_474, NULL, NULL, 0, MU_NO_ID, (MuInstNode [2]){id_476, id_477}, 2);
bldr_37->new_func_ver(bldr_37, id_473, id_472, (MuBBNode [1]){id_474}, 1);
mu_37->compile_to_sharedlib(mu_37, "test_double_sitofp.dylib", NULL, 0);
printf("%s\n", "test_double_sitofp.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_39;
MuCtx* ctx_39;
MuIRBuilder* bldr_39;
MuID id_489;
MuID id_490;
MuID id_491;
MuID id_492;
MuID id_493;
MuID id_494;
MuID id_495;
MuID id_496;
MuID id_497;
MuID id_498;
MuID id_499;
mu_39 = mu_fastimpl_new_with_opts("init_mu --log-level=none --aot-emit-dir=emit");
ctx_39 = mu_39->new_context(mu_39);
bldr_39 = ctx_39->new_ir_builder(ctx_39);
id_489 = bldr_39->gen_sym(bldr_39, "@dbl");
bldr_39->new_type_double(bldr_39, id_489);
id_490 = bldr_39->gen_sym(bldr_39, "@i1");
bldr_39->new_type_int(bldr_39, id_490, 1);
id_491 = bldr_39->gen_sym(bldr_39, "@i64");
bldr_39->new_type_int(bldr_39, id_491, 64);
id_492 = bldr_39->gen_sym(bldr_39, "@k");
bldr_39->new_const_int(bldr_39, id_492, id_491, 42);
id_493 = bldr_39->gen_sym(bldr_39, "@sig__dbl");
bldr_39->new_funcsig(bldr_39, id_493, NULL, 0, (MuTypeNode [1]){id_489}, 1);
id_494 = bldr_39->gen_sym(bldr_39, "@test_fnc");
bldr_39->new_func(bldr_39, id_494, id_493);
id_495 = bldr_39->gen_sym(bldr_39, "@test_fnc.v1");
id_496 = bldr_39->gen_sym(bldr_39, "@test_fnc.v1.blk0");
id_497 = bldr_39->gen_sym(bldr_39, "@test_fnc.v1.blk0.res");
id_498 = bldr_39->gen_sym(bldr_39, NULL);
bldr_39->new_conv(bldr_39, id_498, id_497, MU_CONV_UITOFP, id_491, id_489, id_492);
id_499 = bldr_39->gen_sym(bldr_39, NULL);
bldr_39->new_ret(bldr_39, id_499, (MuVarNode [1]){id_497}, 1);
bldr_39->new_bb(bldr_39, id_496, NULL, NULL, 0, MU_NO_ID, (MuInstNode [2]){id_498, id_499}, 2);
bldr_39->new_func_ver(bldr_39, id_495, id_494, (MuBBNode [1]){id_496}, 1);
mu_39->compile_to_sharedlib(mu_39, "test_double_uitofp.dylib", NULL, 0);
printf("%s\n", "test_double_uitofp.dylib");
return 0;
......@@ -60,3 +60,24 @@ def test_double_arg_pass():
fnp, _ = fncptr_from_c_script("test_double_arg_pass.c", "test_fnc",
[ctypes.c_double, ctypes.c_double], ctypes.c_double)
assert fnp(3.141593, 2.71828) == 5.859873
def test_double_sitofp():
fnp, _ = fncptr_from_c_script("test_double_sitofp.c", "test_fnc", restype=ctypes.c_double)
assert fnp() == -42.0
def test_double_uitofp():
fnp, _ = fncptr_from_c_script("test_double_uitofp.c", "test_fnc", restype=ctypes.c_double)
assert fnp() == 42.0
def test_double_fptosi():
fnp, _ = fncptr_from_c_script("test_double_fptosi.c", "test_fnc", restype=ctypes.c_int64)
assert fnp() == -3
def test_double_fptoui():
fnp, _ = fncptr_from_c_script("test_double_fptoui.c", "test_fnc", restype=ctypes.c_uint64)
assert fnp() == 3
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