Skip to content

Commit

Permalink
Make comparation component flexible, add memset intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn committed Nov 16, 2023
1 parent 9cd288e commit f81154d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions include/nil/blueprint/comparison/comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <nil/blueprint/asserts.hpp>
#include <nil/blueprint/stack.hpp>
#include <nil/blueprint/policy/policy_manager.hpp>

namespace nil {
namespace blueprint {
Expand All @@ -57,13 +58,19 @@ namespace nil {
// TODO(maksenov): replace naive handling with the component
switch (p) {
case llvm::CmpInst::ICMP_EQ: {
eq_component_type component_instance = eq_component_type({0, 1, 2, 3, 4}, {0}, {0}, false);
const auto p = detail::PolicyManager::get_parameters(detail::ManifestReader<eq_component_type, ArithmetizationParams>::get_witness(0, false));
eq_component_type component_instance = eq_component_type(p.witness,
detail::ManifestReader<eq_component_type, ArithmetizationParams>::get_constants(),
detail::ManifestReader<eq_component_type, ArithmetizationParams>::get_public_inputs(), false);
components::generate_circuit(component_instance, bp, assignment, {x, y}, start_row);
return components::generate_assignments(component_instance, assignment, {x, y}, start_row).output;
break;
}
case llvm::CmpInst::ICMP_NE:{
eq_component_type component_instance = eq_component_type({0, 1, 2, 3, 4}, {0}, {0}, true);
const auto p = detail::PolicyManager::get_parameters(detail::ManifestReader<eq_component_type, ArithmetizationParams>::get_witness(0, true));
eq_component_type component_instance = eq_component_type(p.witness,
detail::ManifestReader<eq_component_type, ArithmetizationParams>::get_constants(),
detail::ManifestReader<eq_component_type, ArithmetizationParams>::get_public_inputs(), true);
components::generate_circuit(component_instance, bp, assignment, {x, y}, start_row);
return components::generate_assignments(component_instance, assignment, {x, y}, start_row).output;
break;
Expand Down
16 changes: 16 additions & 0 deletions include/nil/blueprint/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@ namespace nil {
}
}

void memset(ptr_type dst, var val, unsigned width) {
unsigned filled = 0;
while (filled < width) {
filled += stack_memory[dst].size;
stack_memory[dst++].v = val;
}
}

bool handle_intrinsic(const llvm::CallInst *inst, llvm::Intrinsic::ID id, stack_frame<var> &frame, uint32_t start_row, bool next_prover) {
// Passing constants to component directly is only supported for bit decomposition
if (
Expand Down Expand Up @@ -431,6 +439,14 @@ namespace nil {
memcpy(dst, src, width);
return true;
}
case llvm::Intrinsic::memset: {
ptr_type dst = resolve_number<ptr_type>(frame, inst->getOperand(0));
unsigned width = resolve_number<unsigned>(frame, inst->getOperand(2));
ASSERT(frame.scalars.find(inst->getOperand(1)) != frame.scalars.end());
const auto value_var = frame.scalars[inst->getOperand(1)];
memset(dst, value_var, width);
return true;
}
case llvm::Intrinsic::assigner_zkml_convolution: {
UNREACHABLE("zkml_convolution intrinsic is not implemented yet");
return false;
Expand Down

0 comments on commit f81154d

Please sign in to comment.