Skip to content

Commit

Permalink
libstark - first version
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRiabzev committed Feb 28, 2018
1 parent 336b481 commit 47225ef
Show file tree
Hide file tree
Showing 200 changed files with 33,379 additions and 0 deletions.
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
WHICH := $(shell which which)
PWD := $(shell $(WHICH) pwd)

#
WD := $(shell $(PWD))
BUILD_DIR := bin
EXE_DIR := $(WD)
BLDDIR := $(WD)/$(BUILD_DIR)
GADGETLIB3_SRC_DIR := tinyram/gadgetlib/gadgetlib
FFTLIB_SRC_DIR := algebra/FFT/src

ALGEBRALIB_DIR := $(WD)/algebra/algebralib
LIBSTARK_DIR := $(WD)/libstark
GADGETLIB3_DIR := $(WD)/$(GADGETLIB3_SRC_DIR)
TINYRAM_DIR := $(WD)/tinyram/stark-tinyram
FFTLIB_DIR := $(WD)/algebra/FFT

.PHONY: \
libstark libstark-clean \
stark-tinyram stark-tinyram-clean \
fft fft-clean \
algebralib algebralib-clean \
gadgetlib gadgetlib-clean \
clean

default: stark-tinyram

libstark:
$(MAKE) -C $(LIBSTARK_DIR) \
BLDDIR=$(BLDDIR)/libstark \
FFTINC=$(FFTLIB_DIR)/src \
ALGEBRAINC=$(ALGEBRALIB_DIR)/headers

libstark-clean:
$(MAKE) clean -C $(LIBSTARK_DIR) BLDDIR=$(BLDDIR)/libstark

stark-tinyram: gadgetlib fft algebralib libstark
$(MAKE) -C $(TINYRAM_DIR) \
BLDDIR=$(BLDDIR)/stark-tinyram \
EXEDIR=$(EXE_DIR) \
FFTINC=$(FFTLIB_DIR)/src \
FFTLIBLNKDIR=$(BLDDIR)/fft \
ALGEBRAINC=$(ALGEBRALIB_DIR)/headers \
ALGEBRALNKDIR=$(BLDDIR)/algebralib \
LIBSTARKINC=$(LIBSTARK_DIR)/src \
LIBSTARKLINKDIR=$(BLDDIR)/libstark \
GADGET3INC=$(GADGETLIB3_DIR)/../. \
GADGET3LNKDIR=$(BLDDIR)/gadgetlib

stark-tinyram-clean:
$(MAKE) clean -C $(TINYRAM_DIR) \
BLDDIR=$(BLDDIR)/stark-tinyram \
EXEDIR=$(EXE_DIR)

fft:
$(MAKE) -C $(FFTLIB_DIR) BLDDIR=$(BLDDIR)/fft

fft-clean:
$(MAKE) clean -C $(FFTLIB_DIR) BLDDIR=$(BLDDIR)/fft

algebralib:
$(MAKE) -C $(ALGEBRALIB_DIR) \
BLDDIR=$(BLDDIR)/algebralib FFTINC=$(FFTLIB_DIR)/src

algebralib-clean:
$(MAKE) clean -C $(ALGEBRALIB_DIR) BLDDIR=$(BLDDIR)/algebralib

gadgetlib:
$(MAKE) -C $(GADGETLIB3_DIR) \
GADGETINC=$(GADGETLIB3_DIR)/. \
ALGEBRAINC=$(ALGEBRALIB_DIR)/headers \
ALGEBRALIBLINKDIR=$(BLDDIR)/algebralib \
FFTLIBLNKDIR=$(BLDDIR)/fft \
FFTINC=$(FFTLIB_DIR) FFTLIBLNKDIR=$(BLDDIR)/fft \
BLDDIR=$(BLDDIR)/gadgetlib

gadgetlib-clean:
$(MAKE) -C $(GADGETLIB3_DIR) BLDDIR=$(BLDDIR)/gadgetlib clean

clean: gadgetlib-clean stark-tinyram-clean libstark-clean fft-clean algebralib-clean
rm -r $(BLDDIR)
29 changes: 29 additions & 0 deletions algebra/FFT/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CC=g++
CPPFLAGS=-std=c++14
CFLAGS=-O3 -g -Wall -fmessage-length=0 -fopenmp -mavx -maes -mtune=native

WHICH := $(shell which which)
MKDIR := $(shell $(WHICH) mkdir)
DIRNAME := $(shell $(WHICH) dirname)

CFLAGS+=-mpclmul
CPPFLAGS+=-mpclmul
INCFLAGS=-Isrc
TARGET=$(BLDDIR)/libFFT.a

SRCS:= $(shell ls src/*.cpp)
OBJS=$(addprefix $(BLDDIR)/, $(SRCS:.cpp=.o))

$(BLDDIR)/%.o: %.cpp
# @echo 'Building file: $@ ($<)'
@$(MKDIR) -p $(shell $(DIRNAME) $@)
$(CC) $(CFLAGS) $(CPPFLAGS) $(INCFLAGS) -c -o "$@" "$<"

all: $(TARGET)

clean:
$(RM) -f $(TARGET) $(OBJS) $(DEPS)

$(TARGET): $(OBJS)
# @echo 'Building target: $@'
ar -r "$@" $(OBJS) $(LIBS)
81 changes: 81 additions & 0 deletions algebra/FFT/src/Basis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Basis.cpp
*
* Created on: Jul 2, 2014
* Author: matan
*/
#include <iostream>
#include <cstring>
#include "Basis.h"
#include <cstdlib>
namespace FFF {

void Basis::getElement(Basis& b, Element& e,idx_t idx){
b.getShift(e);
for(unsigned int i = 0 ; i < b.size ; ++i){
if(idx & 1)
Element::c_add(e,b.b[i],e);
idx>>=1;
}
}
Basis::Basis() :
b((Element*)malloc(sizeof(Element))), shift() , size(1){};
Basis::Basis(Basis& that) :
shift(that.shift), size(that.size)
{
b = ((Element*)malloc(sizeof(Element)*that.size));
memcpy(this->b, that.b, sizeof(Element)*that.size);
}
Basis::Basis(Element* e, len_t l, Element& s):
b((Element*)malloc(sizeof(Element)*l)), shift(s),size(l)
{
memcpy(b,e,sizeof(Element)*l);
}
//Ariel:buggy method, but not actually used - so commented out
//void Basis::setBasis(Element* e, len_t l, Element& s){
// this->~Basis();
// this->b=(Element*)malloc(sizeof(Element)*l);
// this->shift = s;
// this-> size = l;
//}
void Basis::operator=(const Basis& b){
this->~Basis();
this->b= (Element*)malloc(sizeof(Element)*b.size);
memcpy(this->b,b.b,sizeof(Element)*b.size);
size = b.size;
shift=b.shift;
}
unsigned int Basis::getSize() const {
return this->size;
}
const Element& Basis::getShift() const{
return this->shift;
}
void Basis::getBasis(Element* D) const
{
memcpy(D,this->b,sizeof(Element)*this->size);
}
void Basis::getShift(Element& e) const
{
Element::assign(e,this->shift);
}

Element* Basis::getBasis() const{
return this->b;
}
void Basis::printBasis() const{
std::cout << "Elements:" << std::endl;
for(unsigned int i = 0 ; i < this->size ; ++i){
Element::printElement(this->b[i]);
std::cout << std::endl;
}
std:: cout << "Shift:" << std::endl;
Element::printElement(this->shift);
std::cout << std::endl << std::endl;

}
Basis::~Basis() {
free(b);
}

} /* namespace FFF */
40 changes: 40 additions & 0 deletions algebra/FFT/src/Basis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Basis.h
*
* Created on: Jul 2, 2014
* Author: matan
*/

#ifndef BASIS_H_
#define BASIS_H_
#include "Definitions.h"
#include "Element.h"
namespace FFF {

class Basis {
Element* b;
Element shift;
len_t size;
public:
Basis();
Basis(Basis& b);
void operator=(const Basis& b);
Basis(Element* e, len_t l,Element& s);
void setBasis(Element* e, len_t l, Element& s);
static void getElement(Basis& b, Element& e,idx_t idx);
unsigned int getSize() const ;

/*
* Copies into D the elements of the basis.
* D has to be preallocated.
*/
void getBasis(Element* D)const;
Element* getBasis() const;
void getShift(Element& e) const;
const Element& getShift() const;
void printBasis() const;
~Basis();
};

} /* namespace FFF */
#endif /* BASIS_H_ */
Loading

0 comments on commit 47225ef

Please sign in to comment.