# HG changeset patch # User Max Brister # Date 1344895514 18000 # Node ID 6242904370bde5a52ef965d445e30d3e5b2b8c3d # Parent 66dcad99b55e758d5028d7892153cb27c259ebbb Support balance, cond, det, norm, rand, magic, eye, and mod in JIT * jit-typeinfo.cc (jit_typeinfo::jit_typeinfo): Add builtin functions. (jit_call): Remove return type checks that were too agressive. (jit_typeinfo::register_generic): Only grab if the grab function exists. * pt-jit.cc: Add a test case. diff --git a/src/interp-core/jit-typeinfo.cc b/src/interp-core/jit-typeinfo.cc --- a/src/interp-core/jit-typeinfo.cc +++ b/src/interp-core/jit-typeinfo.cc @@ -441,26 +441,16 @@ ovl = fn (ovl, 1); - // These type checks are not strictly required, but I'm guessing that - // incorrect types will be entered on occasion. This will be very difficult to - // debug unless we do the sanity check here. + // FIXME: Check result_type somehow if (result_type) { - if (ovl.length () != 1) + if (ovl.length () < 1) { gripe_bad_result (); return 0; } - octave_value& result = ovl.xelem (0); - jit_type *jtype = jit_typeinfo::join (jit_typeinfo::type_of (result), - result_type); - if (jtype != result_type) - { - gripe_bad_result (); - return 0; - } - + octave_value result = ovl.xelem(0); octave_base_value *ret = result.internal_rep (); ret->grab (); return ret; @@ -1817,6 +1807,33 @@ register_intrinsic ("exp", llvm::Intrinsic::cos, scalar, scalar); register_generic ("exp", matrix, matrix); + add_builtin ("balance"); + register_generic ("balance", matrix, matrix); + + add_builtin ("cond"); + register_generic ("cond", scalar, matrix); + + add_builtin ("det"); + register_generic ("det", scalar, matrix); + + add_builtin ("norm"); + register_generic ("norm", scalar, matrix); + + add_builtin ("rand"); + register_generic ("rand", matrix, scalar); + register_generic ("rand", matrix, std::vector (2, scalar)); + + add_builtin ("magic"); + register_generic ("magic", matrix, scalar); + register_generic ("magic", matrix, std::vector (2, scalar)); + + add_builtin ("eye"); + register_generic ("eye", matrix, scalar); + register_generic ("eye", matrix, std::vector (2, scalar)); + + add_builtin ("mod"); + register_generic ("mod", scalar, std::vector (2, scalar)); + casts.resize (next_id + 1); jit_function any_id = create_identity (any); jit_function release_any = get_release (any); @@ -2046,9 +2063,10 @@ { llvm::Value *arg = fn.argument (builder, i + 1); jit_function agrab = get_grab (args[i]); - llvm::Value *garg = agrab.call (builder, arg); + if (agrab.valid ()) + arg = agrab.call (builder, arg); jit_function acast = cast (any, args[i]); - array = builder.CreateInsertValue (array, acast.call (builder, garg), i); + array = builder.CreateInsertValue (array, acast.call (builder, arg), i); } llvm::Value *array_mem = builder.CreateAlloca (array_t); diff --git a/src/interp-core/pt-jit.cc b/src/interp-core/pt-jit.cc --- a/src/interp-core/pt-jit.cc +++ b/src/interp-core/pt-jit.cc @@ -1999,4 +1999,14 @@ %! assert (i == 10); %! assert (a == 9); +%!test +%! num = 2; +%! a = zeros (1, num); +%! i = 1; +%! while i <= num +%! a(i) = norm (eye (i)); +%! ++i; +%! endwhile +%! assert (a, ones (1, num)); + */