• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    C++
  • Created over 14 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

fast log and exp functions for x86/x64 SSE

fast approximate function of exponential function exp and log

How to use

include fmath.hpp and use fmath::log, fmath::exp, fmath::expd.

fmath::PowGenerator is a class to generate a function to compute pow(x, y) of x >= 0 for a given fixed y > 0.

eg. fmath::PowGenerator f(1.234); f.get(x) returns pow(x, 1.234);

Prototype of function

  • float fmath::exp(float);
  • float fmath::log(float);
  • double fmath::logd(double);
  • __m128 fmath::exp_ps(__m128);
  • __m128 fmath::log_ps(__m128);
  • void fmath::expv_d(double *p, size_t n); // for double p[n];

for AVX-512

fmath.h provides the following functions:

void fmath_expf_avx512(float *dst, const float *src, size_t n);
void fmath_logf_avx512(float *dst, const float *src, size_t n);
void fmath::expf_v(float *dst, const float *src, size_t n);
void fmath::logf_v(float *dst, const float *src, size_t n);

Experimental

If you install xbyak and define FMATH_USE_XBYAK before including fmath.hpp, then fmath::exp() and fmath::exp_ps() will be about 10~20 % faster. Xbyak version uses SSE4.1 if available.

AVX version of fmath::exp is experimental

Remark

gcc puts warnings such as "dereferencing type-punned pointer will break strict-aliasing rules." It is no problem. Please change #if 1 in fmath.hpp:423 if you worry about it. But it causes a little slower.

-ffast-math option of gcc may generate bad code for fmath::expd.

License

History

  • 2022/May/30 log for AVX-512 got 1.5 times faster
  • 2020/Jul/10 add expf_v and logf_v for AVX-512
  • 2012/Oct/30 fix fmath::expd for small value
  • 2011/Aug/26 add fmath::expd_v
  • 2011/Mar/25 exp supports AVX
  • 2011/Mar/25 exp, exp_ps support avx
  • 2010/Feb/16 add fmath::exp_ps, log_ps and optimize functions
  • 2010/Jan/10 add fmath::PowGenerator
  • 2009/Dec/28 add fmath::log()
  • 2009/Dec/09 support cygwin
  • 2009/Dec/08 first version

Author

MITSUNARI Shigeo([email protected]) http://herumi.in.coocan.jp/

Benchmark

compiler

  • Visual Studio 2010RC
  • icc 11.1
  • gcc 4.3.2 on cygwin
  • gcc 4.4.1 on 64bit Linux

option

  • cl(icl):

/Ox /Ob2 /GS- /Zi /D_SECURE_SCL=0 /MD /Oy /arch:SSE2 /fp:fast /DNOMINMAX

  • gcc:

-O3 -fomit-frame-pointer -DNDEBUG -fno-operator-names -msse2 -mfpmath=sse -march=native

see fastexp.cpp

More Repositories

1

xbyak

a JIT assembler for x86(IA-32)/x64(AMD64, x86-64) MMX/SSE/SSE2/SSE3/SSSE3/SSE4/FPU/AVX/AVX2/AVX-512 by C++ header
C++
1,949
star
2

mcl

a portable and fast pairing-based cryptography library
C++
431
star
3

prml

TeX
367
star
4

bls

C++
284
star
5

msoffice

C++
228
star
6

ate-pairing

C++
132
star
7

ango-src

TeX
87
star
8

cybozulib

a tiny library for C++
C++
63
star
9

she-wasm

Two-level homomorphic encryption for Node.js by WebAssembly
JavaScript
62
star
10

bls-eth-go-binary

Go
61
star
11

mcl-wasm

TypeScript
58
star
12

ango

51
star
13

misc

C++
51
star
14

bls-wasm

BLS signature for Node.js by WebAssembly
JavaScript
46
star
15

emcjp

C++
44
star
16

x86opti

37
star
17

blog

C++
36
star
18

bls-eth-wasm

JavaScript
30
star
19

opti

C++
29
star
20

xbyak_riscv

C++
26
star
21

bls-go-binary

Go
21
star
22

bls-eth-rust

Rust
20
star
23

simdgen

A library to generate a SIMD code for AVX-512/SVE from a given function string.
C++
19
star
24

ecdsa-motoko

Motoko
14
star
25

mie_string

C++
13
star
26

mie

C++
11
star
27

s_xbyak

ASM generation tool for GAS/NASM/MASM with Xbyak-like syntax in Python
Python
11
star
28

ecdsa-wasm

ECDSA/secp256k1 + SHA-256
JavaScript
9
star
29

fmindex

forked fmindex-plus-plus
C++
7
star
30

anninbon

HTML
7
star
31

ahe-demo

additive homomorphic encryption demo to compute an edge of an image
C++
5
star
32

add_he

additive homomorphic encryption demo using lifted ElGamal encryption
C++
5
star
33

test-picotls

C
4
star
34

mcl-rust

Rust
4
star
35

edit-dist

C++
4
star
36

gogo

obsolete
4
star
37

pairing-doc

TeX
4
star
38

faster-csidh

The original is https://gitlab.cs.hs-rm.de/pqcrypto/faster-csidh
C
4
star
39

walb-tools

C
3
star
40

mcl-android

sample of mcl on Android
CMake
3
star
41

l2-to-l1

C++
3
star
42

obsolete-bls-all-in-one

Assembly
2
star
43

gmp-android

C++
2
star
44

mcl-ff

arithmetic operations of a finite field
Python
2
star
45

ot-by-l2he

Oblivious Transfer demo by L2-HE
C++
2
star
46

she-rust

Rust
2
star
47

test-harmony-bls

test of harmony-bls for jaa
C++
2
star
48

cybozulib_ext

a collection for cybozulib
C
2
star
49

debug_mcl

debug mcl for travis
Assembly
1
star
50

mcladt

Java
1
star
51

test-bls-go-binary

Go
1
star
52

sample-wasm-cpp

JavaScript
1
star