GithubHelp home page GithubHelp logo

remyoudompheng / bigfft Goto Github PK

View Code? Open in Web Editor NEW
70.0 5.0 17.0 64 KB

Big integer multiplication library for Go using Fast Fourier transform

License: BSD 3-Clause "New" or "Revised" License

Go 100.00%

bigfft's Introduction

This library is a toy proof-of-concept implementation of the
well-known Schonhage-Strassen method for multiplying integers.
It is not expected to have a real life usecase outside number
theory computations, nor is it expected to be used in any production
system.

If you are using it in your project, you may want to carefully
examine the actual requirement or problem you are trying to solve.

# Comparison with the standard library and GMP

Benchmarking math/big vs. bigfft

Number size    old ns/op    new ns/op    delta
  1kb               1599         1640   +2.56%
 10kb              61533        62170   +1.04%
 50kb             833693       831051   -0.32%
100kb            2567995      2693864   +4.90%
  1Mb          105237800     28446400  -72.97%
  5Mb         1272947000    168554600  -86.76%
 10Mb         3834354000    405120200  -89.43%
 20Mb        11514488000    845081600  -92.66%
 50Mb        49199945000   2893950000  -94.12%
100Mb       147599836000   5921594000  -95.99%

Benchmarking GMP vs bigfft

Number size   GMP ns/op     Go ns/op    delta
  1kb                536         1500  +179.85%
 10kb              26669        50777  +90.40%
 50kb             252270       658534  +161.04%
100kb             686813      2127534  +209.77%
  1Mb           12100000     22391830  +85.06%
  5Mb          111731843    133550600  +19.53%
 10Mb          212314000    318595800  +50.06%
 20Mb          490196000    671512800  +36.99%
 50Mb         1280000000   2451476000  +91.52%
100Mb         2673000000   5228991000  +95.62%

Benchmarks were run on a Core 2 Quad Q8200 (2.33GHz).
FFT is enabled when input numbers are over 200kbits.

Scanning large decimal number from strings.
(math/big [n^2 complexity] vs bigfft [n^1.6 complexity], Core i5-4590)

Digits    old ns/op      new ns/op      delta
1e3            9995          10876     +8.81%
1e4          175356         243806    +39.03%
1e5         9427422        6780545    -28.08%
1e6      1776707489      144867502    -91.85%
2e6      6865499995      346540778    -94.95%
5e6     42641034189     1069878799    -97.49%
10e6   151975273589     2693328580    -98.23%

bigfft's People

Contributors

fumiama avatar r-value avatar remyoudompheng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bigfft's Issues

Div

Is there any way to speed up number division?

ARM support, for EdgeX Foundry and gollvm

I am trying to use gollvm for building device-virtual-go - and it would require cross-compiling capabilities, if building under x86_64 (Ubuntu 20, in my case).

Looks like 3rd party assembler tool has to be called:

~/device-virtual-go$ make
CGO_ENABLED=0 GO111MODULE=on go build -ldflags "-X github.com/edgexfoundry/device-virtual-go.Version=0.0.0" -o cmd/device-virtual ./cmd
go build: when using gccgo toolchain, please pass linker flags using -gccgoflags, not -ldflags

github.com/remyoudompheng/bigfft

vendor/github.com/remyoudompheng/bigfft/arith_amd64.s: Assembler messages:
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:6: Error: no such instruction: text ·addVV(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:7: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:11: Error: no such instruction: text ·subVV(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:12: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:15: Error: no such instruction: text ·addVW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:16: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:20: Error: no such instruction: text ·subVW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:21: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:24: Error: no such instruction: text ·shlVU(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:25: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:28: Error: no such instruction: text ·shrVU(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:29: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:32: Error: no such instruction: text ·mulAddVWW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:33: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:36: Error: no such instruction: text ·addMulVVW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:37: Error: junk (SB)' after expression
make: *** [Makefile:20: cmd/device-virtual] Error 2

Somewhat more verbosity here:

$ make GOFLAGS=' -i -v -x '
CGO_ENABLED=0 GO111MODULE=on go build -i -v -x -o cmd/device-virtual ./cmd
WORK=/tmp/go-build256936414
github.com/remyoudompheng/bigfft
mkdir -p $WORK/b131/
cd $WORK
/usr/local/bin/llvm-goc -fgo-importcfg=/dev/null -c -x c - -o /dev/null || true
cd /home/oceanfish81/device-virtual-go/vendor/github.com/remyoudompheng/bigfft
/usr/local/bin/llvm-goc -c -O2 -g -m64 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -fgo-pkgpath=github.com/remyoudompheng/bigfft -o $WORK/b131/go.o -I $WORK/b131/importcfgroot ./arith_decl.go ./fermat.go ./fft.go ./scan.go
/usr/local/bin/llvm-goc -xassembler-with-cpp -I $WORK/b131/ -c -o $WORK/b131/arith_amd64.o -D GOOS_linux -D GOARCH_amd64 -D GOPKGPATH=github.x2ecom..z2fremyoudompheng..z2fbigfft -m64 ./arith_amd64.s

github.com/remyoudompheng/bigfft

vendor/github.com/remyoudompheng/bigfft/arith_amd64.s: Assembler messages:
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:6: Error: no such instruction: text ·addVV(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:7: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:11: Error: no such instruction: text ·subVV(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:12: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:15: Error: no such instruction: text ·addVW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:16: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:20: Error: no such instruction: text ·subVW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:21: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:24: Error: no such instruction: text ·shlVU(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:25: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:28: Error: no such instruction: text ·shrVU(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:29: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:32: Error: no such instruction: text ·mulAddVWW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:33: Error: junk (SB)' after expression
vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:36: Error: no such instruction: text ·addMulVVW(SB),NOSPLIT,$0' vendor/github.com/remyoudompheng/bigfft/arith_amd64.s:37: Error: junk (SB)' after expression
make: *** [Makefile:20: cmd/device-virtual] Error 2

Build under such env.:

$ go env && go version
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/oceanfish81/.cache/go-build"
GOENV="/home/oceanfish81/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/oceanfish81/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/oceanfish81/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/tools"
GCCGO="/usr/local/bin/llvm-goc"
AR="ar"
CC="/usr/bin/clang"
CXX="/usr/bin/clang++"
CGO_ENABLED="1"
GOMOD="/home/oceanfish81/device-virtual-go/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build099959315=/tmp/go-build -gno-record-gcc-switches -funwind-tables"
go version go1.15rc2 gollvm LLVM 12.0.0git linux/amd64

@erifan, any suggestions/propositions?

@jpwhitemn, is this project to be built under ARM port of Linux? Or any brave people tried to cross-compile?

CC @remyoudompheng
BCC @erifan @thanm @cherrymui

Ivan

ppc asm does not compile

# github.com/remyoudompheng/bigfft
./arith_ppc64x.s:7: unrecognized instruction "BR"
./arith_ppc64x.s:11: unrecognized instruction "BR"
./arith_ppc64x.s:15: unrecognized instruction "BR"
./arith_ppc64x.s:19: unrecognized instruction "BR"
./arith_ppc64x.s:23: unrecognized instruction "BR"
./arith_ppc64x.s:27: unrecognized instruction "BR"
./arith_ppc64x.s:31: unrecognized instruction "BR"
./arith_ppc64x.s:35: unrecognized instruction "BR"
asm: assembly of ./arith_ppc64x.s failed

TestFermatMul fails on 32bit architectures

I get this test output on 32bit x86 when running the code from latest master (commit 3d026bc):

go test -compiler gc -ldflags '' github.com/remyoudompheng/bigfft
--- FAIL: TestFermatMul (0.00s)
	fermat_test.go:23: mulTests[1]: 0 != 1
	fermat_test.go:23: mulTests[4]: fff40002ffffffffffffffff00060001fffffffe00020001fffffffffffe000bfffbffff000000000001fffbfffdfffffffffffffffc000000000002fffa00030001fffffffffff900040001fffffffffffe000400000000fffe0003fffffffd000000000005fffbfffe000000000003fffbfffa00000000fffdfffd0001fffffffffffa000600000001fffffffc000d != fffe00000003fffc0000000000000000fff40003000000000000000000060001fffffffd0001fffffffffffffffe000dfffbfffffffffffffffffffafffe0000000200000000000000000002fff60002fffffffffffffffa00060001ffffffff0000000000000000fffc0007fffe0000000000000007fff8fffdfffffffffffffffffffa00000004fffa0000fffffffffffffff600080000000000000000000a
FAIL
FAIL	github.com/remyoudompheng/bigfft	24.688s

The same error also occurs on 32bit arm.

How to fix "missing function body" build for mips, thank you !

macOS 10.14.4 (18E226)

go version go1.11.2 darwin/amd64

go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hongjinlin/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hongjinlin/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.2/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1q/3d6q6x2s6057s6fgwdxr7ffw0000gn/T/go-build945892395=/tmp/go-build -gno-record-gcc-switches -fno-common"

build commond:
env GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -ldflags="-s -w" main.go

errors:

github.com/remyoudompheng/bigfft

../github.com/remyoudompheng/bigfft/arith_decl.go:10:6: missing function body
../github.com/remyoudompheng/bigfft/arith_decl.go:11:6: missing function body
../github.com/remyoudompheng/bigfft/arith_decl.go:12:6: missing function body
../github.com/remyoudompheng/bigfft/arith_decl.go:13:6: missing function body
../github.com/remyoudompheng/bigfft/arith_decl.go:14:6: missing function body
../github.com/remyoudompheng/bigfft/arith_decl.go:15:6: missing function body
../github.com/remyoudompheng/bigfft/arith_decl.go:16:6: missing function body

Mul: incorrect result

@remyoudompheng

Post PR issue for #1.

We had a blackout, after power was restored the browser remembered the issue content but not the title. I did not notice that and Github rightfully disables the "Submit" button when the issue has no title.

Can't run demo file in wm

I can't run the demo file in wm module because there were too many errors, stopping now. How do I increase or eliminate this error limit?

# github.com/remyoudompheng/bigfft
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:10:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:11:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:12:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:13:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:14:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:15:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:16:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:18:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:19:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:20:6: missing function body
../go/pkg/mod/github.com/remyoudompheng/[email protected]/arith_decl.go:10:6: too many errors

RISC-V support

Go 1.15 will have a more stable RISC-V support. Consider update the package for compatibility.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.