Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
pmineiro committed Jul 6, 2011
0 parents commit 5685389
Show file tree
Hide file tree
Showing 34 changed files with 3,283 additions and 0 deletions.
1 change: 1 addition & 0 deletions fastapprox/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Paul Mineiro <[email protected]>
2 changes: 2 additions & 0 deletions fastapprox/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Version 0.0.0
* Fast logarithm, exponential, power, and inverse root.
1 change: 1 addition & 0 deletions fastapprox/Makefile.am.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# put whatever (auto)make commands here, they will be included from Makefile.am
Empty file added fastapprox/NEWS
Empty file.
1 change: 1 addition & 0 deletions fastapprox/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fast approximate versions of certain functions that arise in machine learning.
17 changes: 17 additions & 0 deletions fastapprox/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /bin/sh

if test -d fw/bin
then
PATH="`pwd`/fw/bin:$PATH"
export PATH
fi

fwb=`which fw-bootstrap`

if test -z "$fwb"
then
echo "bootstrap: fatal: fw-bootstrap not installed or not in PATH" 1>&2
exit 1
fi

"$fwb" --fw_version "0.3.3" --name fastapprox --template Cxx --revision svn --svn_project_path https://fastapprox.googlecode.com/svn/trunk/fastapprox --svn_tag_root https://fastapprox.googlecode.com/svn/tags/fastapprox "$@"
4 changes: 4 additions & 0 deletions fastapprox/configure.ac.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dnl -- include additional autoconf commands here
dnl -- do not include AC_OUTPUT, this is called for you

AC_CHECK_HEADERS([emmintrin.h])
1 change: 1 addition & 0 deletions fastapprox/fw-pkgin/Makefile.am.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# put whatever (auto)make commands here, they will be included from Makefile.am
71 changes: 71 additions & 0 deletions fastapprox/fw-pkgin/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# The FW_PACKAGE_MAINTAINER field is populated with the environment
# variable FW_PACKAGE_DEFAULT_MAINTAINER if non-empty at init time

FW_PACKAGE_NAME="fastapprox"
FW_PACKAGE_VERSION="0.0.0"
FW_PACKAGE_MAINTAINER="Paul Mineiro <[email protected]>"
FW_PACKAGE_SHORT_DESCRIPTION="Fast approximate function library."
FW_PACKAGE_DESCRIPTION=`cat README`
FW_PACKAGE_ARCHITECTURE_DEPENDENT="0"

# Dependency information. The native syntax corresponds to Debian,
# http://www.debian.org/doc/debian-policy/ch-relationships.html
# Section 7.1 "Syntax of Relationship Fields"
#
# For other packaging systems, the syntax is translated for you.

FW_PACKAGE_DEPENDS=""
FW_PACKAGE_CONFLICTS=""
FW_PACKAGE_PROVIDES=""
FW_PACKAGE_REPLACES=""
FW_PACKAGE_SUGGESTS=""

FW_PACKAGE_BUILD_DEPENDS="libboost1.40-dev"
FW_PACKAGE_BUILD_CONFLICTS=""

# dupload is used for submitting debian packages to a package archive
# The FW_DUPLOAD_ARGS field is populated with the environment variable
# FW_DEFAULT_DUPLOAD_ARGS if non-empty at init time

FW_DUPLOAD_ARGS=${FW_DUPLOAD_ARGS-"-t dukeslucid"}

# scp+createrepo is used for submitting rpm packages to a package archive
# The FW_RPM_REPO_USER, FW_RPM_REPO_HOST, FW_RPM_REPO_BASEDIR,
# and FW_RPM_POSTCREATEREPO_COMMANDS variables are populated with
# FW_RPM_REPO_USER_DEFAULT, FW_RPM_REPO_HOST_DEFAULT,
# FW_RPM_REPO_BASEDIR_DEFAULT, and FW_RPM_POSTCREATEREPO_COMMANDS_DEFAULT
# respectively if non-empty at init time

FW_RPM_REPO_USER=${FW_RPM_REPO_USER-"`whoami`"}
FW_RPM_REPO_HOST=${FW_RPM_REPO_HOST-"ub32srvvmw"}
FW_RPM_REPO_BASEDIR=${FW_RPM_REPO_BASEDIR-"/var/yum"}
FW_RPM_CREATEREPO_ARGS=${FW_RPM_CREATEREPO_ARGS-"-q --database"}

# this variable controls whether createrepo is run incrementally (--update).
# possible settings are yes (always do it), no (never do it), and
# auto (do it if the repository has been previously initialized)
FW_RPM_CREATEREPO_INCREMENTAL=${FW_RPM_CREATEREPO_INCREMENTAL-"auto"}

# these commands will be run after a successful createrepo run
FW_RPM_POSTCREATEREPO_COMMANDS=${FW_RPM_POSTCREATEREPO_COMMANDS-"{ cd /var; rsync -a yum /var/package/dukes; }"}
# here's a suggestion:
# FW_RPM_POSTCREATEREPO_COMMANDS="gpg --detach-sign --armor repodata/repomd.xml"

# set to the directory in which version-named tags will be created
FW_SUBVERSION_TAG_ROOT="https://fastapprox.googlecode.com/svn/tags/fastapprox"

# uncomment and set to specify additional pkg-config packages on the Requires:
# line of the generated .pc file
# FW_PKGCONFIG_REQUIRES_EXTRA=""

# uncomment and set to specify additional content for the Libs:
# line of the generated .pc file
# FW_PKGCONFIG_LIBS_EXTRA=""

# uncomment and set to specify additional content for the Cflags:
# line of the generated .pc file
# FW_PKGCONFIG_CFLAGS_EXTRA=""

# uncomment and set to add arbitrary additional content to the
# generated .pc file
# FW_PKGCONFIG_EXTRA=""
21 changes: 21 additions & 0 deletions fastapprox/fw-pkgin/post-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /bin/sh

set -e

#---------------------------------------------------------------------
# post-install
#
# Executed after the package is installed.
#
# http://code.google.com/p/fwtemplates/wiki/PackageHooks
#---------------------------------------------------------------------

case "$1" in
configure)
# most recently configured version is $2 (possibly empty string)
;;
*)
;;
esac

exit 0
28 changes: 28 additions & 0 deletions fastapprox/fw-pkgin/post-remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/sh

set -e

#---------------------------------------------------------------------
# post-remove
#
# Executed after the package is removed.
#
# http://code.google.com/p/fwtemplates/wiki/PackageHooks
#---------------------------------------------------------------------

case "$1" in
upgrade)
# defer to newer package's script
exit 1
;;
failed-upgrade)
# actually handle the upgrade here
# old-version is $2
;;
remove)
;;
*)
;;
esac

exit 0
23 changes: 23 additions & 0 deletions fastapprox/fw-pkgin/pre-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /bin/sh

set -e

#---------------------------------------------------------------------
# pre-install
#
# Executed before the package is installed.
#
# http://code.google.com/p/fwtemplates/wiki/PackageHooks
#---------------------------------------------------------------------

case "$1" in
install)
;;
upgrade)
# old version is $2
;;
*)
;;
esac

exit 0
28 changes: 28 additions & 0 deletions fastapprox/fw-pkgin/pre-remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/sh

set -e

#---------------------------------------------------------------------
# pre-remove
#
# Executed before the package is removed.
#
# http://code.google.com/p/fwtemplates/wiki/PackageHooks
#---------------------------------------------------------------------

case "$1" in
upgrade)
# defer to newer package's script
exit 1
;;
failed-upgrade)
# actually handle the upgrade here
# old-version is $2
;;
remove)
;;
*)
;;
esac

exit 0
10 changes: 10 additions & 0 deletions fastapprox/fw-pkgin/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/sh

#---------------------------------------------------------------------
# start
#
# Executed when the package (service) is started up.
# Not supported by all package formats.
#---------------------------------------------------------------------

exit 0
10 changes: 10 additions & 0 deletions fastapprox/fw-pkgin/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/sh

#---------------------------------------------------------------------
# start
#
# Executed when the package (service) is shut down.
# Not supported by all package formats.
#---------------------------------------------------------------------

exit 0
18 changes: 18 additions & 0 deletions fastapprox/src/Makefile.am.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# put whatever (auto)make commands here, they will be included from Makefile.am
#

fastonebigheader.h: $(filter-out config.h fastonebigheader.h, $(wildcard *.h))
cat \
sse.h \
fastexp.h \
fastlog.h \
fasterf.h \
fastgamma.h \
fasthyperbolic.h \
fastsigmoid.h \
fasttrig.h \
| grep -v '#include "' > "$@"

myinclude_HEADERS += \
fastonebigheader.h \
$(filter-out config.h fastonebigheader.h, $(wildcard *.h))
139 changes: 139 additions & 0 deletions fastapprox/src/fasterf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*=====================================================================*
* Copyright (C) 2011 Paul Mineiro *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with *
* or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the *
* above copyright notice, this list of conditions and *
* the following disclaimer. *
* *
* * Redistributions in binary form must reproduce the *
* above copyright notice, this list of conditions and *
* the following disclaimer in the documentation and/or *
* other materials provided with the distribution. *
* *
* * Neither the name of Paul Mineiro nor the names *
* of other contributors may be used to endorse or promote *
* products derived from this software without specific *
* prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE *
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
* Contact: Paul Mineiro <[email protected]> *
*=====================================================================*/

#ifndef __FAST_ERF_H_
#define __FAST_ERF_H_

#include <math.h>
#include <stdint.h>
#include "sse.h"
#include "fastexp.h"

// fasterfc: not actually faster on newer machines!
// ... although vectorized version is interesting
// and fastererfc is very fast

static inline float
fasterfc (float x)
{
static const float k = 3.3509633149424609f;
static const float a = 0.0846486355377475f;
static const float b = 1.6732800045663587f;
static const float c = 5.604430819154318f;

float bx = b * x;
union { float f; uint32_t i; } vc = { c * x };
float bxsq = bx * bx;
float bxquad = bxsq * bxsq;
float bxfive = bxquad * bx;

vc.i |= 0x80000000;

return 2.0f / (1.0f + fastpow2 (k * x)) - a * (bxfive - x) * fasterpow2 (vc.f);
}

static inline float
fastererfc (float x)
{
static const float k = 3.3509633149424609f;

return 2.0f / (1.0f + fasterpow2 (k * x));
}

// fasterf: not actually faster on newer machines!
// ... although vectorized version is interesting
// and fastererf is very fast

static inline float
fasterf (float x)
{
return 1.0f - fasterfc (x);
}

static inline float
fastererf (float x)
{
return 1.0f - fastererfc (x);
}

#ifdef __SSE2__

static inline v4sf
vfasterfc (v4sf x)
{
static const v4sf k = v4sfl (3.3509633149424609f);
static const v4sf a = v4sfl (0.0846486355377475f);
static const v4sf b = v4sfl (1.6732800045663587f);
static const v4sf c = v4sfl (5.604430819154318f);

union { v4sf f; v4si i; } vc = { c * x };
vc.i |= v4sil (0x80000000);

v4sf bx = b * x;
v4sf bxsq = bx * bx;
v4sf bxquad = bxsq * bxsq;
v4sf bxfive = bxquad * bx;

return v4sfl (2.0f) / (v4sfl (1.0f) + vfastpow2 (k * x)) - a * (bxfive - x) * vfasterpow2 (vc.f);
}

static inline v4sf
vfastererfc (const v4sf x)
{
static const v4sf k = v4sfl (3.3509633149424609f);

return v4sfl (2.0f) / (v4sfl (1.0f) + vfasterpow2 (k * x));
}

static inline v4sf
vfasterf (v4sf x)
{
return v4sfl (1.0f) - vfasterfc (x);
}

static inline v4sf
vfastererf (const v4sf x)
{
return v4sfl (1.0f) - vfastererfc (x);
}

#endif //__SSE2__

#endif // __FAST_ERF_H_
Loading

0 comments on commit 5685389

Please sign in to comment.