Skip to content

Commit

Permalink
Small code refactoring
Browse files Browse the repository at this point in the history
Can be treated as part of #180.
  • Loading branch information
aleasims committed Mar 4, 2024
1 parent 8933e7e commit b9d0bea
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
28 changes: 22 additions & 6 deletions include/nil/blueprint/non_native_marshalling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@
#ifndef CRYPTO3_ASSIGNER_NON_NATIVE_MARSHALLING_HPP
#define CRYPTO3_ASSIGNER_NON_NATIVE_MARSHALLING_HPP

#include <nil/blueprint/basic_non_native_policy.hpp>

#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/crypto3/algebra/curves/ed25519.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
// TODO: this include should be replaced with more precise and appropriate one, but I couldn't find it.
#include <nil/crypto3/marshalling/zk/types/plonk/constraint_system.hpp>
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/ZK/ZKEnums.h"

#include <iostream>

namespace nil {
namespace blueprint {

Expand Down Expand Up @@ -125,16 +141,16 @@ namespace nil {

}

/// @brief Get number of native fields ("chunks") used to store a single non-native field element.
template<typename BlueprintFieldType>
std::size_t field_arg_num(llvm::Type *arg_type) {
ASSERT_MSG(llvm::isa<llvm::GaloisFieldType>(arg_type), "only fields can be handled here");
return field_kind_size<BlueprintFieldType>(llvm::cast<llvm::GaloisFieldType>(arg_type)->getFieldKind());
std::size_t field_chunks_num(llvm::GaloisFieldType *type) {
return field_kind_size<BlueprintFieldType>(type->getFieldKind());
}

/// @brief Get number of native fields ("chunks") used to store a single non-native curve element.
template<typename BlueprintFieldType>
std::size_t curve_arg_num(llvm::Type *arg_type) {
ASSERT_MSG(llvm::isa<llvm::EllipticCurveType>(arg_type), "only curves can be handled here");
return 2 * field_kind_size<BlueprintFieldType>(llvm::cast<llvm::EllipticCurveType>(arg_type)->GetBaseFieldKind());
std::size_t curve_chunks_num(llvm::EllipticCurveType *type) {
return 2 * field_kind_size<BlueprintFieldType>(type->GetBaseFieldKind());
}

template<typename BlueprintFieldType, typename NonNativeFieldType>
Expand Down
16 changes: 12 additions & 4 deletions include/nil/blueprint/stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@
#include <llvm/IR/Instructions.h>
#include "llvm/IR/Constants.h"

#include <nil/blueprint/memory.hpp>

namespace nil {
namespace blueprint {

template<typename VarType>
struct stack_frame {
std::map<const llvm::Value *, VarType> scalars;
std::map<const llvm::Value *, std::vector<VarType>> vectors;
/// @brief Type representing scalar registers.
using scalar_regs = std::map<const llvm::Value *, VarType>;

/// @brief Type representing vector registers.
using vector_regs = std::map<const llvm::Value *, std::vector<VarType>>;

/// @brief Registers holding scalar values (integers, pointers, native fields).
scalar_regs scalars;

/// @brief Registers holding vector values (non-native fields, curves, vectors, etc.).
vector_regs vectors;

const llvm::CallInst *caller;
};

Expand Down

0 comments on commit b9d0bea

Please sign in to comment.