Skip to content

Commit

Permalink
github actions pipeline to build libgoldilocks (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaZezulinsky authored Sep 30, 2021
1 parent b742d93 commit a352180
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 27 deletions.
83 changes: 67 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,93 @@
name: libgoldilocks pipeline
on: [push, pull_request]
on: push
jobs:
build:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest, raspbian-private, macos-private]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build Linux
if: ${{ matrix.platform == 'ubuntu-latest' || matrix.platform == 'raspbian-private'}}
run: |
mkdir -p src/.libs
docker build . -t libgoldilocks:${{matrix.platform}}
docker create -it --name dummy libgoldilocks:${{matrix.platform}} bash
docker cp dummy:/usr/local/bin/libgoldilocks.a src/.libs/libgoldilocks.a
docker rm -f dummy
- name: Build Mac
if: ${{ matrix.platform == 'macos-private' }}
run: |
autoreconf --install && ./configure && make all
- name: Setup Win
if: ${{ matrix.platform == 'windows-latest' }}
uses: msys2/setup-msys2@v2
with:
msystem: mingw64
update: true
install: >
base-devel
mingw-w64-x86_64-toolchain
- name: Build Windows
if: ${{ matrix.platform == 'windows-latest' }}
shell: msys2 {0}
run: |
autoreconf --install && ./configure && make all
- name: Upload
uses: actions/upload-artifact@v2
with:
name: libgoldilocks-${{matrix.platform}}
path: src/.libs/libgoldilocks.a
release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Build
- name: Download Linux lib
uses: actions/download-artifact@v2
with:
name: libgoldilocks-ubuntu-latest
path: linux-x86_64
- name: Download Raspbian lib
uses: actions/download-artifact@v2
with:
name: libgoldilocks-raspbian-private
path: linux-arm64
- name: Download Mac lib
uses: actions/download-artifact@v2
with:
name: libgoldilocks-macos-private
path: darwin-x86_64
- name: Download Win lib
uses: actions/download-artifact@v2
with:
name: libgoldilocks-windows-latest
path: windows-x86_64
- name: Create zip
run: |
autoreconf --install
./configure
make lib
- name: Test
run: make test
- name: Zip
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: zip -r -j libgoldilocks build/lib
zip -r libgoldilocks *
- name: Bump version
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
id: version_bump
uses: anothrNick/github-tag-action@1.13.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BUMP: "patch"
RELEASE_BRANCHES: "master"
- name: Create Release
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version_bump.outputs.tag }}
release_name: Release libgoldilocks ${{ steps.version_bump.outputs.tag }}
release_name: libgoldilocks ${{ steps.version_bump.outputs.tag }}
draft: false
prerelease: false
- name: Upload Release Asset
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
- name: Upload release assets
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM alpine:3
FROM alpine:3 as builder
WORKDIR libgoldilocks
COPY . libgoldilocks
RUN apk add automake autoconf libtool make gcc g++
RUN cd libgoldilocks && autoreconf --install && ./configure && make lib
RUN cd libgoldilocks && autoreconf --install && ./configure && make all

FROM alpine:3
COPY --from=builder /libgoldilocks/libgoldilocks/src/.libs/libgoldilocks.a /usr/local/bin/
CMD ["tail", "-f"]
12 changes: 6 additions & 6 deletions src/arch_x86_64/f_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ void gf_mul (gf_s *__restrict__ cs, const gf as, const gf bs) {

/* For some reason clang doesn't vectorize this without prompting? */
unsigned int i;
for (i=0; i<sizeof(aa)/sizeof(uint64xn_t); i++) {
((uint64xn_t*)aa)[i] = ((const uint64xn_t*)a)[i] + ((const uint64xn_t*)(&a[4]))[i];
((uint64xn_t*)bb)[i] = ((const uint64xn_t*)b)[i] + ((const uint64xn_t*)(&b[4]))[i];
((uint64xn_t*)bbb)[i] = ((const uint64xn_t*)bb)[i] + ((const uint64xn_t*)(&b[4]))[i];
for (i=0; i<sizeof(aa)/sizeof(uint64_t); i++) {
((uint64_t*)aa)[i] = ((const uint64_t*)a)[i] + ((const uint64_t*)(&a[4]))[i];
((uint64_t*)bb)[i] = ((const uint64_t*)b)[i] + ((const uint64_t*)(&b[4]))[i];
((uint64_t*)bbb)[i] = ((const uint64_t*)bb)[i] + ((const uint64_t*)(&b[4]))[i];
}
/*
for (int i=0; i<4; i++) {
Expand Down Expand Up @@ -191,8 +191,8 @@ void gf_sqr (gf_s *__restrict__ cs, const gf as) {

/* For some reason clang doesn't vectorize this without prompting? */
unsigned int i;
for (i=0; i<sizeof(aa)/sizeof(uint64xn_t); i++) {
((uint64xn_t*)aa)[i] = ((const uint64xn_t*)a)[i] + ((const uint64xn_t*)(&a[4]))[i];
for (i=0; i<sizeof(aa)/sizeof(uint64_t); i++) {
((uint64_t*)aa)[i] = ((const uint64_t*)a)[i] + ((const uint64_t*)(&a[4]))[i];
}

accum2 = widemul(&a[0],&a[3]);
Expand Down
7 changes: 7 additions & 0 deletions src/goldilocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1233,10 +1233,17 @@ extern const gf API_NS(precomputed_wnaf_as_fe)[];
static const niels_p *API_NS(wnaf_base) = (const niels_p *)API_NS(precomputed_wnaf_as_fe);
const size_t API_NS(sizeof_precomputed_wnafs) = sizeof(niels_p)<<GOLDILOCKS_WNAF_FIXED_TABLE_BITS;

#ifdef __MINGW32__
void API_NS(precompute_wnafs) (
niels_p out[1<<GOLDILOCKS_WNAF_FIXED_TABLE_BITS],
const point_p base
);
#else
void API_NS(precompute_wnafs) (
niels_p out[1<<GOLDILOCKS_WNAF_FIXED_TABLE_BITS],
const point_p base
) __attribute__ ((visibility ("hidden")));
#endif

void API_NS(precompute_wnafs) (
niels_p out[1<<GOLDILOCKS_WNAF_FIXED_TABLE_BITS],
Expand Down
17 changes: 14 additions & 3 deletions src/goldilocks_gen_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include <stdio.h>
#include <stdlib.h>

#include "field.h"
#include "include/field.h"
#include "f_field.h"
#include "goldilocks.h"
#include "api.h"
#include "public_include/goldilocks.h"
#include "include/api.h"

static const unsigned char base_point_ser_for_pregen[SER_BYTES] = {
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33
Expand Down Expand Up @@ -102,7 +102,12 @@ int main(int argc, char **argv) {
output = (const gf_s *)pre;
printf("const gf API_NS(precomputed_base_as_fe)[%d]\n",
(int)(API_NS(sizeof_precomputed_s) / sizeof(gf)));

#ifdef __MINGW32__
printf("VECTOR_ALIGNED = {\n ");
#else
printf("VECTOR_ALIGNED __attribute__((visibility(\"hidden\"))) = {\n ");
#endif

for (i=0; i < API_NS(sizeof_precomputed_s); i+=sizeof(gf)) {
if (i) printf(",\n ");
Expand All @@ -113,7 +118,13 @@ int main(int argc, char **argv) {
output = (const gf_s *)pre_wnaf;
printf("const gf API_NS(precomputed_wnaf_as_fe)[%d]\n",
(int)(API_NS(sizeof_precomputed_wnafs) / sizeof(gf)));

#ifdef __MINGW32__
printf("VECTOR_ALIGNED = {\n ");
#else
printf("VECTOR_ALIGNED __attribute__((visibility(\"hidden\"))) = {\n ");
#endif

for (i=0; i < API_NS(sizeof_precomputed_wnafs); i+=sizeof(gf)) {
if (i) printf(",\n ");
field_print(output++);
Expand Down
4 changes: 4 additions & 0 deletions src/include/word.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#ifndef __WORD_H__
#define __WORD_H__

#ifdef __MINGW32__
#define posix_memalign(p, a, s) (((*(p)) = _aligned_malloc((s), (a))), *(p) ?0 :errno)
#endif

/* for posix_memalign */
#define _XOPEN_SOURCE 600
#define __STDC_WANT_LIB_EXT1__ 1 /* for memset_s */
Expand Down

0 comments on commit a352180

Please sign in to comment.