Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit d1eb36c

Browse files
committed
Terms with coeff=1 profiling optimized #3
1 parent 0392521 commit d1eb36c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

include/nil/blueprint/transpiler/minimized_profiling_plonk_circuit.hpp

+19-6
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ namespace nil {
139139
for (std::size_t c_index = 0; c_index < gates[g_index].constraints.size(); c_index++) {
140140
gate_lines += 2;
141141
for (std::size_t t_index = 0; t_index < gates[g_index].constraints[c_index].terms.size(); t_index++) {
142-
gate_lines += 1;
142+
if(gates[g_index].constraints[c_index].terms[t_index].coeff != FieldType::value_type::one())
143+
gate_lines += 1;
143144
for (std::size_t v_index = 0; v_index < gates[g_index].constraints[c_index].terms[t_index].vars.size(); v_index++) {
144145
gate_lines += 1;
145146
}
@@ -405,18 +406,27 @@ namespace nil {
405406
static std::string generate_term(
406407
const profiling_params_type &profiling_params,
407408
const Vars &vars,
408-
columns_rotations_type &columns_rotations
409+
columns_rotations_type &columns_rotations,
410+
bool coeff_one = false
409411
) {
410412
std::stringstream res;
413+
bool first = true;
414+
411415
for( auto it = std::cbegin(vars); it != std::end(vars); it++){
416+
if( first ){
417+
first = false;
418+
if(coeff_one){
419+
res << "\t\t\tterms:=" << generate_variable(profiling_params, *it, columns_rotations) << std::endl;
420+
continue;
421+
}
422+
}
412423
res << "\t\t\tterms:=mulmod(terms, ";
413424
res << generate_variable(profiling_params, *it, columns_rotations);
414425
res << ", modulus)" << std::endl;
415426
}
416427
return res.str();
417428
}
418429

419-
//TODO: optimise coeff = 0x1;
420430
template<typename Terms>
421431
static std::string generate_terms(
422432
const profiling_params_type &profiling_params,
@@ -425,8 +435,12 @@ namespace nil {
425435
) {
426436
std::stringstream res;
427437
for( auto it = std::cbegin(terms); it != std::cend(terms); it++ ){
428-
res << "\t\t\tterms:=0x" << std::hex << it->coeff.data << std::dec << std::endl;
429-
res << generate_term(profiling_params, it->vars, columns_rotations);
438+
if(it->coeff == FieldType::value_type::one())
439+
res << generate_term(profiling_params, it->vars, columns_rotations, true);
440+
else {
441+
res << "\t\t\tterms:=0x" << std::hex << it->coeff.data << std::dec << std::endl;
442+
res << generate_term(profiling_params, it->vars, columns_rotations, false);
443+
}
430444
res << "\t\t\tmstore("
431445
"add(local_vars, CONSTRAINT_EVAL_OFFSET),"
432446
"addmod("
@@ -672,7 +686,6 @@ namespace nil {
672686
std::stringstream executions;
673687

674688
if(!profiling_params.optimize_gates){
675-
std::cout << "Non-optimized gates" << std::endl;
676689
for (const auto &gate : bp.gates()) {
677690
imports << "import \"./gate" << i << ".sol\";" << std::endl;
678691
executions << "\t\t(local_vars.gates_evaluation, local_vars.theta_acc) = gate"<< i <<".evaluate_gate_be(gate_params, local_vars);" << std::endl;

0 commit comments

Comments
 (0)