16 #include <libff/common/profiling.hpp>
17 #include <libff/common/utils.hpp>
114 std::vector<tinyram_instruction> result;
115 const size_t increment = libff::log2(ap.
w) / 8;
116 const size_t mem_start = 1ul << (ap.
w - 1);
176 for (
size_t i = 0; i < program.
instructions.size(); ++i) {
180 const size_t input_addr = 1ul << (
dwaddr_len() - 1);
184 size_t latest_double_word = (1ull << (
w - 1)) + primary_input.size();
185 for (
size_t i = 0; i < primary_input.size() / 2 + 1; ++i) {
186 if (2 * i < primary_input.size()) {
187 latest_double_word += (primary_input[2 * i] <<
w);
190 m[input_addr + i] = latest_double_word;
192 if (2 * i + 1 < primary_input.size()) {
193 latest_double_word = primary_input[2 * i + 1];
208 return libff::log2(
k);
224 return w - (libff::log2(
w) - 2);
229 return libff::log2(
w) - 2;
239 return (this->
w == other.
w && this->k == other.
k);
253 libff::consume_newline(in);
255 libff::consume_newline(in);
261 const bool arg2_is_imm,
262 const size_t &desidx,
263 const size_t &arg1idx,
264 const size_t &arg2idx_or_imm)
266 , arg2_is_imm(arg2_is_imm)
269 , arg2idx_or_imm(arg2idx_or_imm)
276 size_t result =
static_cast<size_t>(
opcode);
278 result = (result << libff::log2(ap.
k)) |
desidx;
279 result = (result << libff::log2(ap.
k)) |
arg1idx;
281 (result << (2 * ap.
w - ap.
opcode_width() - 1 - 2 * libff::log2(ap.
k))) |
289 printf(
"* Number of registers (k): %zu\n",
k);
290 printf(
"* Word size (w): %zu\n",
w);
298 const bool arg2_is_imm = std::rand() & 1;
299 const size_t desidx = std::rand() % (1ul << ap.
reg_arg_width());
300 const size_t arg1idx = std::rand() % (1ul << ap.
reg_arg_width());
301 const size_t arg2idx_or_imm =
304 opcode, arg2_is_imm, desidx, arg1idx, arg2idx_or_imm);
319 libff::enter_block(
"Loading program");
320 std::string instr, line;
322 while (preprocessed >> instr) {
323 libff::print_indent();
324 size_t immflag, des, a1;
326 if (preprocessed.good()) {
327 preprocessed >> immflag >> des >> a1 >> a2;
328 a2 = ((1ul << ap.
w) + (a2 % (1ul << ap.
w))) % (1ul << ap.
w);
333 libff::leave_block(
"Loading program");
340 const size_t boot_trace_size_bound,
348 size_t boot_pos = boot_trace_size_bound - 1;
349 for (
size_t i = 0; i < program.
instructions.size(); ++i) {
352 std::make_pair(i, program.
instructions[i].as_dword(ap)));
355 const size_t primary_input_base_addr = (1ul << (ap.
dwaddr_len() - 1));
357 for (
size_t j = 0; j < primary_input.size(); j += 2) {
358 const size_t memory_dword =
360 ((j + 1 < primary_input.size() ? primary_input[j + 1] : 0) << ap.
w);
363 std::make_pair(primary_input_base_addr + j, memory_dword));
371 libff::enter_block(
"Loading tape");
374 libff::print_indent();
375 printf(
"Tape contents:");
377 while (tape >> cell) {
378 printf(
"\t%zu", cell);
379 result.emplace_back(cell);
383 libff::leave_block(
"Loading tape");