MCPcopy Create free account
hub / github.com/data61/MP-SPDZ / run_function

Method run_function

Processor/Machine.hpp:424–503  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422
423template<class sint, class sgf2n>
424void Machine<sint, sgf2n>::run_function(const string& name,
425 FunctionArgument& result, vector<FunctionArgument>& arguments)
426{
427 ifstream file;
428 FunctionArgument::open(file, name, arguments);
429
430 string progname, return_type;
431 int tape_number, return_reg;
432 file >> progname >> tape_number >> return_type >> return_reg;
433
434 result.check_type(return_type);
435
436 vector<int> arg_regs(arguments.size());
437 vector<int> address_regs(arguments.size());
438 for (size_t i = 0; i < arguments.size(); i++)
439 {
440 file >> arg_regs.at(i);
441 if (arguments[i].get_memory())
442 file >> address_regs.at(i);
443 }
444
445 if (not file.good())
446 throw runtime_error("error reading file for function " + name);
447
448 prepare(progname);
449 auto& processor = *tinfo.at(0).processor;
450 processor.reset(progs.at(tape_number), 0);
451
452 for (size_t i = 0; i < arguments.size(); i++)
453 for (size_t j = 0; j < arguments[i].get_size(); j++)
454 {
455 if (arguments[i].get_n_bits())
456 {
457 size_t n_limbs = DIV_CEIL(arguments[i].get_n_bits(),
458 sint::bit_type::default_length);
459 for (size_t k = 0; k < n_limbs; k++)
460 bit_memories.MS[arg_regs.at(i) + j * n_limbs + k] =
461 arguments[i].get_value<vector<typename sint::bit_type>>(j).at(
462 k);
463 }
464 else if (arguments[i].has_reg_type("s"))
465 {
466 auto& value = arguments[i].get_value<sint>(j);
467 if (arguments[i].get_memory())
468 Mp.MS[arg_regs.at(i) + j] = value;
469 else
470 processor.Procp.get_S()[arg_regs.at(i) + j] = value;
471 }
472 else
473 {
474 assert(arguments[i].has_reg_type("ci"));
475 processor.write_Ci(arg_regs.at(i) + j, arguments[i].get_value<long>(j));
476 }
477 if (arguments[i].get_memory())
478 processor.write_Ci(address_regs.at(i), arg_regs.at(i));
479 }
480
481 run_tape(0, tape_number, 0, N.num_players());

Callers 5

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
runFunction · 0.80
mainFunction · 0.80

Calls 13

runtime_errorFunction · 0.85
DIV_CEILFunction · 0.85
run_tapeClass · 0.85
join_tapeClass · 0.85
check_typeMethod · 0.80
get_memoryMethod · 0.80
get_n_bitsMethod · 0.80
has_reg_typeMethod · 0.80
write_CiMethod · 0.80
sizeMethod · 0.45
resetMethod · 0.45
get_sizeMethod · 0.45

Tested by

no test coverage detected