Compare commits

..

74 Commits

Author SHA1 Message Date
cb6c436612 Add doc note to explain why we do not run make install 2023-05-15 12:11:01 +02:00
914ac88e93 Add quick test to check installed output 2023-05-15 11:55:21 +02:00
f7348b1eaa Ignore yaml test scripts 2023-05-15 11:42:43 +02:00
4c24b37006 Add dependency to build 2023-05-15 11:37:29 +02:00
7999210d0d Pass volumes to each step 2023-05-15 11:22:51 +02:00
b0f06c1082 depends_on is a string array 2023-05-15 11:18:52 +02:00
2e3b529d17 attempt to fix unmarshal error 2023-05-15 11:14:26 +02:00
b6c83ccec9 indentation 2023-05-15 11:07:40 +02:00
fda4cd9ccb Add build-install 2023-05-15 10:48:29 +02:00
48997b41c7 Add TODO note 2023-05-13 11:11:26 +02:00
2e19f44b17 more debugging - definitely need to escape the local var 2023-05-13 11:06:33 +02:00
2c00eaca50 more debugging 2023-05-13 11:05:16 +02:00
4789a563c6 YADE 2023-05-13 10:59:50 +02:00
203f492d91 duh! 2023-05-13 10:54:55 +02:00
9aa04e30eb Experiment with some debug code 2023-05-13 10:53:52 +02:00
7df881f611 Hard code CC 2023-05-13 10:44:50 +02:00
d968b291c3 Fix typo 2023-05-13 10:43:58 +02:00
315b379765 Try yet again 2023-05-13 10:41:44 +02:00
c95fc7a9a6 Try again 2023-05-13 10:38:33 +02:00
bea295bc63 Syntax again 2023-05-13 10:28:39 +02:00
b3b1731f1d Syntax 2023-05-13 10:27:08 +02:00
ef222418df Fill out linux pipeline 2023-05-13 10:01:40 +02:00
c562cce807 Initial commit of drone.yml using tfm's make 2023-05-13 09:46:43 +02:00
e0be67f243 Initial commit of CMake build support 2023-05-13 09:44:49 +02:00
5803eacbcb Enable kate project/editor support 2023-05-13 09:43:52 +02:00
Steffen Jaeckel
7bfb903735
Merge pull request #26 from aewag/develop
fix INNERMUL and PROPCARRY warnings for ARM inline asm
2021-02-19 20:42:34 +01:00
aewag
53e8e9a874 fix INNERMUL and PROPCARRY warnings for ARM inline asm 2021-02-19 20:30:36 +01:00
Steffen Jaeckel
6a41cc4e2d fix docs on non-linux machines
This closes #27

[skip ci]
2021-02-04 19:09:20 +01:00
Steffen Jaeckel
55863ae1d9 fix sqr_comba warnings for comba3&4 2019-11-07 20:37:42 +01:00
Steffen Jaeckel
c82a774e4c
Merge pull request #23 from libtom/relicense
Relicense
2019-11-07 20:36:06 +01:00
Steffen Jaeckel
6ac31fe980 more clean-up & relicense 2019-10-03 16:54:37 +02:00
Steffen Jaeckel
2c320c3d54 remove mess.sh 2019-10-03 16:49:34 +02:00
Steffen Jaeckel
b5f84fcd49 always try to re-build tfm.pdf 2019-09-23 17:05:01 +02:00
Steffen Jaeckel
7087068e1a tom's email doesn't work anymore 2019-09-23 17:03:08 +02:00
Steffen Jaeckel
e29160b144 remove pre_gen from repo 2019-09-23 17:01:21 +02:00
Steffen Jaeckel
a251347c50 clean-up file headers & footers 2019-09-23 16:35:41 +02:00
Steffen Jaeckel
6b1c8318a9 Re-license 2019-09-23 16:08:13 +02:00
Steffen Jaeckel
218a79351f
Merge pull request #22 from libtom/fix-travis
fix travis build
2019-09-06 09:23:47 +02:00
Steffen Jaeckel
3495a5ca1d don't build all branches 2019-09-06 09:16:30 +02:00
Steffen Jaeckel
e291abe703 enable sudo-required for the build 2019-09-06 09:16:30 +02:00
Steffen Jaeckel
397d2ca9a3 fix fp_iseven() ... this time for real
as indicated once more by @muks in #21
2019-09-04 22:13:51 +02:00
Steffen Jaeckel
ae948ee4a9 fix fp_iseven()
as indicated by @muks in #21
2019-09-03 11:17:32 +02:00
Steffen Jaeckel
9752086431 fix warning when compiling tfm from pre_gen/mpi.c 2018-06-22 15:31:58 +02:00
Steffen Jaeckel
3bfaf74033 protect include of c-files
the way it was before, pre_gen/mpi.c couldn't be built
2018-02-01 01:53:00 +01:00
Steffen Jaeckel
b460616547 improve make clean 2017-09-13 18:08:38 +02:00
Steffen Jaeckel
f98098f78f use pseudo-random data for mtest 2017-09-13 17:55:22 +02:00
Steffen Jaeckel
d3cca2245f let's have the same amount of invmod tests than the other tests 2017-09-13 17:47:23 +02:00
Steffen Jaeckel
8bb0855e74 fix coverage creation 2017-09-13 17:46:41 +02:00
Steffen Jaeckel
e7fc79309e fix compiler warning 2017-09-13 17:28:15 +02:00
Steffen Jaeckel
00bee4c975 add possibility to only run timing for a specific operation 2017-09-13 17:20:27 +02:00
Steffen Jaeckel
0729166b25 also provide early-out optimization of comba32 for bigger multipliers 2017-09-13 16:11:43 +02:00
Steffen Jaeckel
5f0ffc0e26 properly re-generate fp_mul_comba32() 2017-09-13 16:07:59 +02:00
Steffen Jaeckel
8042e3ff5f also regen mont/fp_mont_small.i 2017-09-13 15:58:36 +02:00
Steffen Jaeckel
4eac223b54 display git version in ident string if available 2017-09-13 15:21:59 +02:00
Steffen Jaeckel
3dc016ffca consolidate makefiles a bit 2017-09-13 15:21:29 +02:00
Steffen Jaeckel
8924d33424 properly handle install PREFIX etc. 2017-09-13 15:20:40 +02:00
Steffen Jaeckel
81530c207d add fp_isprime_ex to exported symbols 2017-06-14 17:17:30 +02:00
Steffen Jaeckel
8cfdb2a3b9 fix warning on OS X 2017-06-14 14:11:00 +02:00
Steffen Jaeckel
cf4dd99079 use zipup from ltc 2017-06-14 13:58:48 +02:00
Steffen Jaeckel
0bcd2dd635 fix tfm.tex 2017-06-14 13:50:52 +02:00
Steffen Jaeckel
916f81304d remove tfm.pdf from repo 2017-06-14 13:49:46 +02:00
Steffen Jaeckel
b8941c8f67 move tfm.tex to doc 2017-06-14 13:46:05 +02:00
Steffen Jaeckel
53baae2c99 don't include tfm.h from the system, but the local one 2017-06-14 13:18:12 +02:00
Steffen Jaeckel
fe56698355 also show in TFM_VERSION[_S] that we're in-development 2017-06-14 13:17:44 +02:00
Steffen Jaeckel
aae8ed3809 add pkg-config file for shared library 2017-06-14 13:16:54 +02:00
Steffen Jaeckel
e632e097c8 introduce makefile_include.mk
this also fixes a bug where makefile.shared didn't always use $(LT)
instead of libtool
2017-06-14 13:16:06 +02:00
Steffen Jaeckel
6c1b3e2424 clean-up installation process 2017-05-11 09:13:38 +02:00
Steffen Jaeckel
71de1a493d only include library objects in library 2017-05-11 08:58:54 +02:00
Steffen Jaeckel
e085db82d6 Merge pull request #15 from bchauvaux/develop
Now truncating input array if ENDIANESS is unknown
2017-04-18 13:19:16 +02:00
bchauvaux
dfad7c7d17 Now truncating input array if ENDIANESS is unknown 2017-04-12 13:09:23 -07:00
Steffen Jaeckel
8ea3fb46b1 fix parallel build 2017-04-08 22:10:29 +02:00
Steffen Jaeckel
c2d5fbfd0e improve tests, add coverage make target 2017-04-08 21:58:12 +02:00
Steffen Jaeckel
df82859cc8 start development on next version 2017-04-04 12:27:35 +02:00
Steffen Jaeckel
e578621888 Merge tag 'v0.13.1' into develop
Bugfix release 0.13.1
2017-04-04 12:25:02 +02:00
136 changed files with 2370 additions and 14959 deletions

124
.drone.yml Normal file
View File

@ -0,0 +1,124 @@
---
kind: pipeline
name: build-linux
platform:
arch: amd64
environment:
SLEEP: 600
imagedefs:
- &anchor_compiler_image
image: dctl-registry.dcinet:5000/suse-15.4/gcc-113
steps:
- name: build
<<: *anchor_compiler_image
volumes:
- name: temp
path: /tmp
- name: cache
path: /tmp/cache
commands:
- export CC=gcc
- make -f makefile.shared test_standalone >test_gcc_1.txt 2>test_gcc_2.txt
- ./test >test_std.txt 2>test_err.txt
- name: build-fail
<<: *anchor_compiler_image
volumes:
- name: temp
path: /tmp
- name: cache
path: /tmp/cache
commands:
- echo "Go do some debugging - you've got $${SLEEP} seconds"
- sleep $${SLEEP}
- cat test_gcc_1.txt
- cat test_std.txt
- cat test_err.txt
when:
status:
- failure
- name: build-success
<<: *anchor_compiler_image
volumes:
- name: temp
path: /tmp
- name: cache
path: /tmp/cache
commands:
# - echo "Go check where the binaries are - you've got $${SLEEP} seconds"
# - sleep $${SLEEP}
- cat test_gcc_2.txt
depends_on:
- build
when:
status:
- success
# ### NOTE build-install is of no use to us for fireswarm as it only installs the static library and header
# ### It is easier to pull shared lib from .libs/libtfm.so.1.0.0 and header from src/headers/tfm.h
#- name: build-install
#<<: *anchor_compiler_image
#volumes:
#- name: temp
#path: /tmp
#- name: cache
#path: /tmp/cache
#commands:
#- make install
#- ls -R -l /usr/local/* | grep tfm
#depends_on:
#- build-success
# ### TODO package up the contents of .libs and maybe the public header?
# #-rw-r--r-- 1 root root 325206 May 13 09:06 libtfm.a
# #lrwxrwxrwx 1 root root 12 May 13 09:06 libtfm.la -> ../libtfm.la
# #-rw-r--r-- 1 root root 909 May 13 09:06 libtfm.lai
# #lrwxrwxrwx 1 root root 15 May 13 09:06 libtfm.so -> libtfm.so.1.0.0
# #lrwxrwxrwx 1 root root 15 May 13 09:06 libtfm.so.1 -> libtfm.so.1.0.0
# #-rwxr-xr-x 1 root root 233136 May 13 09:06 libtfm.so.1.0.0
# #-rw-r--r-- 1 root root 671 May 13 09:06 libtfm.ver
volumes:
- name: cache
host:
path: /srv/dockerctl_icc/cache
- name: staging-icc
host:
path: /srv/dockerctl_icc/staging
- name: temp
temp: {}
trigger:
# For now we only run on demand
event:
- custom
# Disable running pipeline a second time when we promote a successful build
exclude:
- promote
# ---
# kind: pipeline
# name: build-windows
# platform:
# arch: amd64
# environment:
# MYCC: gcc" SHARED="-f makefile.shared"
# steps:
# - name: test
# image: gcc
# commands:
# - ${MYCC}" make ${SHARED} test_standalone >test_gcc_1.txt 2>test_gcc_2.txt && ./test >test_std.txt 2>test_err.txt"
...

4
.gitattributes vendored Normal file
View File

@ -0,0 +1,4 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/** export-subst

15
.gitignore vendored
View File

@ -14,6 +14,15 @@
.cproject .cproject
/.libs /.libs
test_*.txt test_*.txt
*.pc
doc/tfm.pdf
pre_gen/
*.gcda
*.gcno
*.info
coverage/
compat_reports/
test test
test.exe test.exe
@ -25,3 +34,9 @@ rsatest
rsatest.exe rsatest.exe
timing timing
timing.exe timing.exe
/Build/
/cmake/sources.txt
/.drone.yml.lint.txt
/yamllint-config.yml
/yamllint.sh
/yq.sh

17
.kateconfig Normal file
View File

@ -0,0 +1,17 @@
# global editor options
auto-brackets false;
indent-width 4;
newline-at-eof on;
replace-tabs on;
replace-tabs-save on;
tab-width 4;
# Force override of cmake options
kate-wildcard(*.cmake;CMakeLists.txt): auto-brackets false;
kate-wildcard(*.cmake;CMakeLists.txt): indent-width 4;
kate-wildcard(*.cmake;CMakeLists.txt): newline-at-eof on;
kate-wildcard(*.cmake;CMakeLists.txt): replace-tabs on;
kate-wildcard(*.cmake;CMakeLists.txt): replace-tabs-save on;
kate-wildcard(*.cmake;CMakeLists.txt): tab-width 4;

5
.kateproject Normal file
View File

@ -0,0 +1,5 @@
{
"name": "CMakeLists",
"directory": "/srv/code/cpp/FireSwarm",
"files": [ { "git": 1 } ]
}

View File

@ -1,6 +1,14 @@
dist: trusty
sudo: required
language: c language: c
compiler: compiler:
- gcc - gcc
branches:
only:
- master
- develop
- /^release/
- /^travis/
script: CC="${MYCC}" make ${SHARED} test_standalone >test_gcc_1.txt 2>test_gcc_2.txt && ./test >test_std.txt 2>test_err.txt script: CC="${MYCC}" make ${SHARED} test_standalone >test_gcc_1.txt 2>test_gcc_2.txt && ./test >test_std.txt 2>test_err.txt
env: env:
- MYCC="gcc" SHARED="" - MYCC="gcc" SHARED=""

464
CMake.sh Executable file
View File

@ -0,0 +1,464 @@
#!/bin/bash
todo() {
<< TODO
- Continue with adding platform(s)
- Add support for other platforms such as x86.
- Add support for Release | Debug | DebugInfo etc.
- If generating CodeBlocks support...
- Parse the source and for each CMakeLists found add it to the workspace
TODO
}
load_opts() {
GETOPT=$( getopt -o bcdDfhiru \
--long build,cmakehelp,debug,dry-run,fbver:,fresh,help,info,reset,usecodeblocks,verbose \
-n "$0" -- "$@" )
}
ShowHelp(){
tabs 3,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61,65,69,73,77
DOCNOTE=$(cat << MSG > ${BASENAME}-readme.md
# CMake wrapper script
This script encapsulates the necessary calls to the CMake binary to configure
and generate the makefiles required to build this application.
Optionally a full build can also be executed.
### Options
- (boolean) help
Outputs this help screen and quits.
- (boolean) build
Will execute make in the build dir if makefile generation was successful.
- (boolean) cmakehelp
Outputs the CMake help screen and quits.
- (string) --fbver
The firebird version to build against.
This must be in the format 'fb4', 'fb5' etc.
The script will exit if this parameter is not supplied.
NOTE: Currently this application does not need to know the firebird version.
This setting is just a formality. However, firebird __MUST__ be installed.
- (boolean) --fresh
Pass --fresh to cmake, removing existing cache files.
- (boolean) --reset
Delete the Build dir. Recommended if thinks start to go wrong after
successive runs of CMake but should not usually be required.
- (boolean) --usecodeblocks
Generates CodeBlocks project files in addition to standard make files
These will be placed under the Build dir.
(Not tested.)
### Examples
- Configure and Generate make files for all platforms
CMake.sh --fbver fb4
- Check the CMake Help screen
CMake.sh --cmakehelp
- Configure, Generate and build all platforms
CMake.sh --fbver fb4 -build
MSG
)
cat ${BASENAME}-readme.md
}
######################### START OF GENERIC FUNCTIONS #########################
Pause(){
local _aprompt=""
if [ "${1:-}" = "" ]; then
_aprompt="Press any key to continue..."
else
_aprompt="$*"
fi
#shellcheck disable=SC2162
read -p "$_aprompt"
}
GetTime(){
export LOGSTAMP=$(date "+%Y-%m-%d %H:%M:%S")
export DATESTAMP=$(date +%Y%m%d)
export TIMESTAMP=$(date +%Y%m%d-%H%M%S)
export TAGSTAMP=$(date +:%Y%m%d%H%M)
case "${1:-}" in
LOGSTAMP)
echo LOGSTAMP is "$LOGSTAMP"
;;
DATESTAMP)
echo DATE is "$DATESTAMP"
;;
TIMESTAMP)
echo TIMESTAMP is "$TIMESTAMP"
;;
TAGSTAMP)
echo TAGSTAMP is "$TAGSTAMP"
;;
esac
}
GetLogStamp() {
GetTime "LOGSTAMP"
}
Debug() {
# Debug is intended for printing values assigned to variables etc.
if [ "${DEBUG:-}" == "1" ]; then
GetTime
local FUNC=$1
shift
echo -e $LOGSTAMP $FUNC "-" "$@"
fi
}
Verbose() {
# Verbose is intended to give the user a more
# detailed narrative of programm execution.
# shellcheck disable=SC2166
if [ "${VERBOSE:-}" == "1" -o "${DEBUG:-}" == "1" ]; then
GetTime
if [ "${2:-}" = "" ]; then
echo -e $LOGSTAMP "$@"
else
local FUNC=${1:-}
shift
echo -e $LOGSTAMP $FUNC "-" "$@"
fi
fi
}
EchoSpacer() {
set +x
# Echo a divider line to output
if [ -z ${1:-} ]; then
_spacer="-"
else
_spacer=$1
fi
if [ -z ${2:-} ]; then
_repeat="80"
else
_repeat=$2
fi
echo -e "\n"
for a in $(seq 1 ${_repeat} )
do
echo -n "$_spacer"
done
echo -e "\n"
}
WriteLog() {
# Param 1 - Logfile
# Param 2 - FUNCNAME
# We automatically call Verbose after shifting LOGFILE
# We then shift FUNCNAME and write out to the log.
GetTime
local LOGFILE=${1:-}
shift
Verbose "$@"
# shellcheck disable=SC2166
if [ ! "${VERBOSE:-}" = 1 -o ! "${DEBUG:-}" = 1 ]; then
shift
fi
if [ ! "${LOGFILE:-}" = "" ]; then
echo -e $LOGSTAMP "-" "$@" >> $LOGFILE
fi
}
Stop() {
# echo an error code and a message and stop execution.
local _err=0
if [ "${1:-}" -ge 0 ] 2>/dev/null ; then
_err=$1
shift
fi
echo "$@"
exit $_err
}
Error(){
local _err=0
if [ "${1:-}" -ge 0 ] 2>/dev/null ; then
_err=$1
shift
fi
EchoSpacer
echo ""
echo " Error in $0"
echo " $* "
echo ""
EchoSpacer
return $_err
<< COMMENT
Use Error on its own thus:
Error 1 A remark about the error
In this case it is up to the caller to test the error code
Or use it with Stop:
Error 1 A remark about the error
Stop $?
COMMENT
}
######################### END OF GENERIC FUNCTIONS #########################
ResetVars() {
unset BUILD
unset CMAKEHELP
unset DEBUG
unset DRYRUN
unset FRESH
unset FBVER
unset RESET
unset SHOWINFO
unset USECODEBLOCKS
BASENAME=$(basename "$0" .sh)
GENERATOR="Unix Makefiles"
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
}
ParseCommandLine() {
#set -x
if [ $# -le 0 ]; then
ShowHelp
return 1
fi
eval set -- "$GETOPT"
while true; do
case "${1:-}" in
-h|--help) return 1 ;;
-b|--build)
BUILD=" --build ";
shift;
;;
-c|--cmakehelp)
CMAKEHELP=" --help ";
shift;
;;
-d|--debug)
DEBUG=1;
shift;
;;
-D|--dry-run)
DRYRUN=1;
shift;
;;
-f|--fresh)
FRESH=" --fresh ";
shift;
;;
--fbver)
if [ "$2" ] > /dev/null 2>&1; then
FBVER="$2";
fi
shift; shift;
;;
-i|--info)
SHOWINFO=1;
shift;
;;
-r|--reset)
RESET=1;
shift;
;;
-u|--usecodeblocks)
GENERATOR="CodeBlocks - Unix Makefiles";
shift;
;;
-v|--verbose)
VERBOSE=1;
shift;
;;
--)
shift;
break;
;;
*)
echo "Invalid Option ${1:-}";
#ShowHelp
shift; shift;
return 1;
;;
esac
done
}
RemoveBuildDir() {
if [ -d $SCRIPTPATH/Build ]; then
Verbose Removing $SCRIPTPATH/Build directory
rm $SCRIPTPATH/Build --recursive
else
Verbose $SCRIPTPATH/Build directory does not exist.
fi
}
CheckParams() {
if [ "${RESET:-}" == "1" ]; then
RemoveBuildDir
fi
if [ ! "${CMAKEHELP:-}" == "" ]; then
cmake $CMAKEHELP
Stop $?
fi
}
ShowInfo() {
Debug Entering FUNCNAME "$FUNCNAME"
if [ "${SHOWINFO:-}" == "1" ]; then
echo
echo g++ version is...........$(g++ --version) | cut -c1-80
echo cmake version is ........$(cmake --version) | cut -c1-80
echo make version is..........$(make --version) | cut -c1-80
echo
fi
return 0
}
Generate() {
Debug Entering FUNCNAME "$FUNCNAME"
local _err=0
# Be sure that we are actually in the root of our repo.
pushd $SCRIPTPATH > /dev/null
_cmdstr='cmake ${FRESH:-} -G "${GENERATOR}" -S . -B Build '
Verbose Executing "$_cmdstr"
eval "$_cmdstr"
_err=$?
popd > /dev/null
return $_err
}
Build() {
if [ "${BUILD:-}" != "" ]; then
pushd $SCRIPTPATH/Build > /dev/null
make
popd > /dev/null
fi
}
main () {
EchoSpacer "="
ResetVars
load_opts "$@"
#set -x
ParseCommandLine "$@" || return 1
CheckParams
ShowInfo
Generate || return $?
Build
EchoSpacer "="
}
main "$@"
if [ $? -ne 0 ]; then echo "An error occurred."; fi
set +x

223
CMakeLists.txt Normal file
View File

@ -0,0 +1,223 @@
##
## THIS IS THE MASTER FILE
## It contains some basic defaults and defintions that are inherited by the projects
##
################################################################################
# CONTENTS
#
# Project header
# CMake globals
# Project Settings
# Options
# Targets
# Testing (TODO)
# Packaging (TODO)
################################################################################
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
include(ConfigSafeGuards)
################################################################################
#
# Project header
#
#################################################################################
# Suppress "Policy CMP0066 is not set"
# This policy provides compatibility for projects that do not expect
# config-specific compiler flags to be used.
# See https://cmake.org/cmake/help/latest/policy/CMP0066.html
#set (CMAKE_POLICY_WARNING_CMP0066 OFF)
cmake_minimum_required(VERSION 3.10)
# tomsfastmath - modified from CMakeLists.txt created for libtomath
project (TOMSFASTMATH
VERSION 0.13.1
DESCRIPTION "TomsFastMath is meant to be a very fast yet still fairly portable and easy to port large integer arithmetic library written in ISO C."
HOMEPAGE_URL "https://github.com/libtom/tomsfastmath"
LANGUAGES C)
# package release version
# bump if re-releasing the same VERSION + patches
# set to 1 if releasing a new VERSION
set(PACKAGE_RELEASE_VERSION 1)
################################################################################
#
# CMake Global Settings
#
################################################################################
# Allow use of function cmake_print_variables to print vars to output
# See https://cmake.org/cmake/help/latest/module/CMakePrintHelpers.html
include(CMakePrintHelpers)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "Export compile_commands.json to support editors such as Kate, Visual Studio Code, Vim etc.")
set(CMAKE_VERBOSE_MAKEFILE ON CACHE INTERNAL "Generate verbose makefile")
# For tomsfastmath we use Build, although convention is to use all lowercase
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/Build)
################################################################################
#
# Project Settings
#
#################################################################################
# Define build mode - this must be executed AFTER the project command otherwise
# the cmake compiler will complain that CMAKE_BUILD_TYPE is uninitialised.
message(STATUS "CMAKE_BUILD_TYPE is ${CMAKE_BUILD_TYPE}")
if (NOT DEFINED CMAKE_BUILD_TYPE OR "${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build...")
endif()
if ( UNIX )
set(CMAKE_INSTALL_PREFIX /opt/fireswarm CACHE PATH "Default installation directory" FORCE)
elseif ( WIN32 )
set(CMAKE_INSTALL_PREFIX $ENV{ProgramFiles}/fireswarm CACHE PATH "Default installation directory" FORCE)
endif()
################################################################################
#
# Option Settings
#
#################################################################################
# ### Options: Things you can set via commandline options to cmake (e.g. -DTOMSFASTMATH_DISABLE_LIBCXX=[ON|OFF])
option(BUILD_SHARED_LIBS "Build shared library" ON)
option(TOMSFASTMATH_DISABLE_LIBCXX "Do not use libc++, even if available" ON)
option(ENABLE_WARNINGS_SETTINGS "Allow target_set_warnings to add flags and defines.
Set this to OFF if you want to provide your own warning parameters.
See cmake/Warnings.cmake for more info." ON)
option(ENABLE_LTO "Enable link time optimization" ON)
include(LTO)
include(Warnings)
include(functions)
include(sources)
include(CompilerSettings)
# Check for LTO (Link-time optimisation) support.
find_lto(CXX)
include_directories( "src/" "src/headers" )
include(cmake/sources.cmake)
# The only direct cmake argument for now
option(BUILD_SHARED_LIBS "Build shared library and only the shared library if \"ON\", default is static" OFF)
#-----------------------------------------------------------------------------
# Compose CFLAGS
#-----------------------------------------------------------------------------
# Some information ported from makefile_include.mk
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release")
endif()
# We only differentiate between MSVC and GCC-compatible compilers
if(MSVC)
set(LTM_C_FLAGS -W3)
elseif(WATCOM)
set(LTM_C_FLAGS -fo=.obj -oaxt -3r -w3)
else()
set(LTM_C_FLAGS -Wall -Wsign-compare -Wextra -Wshadow
-Wdeclaration-after-statement -Wbad-function-cast -Wcast-align
-Wstrict-prototypes -Wpointer-arith -Wsystem-headers)
set(CMAKE_C_FLAGS_DEBUG "-g3")
set(CMAKE_C_FLAGS_RELEASE "-O3 -funroll-loops -fomit-frame-pointer")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g3 -O2")
set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
endif()
# What compiler do we have and what are their...uhm... peculiarities
if(CMAKE_C_COMPILER_ID MATCHES "(C|c?)lang")
list(APPEND LTM_C_FLAGS -Wno-typedef-redefinition -Wno-tautological-compare -Wno-builtin-requires-header)
# Clang requires at least '-O1' for dead code elimination
set(CMAKE_C_FLAGS_DEBUG "-O1 ${CMAKE_C_FLAGS_DEBUG}")
endif()
if(CMAKE_C_COMPILER MATCHES "mingw")
list(APPEND LTM_C_FLAGS -Wno-shadow -Wno-expansion-to-defined -Wno-declaration-after-statement -Wno-bad-function-cast)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
list(APPEND LTM_C_FLAGS -Wno-nullability-completeness)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "CYGWIN")
list(APPEND LTM_C_FLAGS -no-undefined)
endif()
# TODO: coverage (lgcov)
# If the user set the environment variables at generate-time, append them
# in order to allow overriding our defaults.
# ${LTM_CFLAGS} means the user passed it via sth like:
# $ cmake -DLTM_CFLAGS="foo"
list(APPEND LTM_C_FLAGS ${LTM_CFLAGS})
list(APPEND LTM_LD_FLAGS ${LTM_LDFLAGS})
#-----------------------------------------------------------------------------
# library target
#-----------------------------------------------------------------------------
add_library( ${PROJECT_NAME} SHARED
${TFM_SOURCE}
${TFM_HEADERS}
)
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
)
target_compile_options(${PROJECT_NAME} BEFORE PRIVATE
${LTM_C_FLAGS}
)
target_link_options(${PROJECT_NAME} BEFORE PRIVATE
${LTM_LD_FLAGS}
)
set(PUBLIC_HEADERS tfm.h)
set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME tomsfastmath
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
PUBLIC_HEADER "${PUBLIC_HEADERS}"
)
option(COMPILE_LTO "Build with LTO enabled")
if(COMPILE_LTO)
check_ipo_supported(RESULT COMPILER_SUPPORTS_LTO)
if(COMPILER_SUPPORTS_LTO)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(SEND_ERROR "This compiler does not support LTO. Reconfigure ${PROJECT_NAME} with -DCOMPILE_LTO=OFF.")
endif()
endif()
################################################################################
################################################################################
################################################################################
################################################################################

52
LICENSE
View File

@ -1,36 +1,26 @@
TomsFastMath is licensed under DUAL licensing terms. The LibTom license
Choose and use the license of your needs. This is free and unencumbered software released into the public domain.
[LICENSE #1] Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
TomsFastMath is public domain. As should all quality software be. In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
Tom St Denis THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
[/LICENSE #1] For more information, please refer to <http://unlicense.org/>
[LICENSE #2]
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
[/LICENSE #2]
-- Mark Karpelès & Steffen Jaeckel
Note some ideas were borrowed from LibTomMath and OpenSSL. All of the code is original or ported
from LibTomMath [no code was ported from OpenSSL].
-- Tom St Denis

View File

@ -0,0 +1,54 @@
################################################################################
#
# Compiler Settings
#
################################################################################
# Require and enable C++ 0x/11/14/17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS "tomsfastmath pre-check compiler: C++${CMAKE_CXX_STANDARD} with CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wnarrowing -Werror ")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wnarrowing -Wextra")
set(CMAKE_CXX_FLAGS " -Werror -Wshadow -Wextra -Wall -fexceptions -fno-omit-frame-pointer -fno-rtti -DUNICODE ${CMAKE_CXX_FLAGS} ")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
include(CheckCXXCompilerFlag)
if(NOT TOMSFASTMATH_DISABLE_LIBCXX)
check_cxx_compiler_flag("-stdlib=libc++" CXX_SUPPORTS_STDLIB)
if(CXX_SUPPORTS_STDLIB)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -stdlib=libc++")
endif()
set(TOMSFASTMATH_DISABLE_LIBCXX ${TOMSFASTMATH_DISABLE_LIBCXX} CACHE BOOL "Do not use libc++, if available." FORCE)
endif()
message(STATUS "tomsfastmath build: Disable linking libc++ - ${TOMSFASTMATH_DISABLE_LIBCXX}")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
string(REGEX REPLACE "[/-]W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if (NOT (CMAKE_VERSION VERSION_LESS 3.6.0)) # Compiler features for Intel in CMake 3.6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qstd=c++17")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /QaxCORE-AVX2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:precise")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Qipo")
elseif(MSVC)
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if(MSVC_VERSION LESS 1900)
message(FATAL_ERROR "tomsfastmath : Build requires C++17-compliant compiler")
endif()
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "tomsfastmath : Global compiler flags - ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
message(STATUS "tomsfastmath : Global compiler flags - ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
elseif(CMAKE_BUILD_TYPE MATCHES Release)
message(STATUS "tomsfastmath : Global compiler flags - ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
endif()

View File

@ -0,0 +1,22 @@
# https://github.com/bsamseth/cpp-project
# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()
# guard against bad build-type strings
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper)
if( NOT cmake_build_type_tolower STREQUAL "debug"
AND NOT cmake_build_type_tolower STREQUAL "release"
AND NOT cmake_build_type_tolower STREQUAL "profile"
AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo"
AND NOT cmake_build_type_tolower STREQUAL "coverage")
message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Coverage, Release, Profile, RelWithDebInfo (case-insensitive).")
endif()

255
cmake/LTO.cmake Normal file
View File

@ -0,0 +1,255 @@
################################################################################
#
# LTO - Link-time optimisation
#
################################################################################
#
# Usage :
#
# Variable : ENABLE_LTO | Enable or disable LTO support for this build
#
# find_lto(lang)
# - lang is C or CXX (the language to test LTO for)
# - call it after project() so that the compiler is already detected
#
# This will check for LTO support and create a target_enable_lto(target [debug,optimized,general]) macro.
# The 2nd parameter has the same meaning as in target_link_libraries, and is used to enable LTO only for those build configurations
# 'debug' is by default the Debug configuration, and 'optimized' all the other configurations
#
# if ENABLE_LTO is set to false, an empty macro will be generated
#
# Then to enable LTO for your target use
#
# target_enable_lto(mytarget general)
#
# It is however recommended to use it only for non debug builds the following way :
#
# target_enable_lto(mytarget optimized)
#
# Note : For CMake versions < 3.9, target_link_library is used in it's non plain version.
# You will need to specify PUBLIC/PRIVATE/INTERFACE to all your other target_link_library calls for the target
#
# WARNING for cmake versions older than 3.9 :
# This module will override CMAKE_AR CMAKE_RANLIB and CMAKE_NM by the gcc versions if found when building with gcc
# License:
#
# Copyright (C) 2016 Lectem <lectem@gmail.com>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the 'Software') deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
macro(find_lto lang)
if(ENABLE_LTO AND NOT LTO_${lang}_CHECKED)
#LTO support was added for clang/gcc in 3.9
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
cmake_policy(SET CMP0054 NEW)
message(STATUS "Checking for LTO Compatibility")
# Since GCC 4.9 we need to use gcc-ar / gcc-ranlib / gcc-nm
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_GCC_AR OR NOT CMAKE_GCC_RANLIB OR NOT CMAKE_GCC_NM)
find_program(CMAKE_GCC_AR NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${_version}"
DOC "gcc provided wrapper for ar which adds the --plugin option"
)
find_program(CMAKE_GCC_RANLIB NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${_version}"
DOC "gcc provided wrapper for ranlib which adds the --plugin option"
)
# Not needed, but at least stay coherent
find_program(CMAKE_GCC_NM NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm-${_version}"
DOC "gcc provided wrapper for nm which adds the --plugin option"
)
mark_as_advanced(CMAKE_GCC_AR CMAKE_GCC_RANLIB CMAKE_GCC_NM)
set(CMAKE_LTO_AR ${CMAKE_GCC_AR})
set(CMAKE_LTO_RANLIB ${CMAKE_GCC_RANLIB})
set(CMAKE_LTO_NM ${CMAKE_GCC_NM})
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_LTO_AR ${CMAKE_AR})
set(CMAKE_LTO_RANLIB ${CMAKE_RANLIB})
set(CMAKE_LTO_NM ${CMAKE_NM})
endif()
if(CMAKE_LTO_AR AND CMAKE_LTO_RANLIB)
set(__lto_flags -flto)
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7)
list(APPEND __lto_flags -fno-fat-lto-objects)
endif()
if(NOT DEFINED CMAKE_${lang}_PASSED_LTO_TEST)
set(__output_dir "${CMAKE_PLATFORM_INFO_DIR}/LtoTest1${lang}")
file(MAKE_DIRECTORY "${__output_dir}")
set(__output_base "${__output_dir}/lto-test-${lang}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "void foo() {}"
COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -c -xc -
-o "${__output_base}.o"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_LTO_AR} cr "${__output_base}.a" "${__output_base}.o"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_LTO_RANLIB} "${__output_base}.a"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "void foo(); int main() {foo();}"
COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -xc -
-x none "${__output_base}.a" -o "${__output_base}"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
set(__lto_found TRUE)
endif()
set(CMAKE_${lang}_PASSED_LTO_TEST
${__lto_found} CACHE INTERNAL
"If the compiler passed a simple LTO test compile")
endif()
if(CMAKE_${lang}_PASSED_LTO_TEST)
message(STATUS "Checking for LTO Compatibility - works")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags")
else()
message(STATUS "Checking for LTO Compatibility - not working")
endif()
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Checking for LTO Compatibility - works (assumed for clang)")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(STATUS "Checking for LTO Compatibility - works")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS /GL CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -LTCG:INCREMENTAL CACHE STRING "Link Time Optimization link flags")
else()
message(STATUS "Checking for LTO Compatibility - compiler not handled by module")
endif()
mark_as_advanced(LTO_${lang}_SUPPORT LTO_COMPILE_FLAGS LTO_LINK_FLAGS)
set(LTO_${lang}_CHECKED TRUE CACHE INTERNAL "" )
if(CMAKE_GCC_AR AND CMAKE_GCC_RANLIB AND CMAKE_GCC_NM)
# THIS IS HACKY BUT THERE IS NO OTHER SOLUTION ATM
set(CMAKE_AR ${CMAKE_GCC_AR} CACHE FILEPATH "Forcing gcc-ar instead of ar" FORCE)
set(CMAKE_NM ${CMAKE_GCC_NM} CACHE FILEPATH "Forcing gcc-nm instead of nm" FORCE)
set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE FILEPATH "Forcing gcc-ranlib instead of ranlib" FORCE)
endif()
endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
endif(ENABLE_LTO AND NOT LTO_${lang}_CHECKED)
if(ENABLE_LTO)
#Special case for cmake older than 3.9, using a library for gcc/clang, but could setup the flags directly.
#Taking advantage of the [debug,optimized] parameter of target_link_libraries
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
if(LTO_${lang}_SUPPORT)
if(NOT TARGET __enable_lto_tgt)
add_library(__enable_lto_tgt INTERFACE)
endif()
target_compile_options(__enable_lto_tgt INTERFACE ${LTO_COMPILE_FLAGS})
#this might not work for all platforms... in which case we'll have to set the link flags on the target directly
target_link_libraries(__enable_lto_tgt INTERFACE ${LTO_LINK_FLAGS} )
macro(target_enable_lto _target _build_configuration)
if(${_build_configuration} STREQUAL "optimized" OR ${_build_configuration} STREQUAL "debug" )
target_link_libraries(${_target} PRIVATE ${_build_configuration} __enable_lto_tgt)
else()
target_link_libraries(${_target} PRIVATE __enable_lto_tgt)
endif()
endmacro()
else()
#In old cmake versions, we can set INTERPROCEDURAL_OPTIMIZATION even if not supported by the compiler
#So if we didn't detect it, let cmake give it a try
set(__IPO_SUPPORTED TRUE)
endif()
else()
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT __IPO_SUPPORTED OUTPUT output)
if(NOT __IPO_SUPPORTED)
message(STATUS "IPO (interprocedural optimization) is not supported or broken.")
else()
message(STATUS "IPO (interprocedural optimization) is supported")
endif()
endif()
if(__IPO_SUPPORTED)
macro(target_enable_lto _target _build_configuration)
if(NOT ${_build_configuration} STREQUAL "debug" )
#enable for all configurations
set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if(${_build_configuration} STREQUAL "optimized" )
#blacklist debug configurations
set(__enable_debug_lto FALSE)
else()
#enable only for debug configurations
set(__enable_debug_lto TRUE)
endif()
get_property(DEBUG_CONFIGURATIONS GLOBAL PROPERTY DEBUG_CONFIGURATIONS)
if(NOT DEBUG_CONFIGURATIONS)
set(DEBUG_CONFIGURATIONS DEBUG) # This is what is done by CMAKE internally... since DEBUG_CONFIGURATIONS is empty by default
endif()
foreach(config IN LISTS DEBUG_CONFIGURATIONS)
set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_${config} ${__enable_debug_lto})
endforeach()
endmacro()
endif()
endif()
if(NOT COMMAND target_enable_lto)
macro(target_enable_lto _target _build_configuration)
endmacro()
endif()
endmacro()

100
cmake/Warnings.cmake Normal file
View File

@ -0,0 +1,100 @@
# MIT License
#
# Copyright (c) 2017 Lectem
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
function(target_set_warnings)
if(NOT ENABLE_WARNINGS_SETTINGS)
return()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(WMSVC TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(WGCC TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(WCLANG TRUE)
endif()
set(multiValueArgs ENABLE DISABLE AS_ERROR)
cmake_parse_arguments(this "" "" "${multiValueArgs}" ${ARGN})
list(FIND this_ENABLE "ALL" enable_all)
list(FIND this_DISABLE "ALL" disable_all)
list(FIND this_AS_ERROR "ALL" as_error_all)
if(NOT ${enable_all} EQUAL -1)
if(WMSVC)
# Not all the warnings, but WAll is unusable when using libraries
# Unless you'd like to support MSVC in the code with pragmas, this is probably the best option
list(APPEND WarningFlags "/W4")
elseif(WGCC)
list(APPEND WarningFlags "-Wall" "-Wextra" "-Wpedantic")
elseif(WCLANG)
list(APPEND WarningFlags "-Wall" "-Weverything" "-Wpedantic")
endif()
elseif(NOT ${disable_all} EQUAL -1)
set(SystemIncludes TRUE) # Treat includes as if coming from system
if(WMSVC)
list(APPEND WarningFlags "/w" "/W0")
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags "-w")
endif()
endif()
list(FIND this_DISABLE "Annoying" disable_annoying)
if(NOT ${disable_annoying} EQUAL -1)
if(WMSVC)
# bounds-checked functions require to set __STDC_WANT_LIB_EXT1__ which we usually don't need/want
list(APPEND WarningDefinitions -D_CRT_SECURE_NO_WARNINGS)
# disable C4514 C4710 C4711... Those are useless to add most of the time
#list(APPEND WarningFlags "/wd4514" "/wd4710" "/wd4711")
#list(APPEND WarningFlags "/wd4365") #signed/unsigned mismatch
#list(APPEND WarningFlags "/wd4668") # is not defined as a preprocessor macro, replacing with '0' for
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags -Wno-switch-enum)
if(WCLANG)
list(APPEND WarningFlags -Wno-unknown-warning-option -Wno-padded -Wno-undef -Wno-reserved-id-macro -fcomment-block-commands=test,retval)
if(NOT CMAKE_CXX_STANDARD EQUAL 98)
list(APPEND WarningFlags -Wno-c++98-compat -Wno-c++98-compat-pedantic)
endif()
if ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") # clang-cl has some VCC flags by default that it will not recognize...
list(APPEND WarningFlags -Wno-unused-command-line-argument)
endif()
endif(WCLANG)
endif()
endif()
if(NOT ${as_error_all} EQUAL -1)
if(WMSVC)
list(APPEND WarningFlags "/WX")
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags "-Werror")
endif()
endif()
foreach(target IN LISTS this_UNPARSED_ARGUMENTS)
if(WarningFlags)
target_compile_options(${target} PRIVATE ${WarningFlags})
endif()
if(WarningDefinitions)
target_compile_definitions(${target} PRIVATE ${WarningDefinitions})
endif()
if(SystemIncludes)
set_target_properties(${target} PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>)
endif()
endforeach()
endfunction(target_set_warnings)

13
cmake/functions.cmake Normal file
View File

@ -0,0 +1,13 @@
# ##############################################################################
# cmake function library
# ##############################################################################
# Taken from https://jeremimucha.com/2021/01/cmake-fundamentals-part3/
# See also https://jeremimucha.com/2021/02/cmake-functions-and-macros/
function(PrintTargetLibraries target msg)
get_target_property(linkedLibs ${target} LINK_LIBRARIES)
get_target_property(interfaceLibs ${target} INTERFACE_LINK_LIBRARIES)
message(STATUS "${msg}")
message(STATUS "${target} LINK_LIBRARIES: ${linkedLibs}")
message(STATUS "${target} INTERFACE_LINK_LIBRARIES: ${interfaceLibs}")
endfunction()

121
cmake/sources.cmake Normal file
View File

@ -0,0 +1,121 @@
# ### ###########################################################################
# ### Definitions taken from CMakeLists.txt for tomsfastmath in ClamAV
# ### https://github.com/Cisco-Talos/clamav/blob/main/libclamav/CMakeLists.txt
# ### ###########################################################################
# Enable overflow checks in TomsFastMath's fp_exptmod() function.
add_definitions(-DTFM_CHECK)
# Just enable ASM in in TomsFastMath's on x86-64 where we know it works.
# on i686 we run out of registers with -fPIC, and on ia64 we miscompile.
if(NOT CMAKE_COMPILER_IS_GNUCC OR NOT (CMAKE_SIZEOF_VOID_P EQUAL 8))
add_definitions(-DTFM_NO_ASM)
endif()
# ### ###########################################################################
# ### SOURCES and HEADERS
# ### ###########################################################################
# to generate the source list cd to extern/tomsfastmath and execute:
# `find -type f -name *.c | grep -v generators |sort | cut -c 3- | awk '{ print "\"../src/"$0"\""}' > sources.txt`
# then copy/paste here as required.
set ( TFM_SOURCE
"../src/addsub/fp_add.c"
"../src/addsub/fp_add_d.c"
"../src/addsub/fp_addmod.c"
"../src/addsub/fp_cmp.c"
"../src/addsub/fp_cmp_d.c"
"../src/addsub/fp_cmp_mag.c"
"../src/addsub/fp_sub.c"
"../src/addsub/fp_sub_d.c"
"../src/addsub/fp_submod.c"
"../src/addsub/s_fp_add.c"
"../src/addsub/s_fp_sub.c"
"../src/bin/fp_radix_size.c"
"../src/bin/fp_read_radix.c"
"../src/bin/fp_read_signed_bin.c"
"../src/bin/fp_read_unsigned_bin.c"
"../src/bin/fp_reverse.c"
"../src/bin/fp_signed_bin_size.c"
"../src/bin/fp_s_rmap.c"
"../src/bin/fp_toradix.c"
"../src/bin/fp_toradix_n.c"
"../src/bin/fp_to_signed_bin.c"
"../src/bin/fp_to_unsigned_bin.c"
"../src/bin/fp_unsigned_bin_size.c"
"../src/bit/fp_cnt_lsb.c"
"../src/bit/fp_count_bits.c"
"../src/bit/fp_div_2.c"
"../src/bit/fp_div_2d.c"
"../src/bit/fp_lshd.c"
"../src/bit/fp_mod_2d.c"
"../src/bit/fp_rshd.c"
"../src/divide/fp_div.c"
"../src/divide/fp_div_d.c"
"../src/divide/fp_mod.c"
"../src/divide/fp_mod_d.c"
"../src/exptmod/fp_2expt.c"
"../src/exptmod/fp_exptmod.c"
"../src/misc/fp_ident.c"
"../src/misc/fp_rand.c"
"../src/misc/fp_set.c"
"../src/mont/fp_montgomery_calc_normalization.c"
"../src/mont/fp_montgomery_reduce.c"
"../src/mont/fp_montgomery_setup.c"
"../src/mul/fp_mul_2.c"
"../src/mul/fp_mul_2d.c"
"../src/mul/fp_mul.c"
"../src/mul/fp_mul_comba_12.c"
"../src/mul/fp_mul_comba_17.c"
"../src/mul/fp_mul_comba_20.c"
"../src/mul/fp_mul_comba_24.c"
"../src/mul/fp_mul_comba_28.c"
"../src/mul/fp_mul_comba_32.c"
"../src/mul/fp_mul_comba_3.c"
"../src/mul/fp_mul_comba_48.c"
"../src/mul/fp_mul_comba_4.c"
"../src/mul/fp_mul_comba_64.c"
"../src/mul/fp_mul_comba_6.c"
"../src/mul/fp_mul_comba_7.c"
"../src/mul/fp_mul_comba_8.c"
"../src/mul/fp_mul_comba_9.c"
"../src/mul/fp_mul_comba.c"
"../src/mul/fp_mul_comba_small_set.c"
"../src/mul/fp_mul_d.c"
"../src/mul/fp_mulmod.c"
"../src/numtheory/fp_gcd.c"
"../src/numtheory/fp_invmod.c"
"../src/numtheory/fp_isprime.c"
"../src/numtheory/fp_isprime_ex.c"
"../src/numtheory/fp_lcm.c"
"../src/numtheory/fp_prime_miller_rabin.c"
"../src/numtheory/fp_prime_random_ex.c"
"../src/sqr/fp_sqr.c"
"../src/sqr/fp_sqr_comba_12.c"
"../src/sqr/fp_sqr_comba_17.c"
"../src/sqr/fp_sqr_comba_20.c"
"../src/sqr/fp_sqr_comba_24.c"
"../src/sqr/fp_sqr_comba_28.c"
"../src/sqr/fp_sqr_comba_32.c"
"../src/sqr/fp_sqr_comba_3.c"
"../src/sqr/fp_sqr_comba_48.c"
"../src/sqr/fp_sqr_comba_4.c"
"../src/sqr/fp_sqr_comba_64.c"
"../src/sqr/fp_sqr_comba_6.c"
"../src/sqr/fp_sqr_comba_7.c"
"../src/sqr/fp_sqr_comba_8.c"
"../src/sqr/fp_sqr_comba_9.c"
"../src/sqr/fp_sqr_comba.c"
"../src/sqr/fp_sqr_comba_generic.c"
"../src/sqr/fp_sqr_comba_small_set.c"
"../src/sqr/fp_sqrmod.c"
)
set ( TFM_HEADERS
"../src/headers/tfm.h"
# "tfm_private.h"
)

View File

@ -1,3 +1,6 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#include "tfm.h" #include "tfm.h"
#include <time.h> #include <time.h>
@ -77,7 +80,3 @@ int main(void)
return 0; return 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,3 +1,6 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
/* A simple static test program. */ /* A simple static test program. */
#include <tfm.h> #include <tfm.h>
@ -180,8 +183,3 @@ int main(void)
return 0; return 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,3 +1,6 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
/* TFM demo program */ /* TFM demo program */
#include <tfm.h> #include <tfm.h>
#include <time.h> #include <time.h>
@ -427,14 +430,11 @@ draw(&a);draw(&b);draw(&c);draw(&d);
printf("d == %lu\n", ix); printf("d == %lu\n", ix);
return 0; return 0;
} }
} else if (!strcmp(cmd, "exit")) {
printf("\nokay, exiting now\n");
return 0;
} }
} }
#endif #endif
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,4 +1,8 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
/* TFM timing analysis */ /* TFM timing analysis */
#define _GNU_SOURCE
#include <tfm.h> #include <tfm.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
@ -65,21 +69,11 @@ static void print_line(ulong64 b, ulong64 t)
printf("%llu;%s;%llu;%llu\n", ticks, p_str, b, t); printf("%llu;%s;%llu;%llu\n", ticks, p_str, b, t);
} }
int main(void) static void Addition(ulong64 t1)
{ {
fp_int a,b,c,d; fp_int a,b,c;
ulong64 t1, t2; ulong64 t2;
fp_digit fp;
unsigned long t, ix; unsigned long t, ix;
t1 = TIMFUNC();
sleep(1);
ticks = TIMFUNC() - t1;
fprintf(stderr, "Ticks per second: %llu\n", ticks);
printf("Ticks/sec;Algorithm;bits;time\n");
/* do some timings... */
print_start("Addition");
for (t = 2; t <= FP_SIZE / 2; t += 2) { for (t = 2; t <= FP_SIZE / 2; t += 2) {
fp_zero(&a); fp_zero(&a);
fp_zero(&b); fp_zero(&b);
@ -109,7 +103,13 @@ int main(void)
} }
print_line(t * DIGIT_BIT, t2); print_line(t * DIGIT_BIT, t2);
} }
print_start("Multiplication"); }
static void Multiplication(ulong64 t1)
{
fp_int a,b,c;
ulong64 t2;
unsigned long t, ix;
for (t = 2; t < FP_SIZE / 2; t += 2) { for (t = 2; t < FP_SIZE / 2; t += 2) {
fp_zero(&a); fp_zero(&a);
fp_zero(&b); fp_zero(&b);
@ -259,8 +259,13 @@ int main(void)
} }
print_line(t * DIGIT_BIT, t2); print_line(t * DIGIT_BIT, t2);
} }
}
print_start("Squaring"); static void Squaring(ulong64 t1)
{
fp_int a,b;
ulong64 t2;
unsigned long t, ix;
for (t = 2; t < FP_SIZE / 2; t += 2) { for (t = 2; t < FP_SIZE / 2; t += 2) {
fp_zero(&a); fp_zero(&a);
fp_zero(&b); fp_zero(&b);
@ -407,8 +412,13 @@ int main(void)
} }
print_line(t * DIGIT_BIT, t2); print_line(t * DIGIT_BIT, t2);
} }
}
print_start("Invmod"); static void Invmod(ulong64 t1)
{
fp_int a,b,c;
ulong64 t2;
unsigned long t, ix;
for (t = 2; t < FP_SIZE / 2; t += 2) { for (t = 2; t < FP_SIZE / 2; t += 2) {
fp_zero(&a); fp_zero(&a);
for (ix = 0; ix < t; ix++) { for (ix = 0; ix < t; ix++) {
@ -497,8 +507,14 @@ int main(void)
} }
print_line(t * DIGIT_BIT, t2); print_line(t * DIGIT_BIT, t2);
} }
}
print_start("Montgomery"); static void Montgomery(ulong64 t1)
{
fp_int a,b,c,d;
ulong64 t2;
fp_digit fp;
unsigned long t, ix;
for (t = 2; t <= (FP_SIZE / 2) - 4; t += 2) { for (t = 2; t <= (FP_SIZE / 2) - 4; t += 2) {
// printf("%5lu-bit: %9llu\n", t * DIGIT_BIT, t2); // printf("%5lu-bit: %9llu\n", t * DIGIT_BIT, t2);
fp_zero(&a); fp_zero(&a);
@ -590,9 +606,13 @@ int main(void)
} }
print_line(t * DIGIT_BIT, t2); print_line(t * DIGIT_BIT, t2);
} }
}
print_start("Exptmod"); static void Exptmod(ulong64 t1)
{
fp_int a,b,c,d;
ulong64 t2;
unsigned long t, ix;
for (t = 512 / DIGIT_BIT; t <= (FP_SIZE / 2) - 2; t += 256 / DIGIT_BIT) { for (t = 512 / DIGIT_BIT; t <= (FP_SIZE / 2) - 2; t += 256 / DIGIT_BIT) {
fp_zero(&a); fp_zero(&a);
fp_zero(&b); fp_zero(&b);
@ -621,5 +641,41 @@ int main(void)
} }
print_line(t * DIGIT_BIT, t2); print_line(t * DIGIT_BIT, t2);
} }
}
#define FN(n) { n, #n }
struct {
void (*fn)(ulong64 t1);
const char* name;
} funcs[] = {
FN(Addition),
FN(Multiplication),
FN(Squaring),
FN(Invmod),
FN(Montgomery),
FN(Exptmod),
};
int main(int argc, char **argv)
{
ulong64 t1;
unsigned int t;
char* arg = NULL;
if (argc > 1) arg = argv[1];
t1 = TIMFUNC();
sleep(1);
ticks = TIMFUNC() - t1;
fprintf(stderr, "Ticks per second: %llu\n", ticks);
printf("Ticks/sec;Algorithm;bits;time\n");
/* do some timings... */
for (t = 0; t < sizeof(funcs)/sizeof(funcs[0]); ++t) {
if(arg != NULL && strcasestr(funcs[t].name, arg) == NULL) continue;
print_start(funcs[t].name);
funcs[t].fn(t1);
}
return 0; return 0;
} }

36
doc/makefile Normal file
View File

@ -0,0 +1,36 @@
# TomsFastMath, a fast ISO C bignum library. -- Tom St Denis
# SPDX-License-Identifier: Unlicense
ifeq ($V,1)
silent=
silent_stdout=
else
silent=@
silent_stdout= > /dev/null
endif
all: tfm.pdf
docdvi: tfm.tex
cp tfm.tex tfm.bak
touch -r tfm.tex tfm.bak
(printf "%s" "\def\fixedpdfdate{"; date +'D:%Y%m%d%H%M%S%:z' -d @$$(stat --format=%Y tfm.tex) | sed "s/:\([0-9][0-9]\)$$/'\1'}/g") > tfm-deterministic.tex
printf "%s\n" "\pdfinfo{" >> tfm-deterministic.tex
printf "%s\n" " /CreationDate (\fixedpdfdate)" >> tfm-deterministic.tex
printf "%s\n}\n" " /ModDate (\fixedpdfdate)" >> tfm-deterministic.tex
cat tfm.tex >> tfm-deterministic.tex
mv tfm-deterministic.tex tfm.tex
touch -r tfm.bak tfm.tex
touch tfm.ind
latex tfm $(silent_stdout)
latex tfm $(silent_stdout)
makeindex tfm
latex tfm $(silent_stdout)
tfm.pdf: docdvi
latex tfm $(silent_stdout)
pdflatex tfm $(silent_stdout)
sed -b -i 's,^/ID \[.*\]$$,/ID [<0> <0>],g' tfm.pdf
mv tfm.bak tfm.tex
docs: tfm.pdf

Binary file not shown.

View File

@ -1,3 +1,6 @@
% TomsFastMath, a fast ISO C bignum library. -- Tom St Denis
% SPDX-License-Identifier: Unlicense
\documentclass[b5paper]{book} \documentclass[b5paper]{book}
\usepackage{hyperref} \usepackage{hyperref}
\usepackage{makeidx} \usepackage{makeidx}
@ -50,7 +53,7 @@
\frontmatter \frontmatter
\pagestyle{empty} \pagestyle{empty}
\title{TomsFastMath User Manual \\ v0.13.1} \title{TomsFastMath User Manual \\ v0.13.1}
\author{Tom St Denis \\ tomstdenis@gmail.com} \author{LibTom Projects \\ www.libtom.net}
\maketitle \maketitle
This text and library are all hereby placed in the public domain. This book has been formatted for B5 This text and library are all hereby placed in the public domain. This book has been formatted for B5
[176x250] paper using the \LaTeX{} {\em book} macro package. [176x250] paper using the \LaTeX{} {\em book} macro package.
@ -182,7 +185,7 @@ with 32--bit digits. In this mode fp\_digit is 32--bits and fp\_word is 64--bit
Developers of MIPS and SPARC platforms are encouraged to submit GCC asm inline patches Developers of MIPS and SPARC platforms are encouraged to submit GCC asm inline patches
(see chapter \ref{chap:asmops} for more information). (see chapter \ref{chap:asmops} for more information).
\begin{figure}[here] \begin{figure}[h]
\begin{small} \begin{small}
\begin{center} \begin{center}
\begin{tabular}{|l|l|} \begin{tabular}{|l|l|}

View File

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
#
# we want to filter every between START_INS and END_INS out and then insert crap from another file (this is fun) # we want to filter every between START_INS and END_INS out and then insert crap from another file (this is fun)
#
# SPDX-License-Identifier: Unlicense
$dst = shift; $dst = shift;
$ins = shift; $ins = shift;

2
gen.pl
View File

@ -3,9 +3,11 @@
# Generates a "single file" you can use to quickly # Generates a "single file" you can use to quickly
# add the whole source without any makefile troubles # add the whole source without any makefile troubles
# #
# SPDX-License-Identifier: Unlicense
use strict; use strict;
open( OUT, ">mpi.c" ) or die "Couldn't open mpi.c for writing: $!"; open( OUT, ">mpi.c" ) or die "Couldn't open mpi.c for writing: $!";
print OUT "#define TFM_PRE_GEN_MPI_C\n";
foreach my $filename (glob "src/*/*fp_*.c") { foreach my $filename (glob "src/*/*fp_*.c") {
next if ($filename eq "fp_sqr_comba_generic.c"); next if ($filename eq "fp_sqr_comba_generic.c");
open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!"; open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!";

View File

@ -1,9 +1,6 @@
#!/bin/bash #!/bin/bash
# SPDX-License-Identifier: Unlicense
export a=`find . -type f | sort | grep "[.]/src" | grep "[.]c" | grep -v generators | sed -e 'sE\./EE' | sed -e 's/\.c/\.o/' | xargs` export a=`find . -type f | sort | grep "[.]/src" | grep "[.]c" | grep -v generators | sed -e 'sE\./EE' | sed -e 's/\.c/\.o/' | xargs`
perl ./parsenames.pl OBJECTS "$a" perl ./parsenames.pl OBJECTS "$a"
export a=`find . -type f | grep [.]/src | grep [.]h | sed -e 'se\./ee' | xargs` export a=`find . -type f | grep [.]/src | grep [.]h | sed -e 'se\./ee' | xargs`
perl ./parsenames.pl HEADERS "$a" perl ./parsenames.pl HEADERS "$a"
# $Source: /cvs/libtom/tomsfastmath/genlist.sh,v $
# $Revision: 1.1 $
# $Date: 2006/12/31 21:31:40 $

View File

@ -16,6 +16,7 @@ fp_gcd
fp_ident fp_ident
fp_invmod fp_invmod
fp_isprime fp_isprime
fp_isprime_ex
fp_lcm fp_lcm
fp_lshd fp_lshd
fp_mod fp_mod

200
makefile
View File

@ -1,25 +1,15 @@
#makefile for TomsFastMath # makefile for TomsFastMath, a fast ISO C bignum library. -- Tom St Denis
# # SPDX-License-Identifier: Unlicense
#
VERSION=0.13.1
CFLAGS += -Wall -W -Wshadow -Isrc/headers ifndef LIBNAME
LIBNAME=libtfm.a
# Compiler and Linker Names
ifndef PREFIX
PREFIX=
endif endif
ifeq ($(CC),cc) INSTALL_CMD = install
CC = $(PREFIX)gcc UNINSTALL_CMD = rm
endif
LD=$(PREFIX)ld
AR=$(PREFIX)ar
RANLIB=$(PREFIX)ranlib
ifndef MAKE
MAKE=make include makefile_include.mk
endif
ifeq ($V,1) ifeq ($V,1)
silent= silent=
@ -27,30 +17,19 @@ else
silent=@ silent=@
endif endif
ifeq ($(COVERAGE),1)
CFLAGS += -fprofile-arcs -ftest-coverage
LDFLAGS += -lgcov
LIB_PRE = -Wl,--whole-archive
LIB_POST = -Wl,--no-whole-archive
endif
%.o: %.c %.o: %.c
ifneq ($V,1) ifneq ($V,1)
@echo " * ${CC} $@" @echo " * ${CC} $@"
endif endif
${silent} ${CC} ${CFLAGS} -c $< -o $@ ${silent} ${CC} ${CFLAGS} -c $< -o $@
ifdef COMPILE_DEBUG
#debug
CFLAGS += -g3
else
ifndef IGNORE_SPEED
CFLAGS += -O3 -funroll-loops
#profiling
#PROF=-pg -g
#CFLAGS += $(PROF)
#speed
CFLAGS += -fomit-frame-pointer
endif
endif
#START_INS #START_INS
OBJECTS=src/addsub/fp_add.o src/addsub/fp_add_d.o src/addsub/fp_addmod.o src/addsub/fp_cmp.o \ OBJECTS=src/addsub/fp_add.o src/addsub/fp_add_d.o src/addsub/fp_addmod.o src/addsub/fp_cmp.o \
src/addsub/fp_cmp_d.o src/addsub/fp_cmp_mag.o src/addsub/fp_sub.o src/addsub/fp_sub_d.o \ src/addsub/fp_cmp_d.o src/addsub/fp_cmp_mag.o src/addsub/fp_sub.o src/addsub/fp_sub_d.o \
@ -82,143 +61,72 @@ HEADERS=src/headers/tfm_private.h $(HEADERS_PUB)
#END_INS #END_INS
ifndef LIBPATH
LIBPATH=/usr/lib
endif
ifndef INCPATH
INCPATH=/usr/include
endif
ifndef INSTALL_GROUP
GROUP=wheel
else
GROUP=$(INSTALL_GROUP)
endif
ifndef INSTALL_USER
USER=root
else
USER=$(INSTALL_USER)
endif
ifndef LIBNAME
LIBNAME=libtfm.a
endif
default: $(LIBNAME)
$(OBJECTS): $(HEADERS) $(OBJECTS): $(HEADERS)
$(LIBNAME): $(OBJECTS) $(LIBNAME): $(OBJECTS)
$(AR) $(ARFLAGS) $@ $(OBJECTS) $(AR) $(ARFLAGS) $@ $(OBJECTS)
$(RANLIB) $@ $(RANLIB) $@
install: $(LIBNAME) install: .common_install
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
install -g $(GROUP) -o $(USER) $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
HEADER_FILES=$(notdir $(HEADERS_PUB)) uninstall: .common_uninstall
uninstall:
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
rm $(HEADER_FILES:%=$(DESTDIR)$(INCPATH)/%)
.PHONY: mtest
mtest: $(LIBNAME)
cd mtest; CC="$(CC)" CFLAGS="$(CFLAGS) -I../" MAKE=${MAKE} ${MAKE} mtest
demo/test.o: CFLAGS+=-Wno-unused-result
.PHONY: test .PHONY: test
test: $(LIBNAME) demo/test.o test: $(LIBNAME) demo/test.o
$(CC) $(CFLAGS) demo/test.o $(LIBNAME) $(PROF) -o test $(CC) $(CFLAGS) demo/test.o $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(PROF) -o test
test_standalone: CFLAGS+=-DTFM_DEMO_TEST_VS_MTEST=0 test_standalone: CFLAGS+=-DTFM_DEMO_TEST_VS_MTEST=0
.PHONY: test_standalone .PHONY: test_standalone
test_standalone: $(LIBNAME) demo/test.o test_standalone: $(LIBNAME) demo/test.o
$(CC) $(CFLAGS) demo/test.o $(LIBNAME) $(PROF) -o test $(CC) $(CFLAGS) demo/test.o $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(PROF) -o test
testme: test mtest
./mtest/mtest -15 | ./test
timing: $(LIBNAME) demo/timing.o timing: $(LIBNAME) demo/timing.o
$(CC) $(CFLAGS) demo/timing.o $(LIBNAME) $(PROF) -o timing $(CC) $(CFLAGS) demo/timing.o $(LIBNAME) $(PROF) -o timing
profiled: profiled:
CC="$(CC)" PREFIX="${PREFIX} CFLAGS="${CFLAGS} -fprofile-generate" MAKE=${MAKE} ${MAKE} timing CC="$(CC)" CROSS_COMPILE="${CROSS_COMPILE} CFLAGS="${CFLAGS} -fprofile-generate" MAKE=${MAKE} ${MAKE} timing
./test ./test
rm -f `find . -type f -name "*.o" | xargs` rm -f `find . -type f -name "*.o" | xargs`
rm -f `find . -type f -name "*.a" | xargs` rm -f `find . -type f -name "*.a" | xargs`
rm -f test rm -f test
CC=$(CC) PREFIX="${PREFIX} CFLAGS="${CFLAGS} -fprofile-use" MAKE=${MAKE} ${MAKE} timing CC=$(CC) CROSS_COMPILE="${CROSS_COMPILE} CFLAGS="${CFLAGS} -fprofile-use" MAKE=${MAKE} ${MAKE} timing
# target that pre-processes all coverage data
lcov-single-create:
lcov --capture --no-external --directory src -q --output-file coverage_std.info
# target that removes all coverage output
cleancov-clean:
rm -f `find . -type f -name "*.info" | xargs`
rm -rf coverage/
# generates html output from all coverage_*.info files
lcov:
lcov `find -name 'coverage_*.info' -exec echo -n " -a {}" \;` -o coverage.info -q 2>/dev/null
genhtml coverage.info --output-directory coverage -q
# combines all necessary steps to create the coverage from a single testrun with e.g.
lcov-single:
$(MAKE) cleancov-clean
$(MAKE) lcov-single-create
$(MAKE) lcov
#make the code coverage of the library
coverage: CFLAGS += -fprofile-arcs -ftest-coverage
coverage: LDFLAGS += -lgcov
coverage: LIB_PRE = -Wl,--whole-archive
coverage: LIB_POST = -Wl,--no-whole-archive
coverage: testme
$(MAKE) lcov-single
stest: $(LIBNAME) demo/stest.o stest: $(LIBNAME) demo/stest.o
$(CC) $(CFLAGS) demo/stest.o $(LIBNAME) -o stest $(CC) $(CFLAGS) demo/stest.o $(LIBNAME) -o stest
rsatest: $(LIBNAME) demo/rsa.o rsatest: $(LIBNAME) demo/rsa.o
$(CC) $(CFLAGS) demo/rsa.o $(LIBNAME) -o rsatest $(CC) $(CFLAGS) demo/rsa.o $(LIBNAME) -o rsatest
docdvi: tfm.tex
cp tfm.tex tfm.bak
touch --reference=tfm.tex tfm.bak
(printf "%s" "\def\fixedpdfdate{"; date +'D:%Y%m%d%H%M%S%:z' -d @$$(stat --format=%Y tfm.tex) | sed "s/:\([0-9][0-9]\)$$/'\1'}/g") > tfm-deterministic.tex
printf "%s\n" "\pdfinfo{" >> tfm-deterministic.tex
printf "%s\n" " /CreationDate (\fixedpdfdate)" >> tfm-deterministic.tex
printf "%s\n}\n" " /ModDate (\fixedpdfdate)" >> tfm-deterministic.tex
cat tfm.tex >> tfm-deterministic.tex
mv tfm-deterministic.tex tfm.tex
touch --reference=tfm.bak tfm.tex
touch tfm.ind
latex tfm >/dev/null
latex tfm >/dev/null
makeindex tfm
latex tfm >/dev/null
docs: docdvi
latex tfm >/dev/null
pdflatex tfm >/dev/null
sed -b -i 's,^/ID \[.*\]$$,/ID [<0> <0>],g' tfm.pdf
mv tfm.bak tfm.tex
mv -f tfm.pdf doc
#This rule cleans the source tree of all compiled code, not including the pdf
#documentation.
clean:
rm -f `find . -type f -name "*.o" | xargs`
rm -f `find . -type f -name "*.lo" | xargs`
rm -f `find . -type f -name "*.a" | xargs`
rm -f `find . -type f -name "*.la" | xargs`
rm -f `find . -type f -name "*.obj" | xargs`
rm -f `find . -type f -name "*.lib" | xargs`
rm -f `find . -type f -name "*.exe" | xargs`
rm -f `find . -type f -name "*.gcov" | xargs`
rm -f `find . -type f -name "*.gcda" | xargs`
rm -f `find . -type f -name "*.gcno" | xargs`
rm -f `find . -type f -name "*.il" | xargs`
rm -f `find . -type f -name "*.dyn" | xargs`
rm -f `find . -type f -name "*.dpi" | xargs`
rm -rf `find . -type d -name "*.libs" | xargs`
rm -f tfm.aux tfm.dvi tfm.idx tfm.ilg tfm.ind tfm.lof tfm.log tfm.out tfm.toc test test.exe
cd mtest; MAKE=${MAKE} ${MAKE} clean
.PHONY: pre_gen
pre_gen:
perl gen.pl
sed -e 's/[[:blank:]]*$$//' mpi.c > pre_gen/mpi.c
rm mpi.c
zipup:
rm -rf ../tomsfastmath-$(VERSION) && rm -f ../tfm-$(VERSION).zip ../tfm-$(VERSION).tar.bz2 && \
expsrc.sh -i . -o ../tomsfastmath-$(VERSION) --svntags --no-fetch -p '*.c' -p '*.h' && \
MAKE=${MAKE} ${MAKE} -C ../tomsfastmath-$(VERSION) docs && \
tar -c ../tomsfastmath-$(VERSION)/* | xz -cz > ../tfm-$(VERSION).tar.xz && \
find ../tomsfastmath-$(VERSION)/ -type f -exec unix2dos -q {} \; && \
zip -9 -r ../tfm-$(VERSION).zip ../tomsfastmath-$(VERSION)/* && \
gpg -b -a ../tfm-$(VERSION).tar.xz && gpg -b -a ../tfm-$(VERSION).zip
new_file:
bash updatemakes.sh
# $Source$
# $Revision$
# $Date$

View File

@ -1,25 +1,18 @@
#makefile for TomsFastMath # makefile for TomsFastMath, a fast ISO C bignum library. -- Tom St Denis
# # SPDX-License-Identifier: Unlicense
#
VERSION=1:0:0 ifndef LIBNAME
LIBNAME=libtfm.la
endif
LT ?= libtool LT ?= libtool
LTCOMPILE = $(LT) --mode=compile --tag=CC $(CC) LTCOMPILE = $(LT) --mode=compile --tag=CC $(CC)
CFLAGS += -Wall -W -Wshadow -Isrc/headers INSTALL_CMD = $(LT) --mode=install install
UNINSTALL_CMD = $(LT) --mode=uninstall rm
ifndef IGNORE_SPEED
CFLAGS += -O3 -funroll-all-loops include makefile_include.mk
#profiling
#PROF=-pg -g
#CFLAGS += $(PROF)
#speed
CFLAGS += -fomit-frame-pointer
endif
#START_INS #START_INS
OBJECTS=src/addsub/fp_add.o src/addsub/fp_add_d.o src/addsub/fp_addmod.o src/addsub/fp_cmp.o \ OBJECTS=src/addsub/fp_add.o src/addsub/fp_add_d.o src/addsub/fp_addmod.o src/addsub/fp_cmp.o \
@ -47,65 +40,29 @@ src/sqr/fp_sqr_comba_48.o src/sqr/fp_sqr_comba_4.o src/sqr/fp_sqr_comba_64.o src
src/sqr/fp_sqr_comba_7.o src/sqr/fp_sqr_comba_8.o src/sqr/fp_sqr_comba_9.o src/sqr/fp_sqr_comba.o \ src/sqr/fp_sqr_comba_7.o src/sqr/fp_sqr_comba_8.o src/sqr/fp_sqr_comba_9.o src/sqr/fp_sqr_comba.o \
src/sqr/fp_sqr_comba_generic.o src/sqr/fp_sqr_comba_small_set.o src/sqr/fp_sqrmod.o src/sqr/fp_sqr_comba_generic.o src/sqr/fp_sqr_comba_small_set.o src/sqr/fp_sqrmod.o
LOBJECTS = $(OBJECTS:.o=.lo)
HEADERS_PUB:=src/headers/tfm.h HEADERS_PUB:=src/headers/tfm.h
HEADERS=src/headers/tfm_private.h $(HEADERS_PUB) HEADERS=src/headers/tfm_private.h $(HEADERS_PUB)
#END_INS #END_INS
ifndef LIBPATH
LIBPATH=/usr/lib
endif
ifndef INCPATH
INCPATH=/usr/include
endif
ifndef INSTALL_GROUP
GROUP=wheel
else
GROUP=$(INSTALL_GROUP)
endif
ifndef INSTALL_USER
USER=root
else
USER=$(INSTALL_USER)
endif
ifndef LIBNAME
LIBNAME=libtfm.la
endif
ifndef LIBNAME_S
LIBNAME_S=libtfm.a
endif
default: $(LIBNAME)
$(OBJECTS): $(HEADERS) $(OBJECTS): $(HEADERS)
.c.o: .c.o:
$(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $< $(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
$(LIBNAME): $(OBJECTS) $(LIBNAME): $(OBJECTS)
libtool --mode=link --tag=CC $(CC) $(CFLAGS) $(LDFLAGS) `find . -type f | LC_ALL=C sort | grep "[.]lo" | xargs` -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION) -export-symbols libtfm.symbols $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(LDFLAGS) $(LOBJECTS) -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION_LIB) -export-symbols libtfm.symbols
install: $(LIBNAME) install: .common_install
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH) sed -e 's,^Version:.*,Version: $(VERSION_PC),' tomsfastmath.pc.in > tomsfastmath.pc
libtool --mode=install install -c $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME) install -d $(DESTDIR)$(LIBPATH)/pkgconfig
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH) install -m 644 tomsfastmath.pc $(DESTDIR)$(LIBPATH)/pkgconfig/
install -g $(GROUP) -o $(USER) $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
HEADER_FILES=$(notdir $(HEADERS_PUB)) uninstall: .common_uninstall
uninstall: rm $(DESTDIR)$(LIBPATH)/pkgconfig/tomsfastmath.pc
libtool --mode=uninstall rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
rm $(HEADER_FILES:%=$(DESTDIR)$(INCPATH)/%)
mtest/mtest: mtest/mtest.c
cd mtest ; make mtest
demo/test.o: CFLAGS+=-Wno-unused-result
.PHONY: test .PHONY: test
test: $(LIBNAME) demo/test.o test: $(LIBNAME) demo/test.o
@ -123,8 +80,3 @@ stest: $(LIBNAME) demo/stest.o
.PHONY: timing .PHONY: timing
timing: $(LIBNAME) demo/timing.o timing: $(LIBNAME) demo/timing.o
$(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o timing demo/timing.o $(LIBNAME) $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o timing demo/timing.o $(LIBNAME)
# $Source$
# $Revision$
# $Date$

165
makefile_include.mk Normal file
View File

@ -0,0 +1,165 @@
#
# Include makefile used by makefile + makefile.shared
# (GNU make only)
# SPDX-License-Identifier: Unlicense
ifndef INSTALL_CMD
$(error your makefile must define INSTALL_CMD)
endif
ifndef UNINSTALL_CMD
$(error your makefile must define UNINSTALL_CMD)
endif
#
# The Version of the library
#
VERSION=0.13.1-next
VERSION_LIB=1:0:0
VERSION_PC=0.13.1
GIT_VERSION := $(shell [ -e .git ] && { printf git- ; git describe --tags --always --dirty ; } || echo $(VERSION))
ifneq ($(GIT_VERSION),)
CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
endif
# Compiler and Linker Names
ifndef CROSS_COMPILE
CROSS_COMPILE:=
endif
ifeq ($(CC),cc)
CC := $(CROSS_COMPILE)gcc
endif
LD:=$(CROSS_COMPILE)ld
AR:=$(CROSS_COMPILE)ar
RANLIB=$(CROSS_COMPILE)ranlib
ifndef MAKE
MAKE=make
endif
#
# Compilation flags
#
# Note that we're extending the environments' CFLAGS.
# If you think that our CFLAGS are not nice you can easily override them
# by giving them as a parameter to make:
# make CFLAGS="-I./src/headers/ -DLTC_SOURCE ..." ...
#
CFLAGS += -Wall -W -Wshadow -Isrc/headers
ifdef COMPILE_DEBUG
#debug
CFLAGS += -g3
else
ifndef IGNORE_SPEED
CFLAGS += -O3
PLATFORM := $(shell uname | sed -e 's/_.*//')
ifneq ($(PLATFORM), Darwin)
CFLAGS += -funroll-loops
endif
#profiling
#PROF=-pg -g
#CFLAGS += $(PROF)
#speed
CFLAGS += -fomit-frame-pointer
endif
endif
#
# (Un)Install related variables
#
DESTDIR ?=
PREFIX ?= /usr/local
LIBPATH ?= $(PREFIX)/lib
INCPATH ?= $(PREFIX)/include
#
# Build targets
#
default: $(LIBNAME)
demo/test.o: CFLAGS+=-Wno-unused-result
.PHONY: mtest
mtest: $(LIBNAME)
CC="$(CC)" CFLAGS="$(CFLAGS) -I../" MAKE=${MAKE} ${MAKE} -C mtest/ mtest
.common_install: $(LIBNAME)
install -d $(DESTDIR)$(LIBPATH)
$(INSTALL_CMD) $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME)
install -d $(DESTDIR)$(INCPATH)
install $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
HEADER_FILES=$(notdir $(HEADERS_PUB))
.common_uninstall:
$(UNINSTALL_CMD) $(DESTDIR)$(LIBPATH)/$(LIBNAME)
rm $(HEADER_FILES:%=$(DESTDIR)$(INCPATH)/%)
#This rule cleans the source tree of all compiled code, not including the pdf
#documentation.
clean:
find . -type f -name "*.o" \
-o -name "*.lo" \
-o -name "*.a" \
-o -name "*.la" \
-o -name "*.obj" \
-o -name "*.lib" \
-o -name "*.exe" \
-o -name "*.dll" \
-o -name "*.so" \
-o -name "*.gcov"\
-o -name "*.gcda"\
-o -name "*.gcno"\
-o -name "*.il" \
-o -name "*.dyn" \
-o -name "*.dpi" | xargs rm -f
find . -type d -name "*.libs" | xargs rm -rf
rm -f tfm.aux tfm.dvi tfm.idx tfm.ilg tfm.ind tfm.lof tfm.log tfm.out tfm.toc test test.exe
cd mtest; MAKE=${MAKE} ${MAKE} clean
docs:
$(MAKE) -C doc/ $@ V=$(V)
doc/tfm.pdf:
$(MAKE) -C doc/ tfm.pdf V=$(V)
pre_gen:
mkdir -p pre_gen
perl gen.pl
sed -e 's/[[:blank:]]*$$//' mpi.c > pre_gen/mpi.c
rm mpi.c
zipup: doc/tfm.pdf
@# Update the index, so diff-index won't fail in case the pdf has been created.
@# As the pdf creation modifies tfm.tex, git sometimes detects the
@# modified file, but misses that it's put back to its original version.
@git update-index --refresh
@git diff-index --quiet HEAD -- || ( echo "FAILURE: uncommited changes or not a git" && exit 1 )
rm -rf tomsfastmath-$(VERSION) tfm-$(VERSION).*
@# files/dirs excluded from "git archive" are defined in .gitattributes
git archive --format=tar --prefix=tomsfastmath-$(VERSION)/ HEAD | tar x
mkdir -p tomsfastmath-$(VERSION)/doc
cp doc/tfm.pdf tomsfastmath-$(VERSION)/doc/tfm.pdf
$(MAKE) -C tomsfastmath-$(VERSION)/ pre_gen
tar -c tomsfastmath-$(VERSION)/ | xz -6e -c - > tfm-$(VERSION).tar.xz
zip -9rq tfm-$(VERSION).zip tomsfastmath-$(VERSION)
rm -rf tomsfastmath-$(VERSION)
gpg -b -a tfm-$(VERSION).tar.xz
gpg -b -a tfm-$(VERSION).zip
new_file:
bash updatemakes.sh
.PHONY: pre_gen doc/tfm.pdf

View File

@ -1,4 +0,0 @@
#!/bin/bash
if cvs log $1 >/dev/null 2>/dev/null; then exit 0; else echo "$1 shouldn't be here" ; exit 1; fi

View File

@ -1,3 +1,6 @@
# TomsFastMath, a fast ISO C bignum library. -- Tom St Denis
# SPDX-License-Identifier: Unlicense
CFLAGS += -Wall -W -O3 -Wno-unused-result CFLAGS += -Wall -W -O3 -Wno-unused-result
default: mtest default: mtest

View File

@ -27,6 +27,7 @@ mulmod
1 1
*/ */
/* SPDX-License-Identifier: Unlicense */
#ifdef MP_8BIT #ifdef MP_8BIT
#define THE_MASK 127 #define THE_MASK 127
@ -38,42 +39,70 @@ mulmod
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <tommath.h> #include <tommath.h>
#define CRYPT
#undef DIGIT_BIT #undef DIGIT_BIT
#include "../src/headers/tfm.h" #include "../src/headers/tfm.h"
#ifdef TFM_MTEST_REAL_RAND
#define getRandChar() fgetc(rng)
FILE *rng; FILE *rng;
#else
#define getRandChar() (rand()&0xFF)
#endif
/* 1-2048 bit numbers */
void rand_num(mp_int *a) void rand_num(mp_int *a)
{ {
int size; int size;
unsigned char buf[(FP_MAX_SIZE/16 - DIGIT_BIT/2) + 1]; unsigned char buf[2048];
size_t sz;
size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % (FP_MAX_SIZE/16 - DIGIT_BIT/2); size = 1 + ((getRandChar()<<8) + getRandChar()) % 101;
buf[0] = (fgetc(rng)&1)?1:0; buf[0] = (getRandChar()&1)?1:0;
fread(buf+1, 1, size, rng); #ifdef TFM_MTEST_REAL_RAND
while (buf[1] == 0) buf[1] = fgetc(rng); sz = fread(buf+1, 1, size, rng);
#else
sz = 1;
while (sz < (unsigned)size) {
buf[sz] = getRandChar();
++sz;
}
#endif
if (sz != (unsigned)size) {
fprintf(stderr, "\nWarning: fread failed\n\n");
}
while (buf[1] == 0) buf[1] = getRandChar();
mp_read_raw(a, buf, 1+size); mp_read_raw(a, buf, 1+size);
} }
/* 1-256 bit numbers (to test things like exptmod) */
void rand_num2(mp_int *a) void rand_num2(mp_int *a)
{ {
int size; int size;
unsigned char buf[(FP_MAX_SIZE/16 - DIGIT_BIT/2) + 1]; unsigned char buf[2048];
size_t sz;
size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % (FP_MAX_SIZE/16 - DIGIT_BIT/2); size = 10 + ((getRandChar()<<8) + getRandChar()) % 101;
buf[0] = (fgetc(rng)&1)?1:0; buf[0] = (getRandChar()&1)?1:0;
fread(buf+1, 1, size, rng); #ifdef TFM_MTEST_REAL_RAND
while (buf[1] == 0) buf[1] = fgetc(rng); sz = fread(buf+1, 1, size, rng);
#else
sz = 1;
while (sz < (unsigned)size) {
buf[sz] = getRandChar();
++sz;
}
#endif
if (sz != (unsigned)size) {
fprintf(stderr, "\nWarning: fread failed\n\n");
}
while (buf[1] == 0) buf[1] = getRandChar();
mp_read_raw(a, buf, 1+size); mp_read_raw(a, buf, 1+size);
} }
#define mp_to64(a, b) mp_toradix_n(a, b, 64, sizeof(b)) #define mp_to64(a, b) mp_toradix_n(a, b, 64, sizeof(b))
int main(void) int main(int argc, char *argv[])
{ {
long long max;
int n, tmp; int n, tmp;
mp_int a, b, c, d, e; mp_int a, b, c, d, e;
#ifdef MTEST_NO_FULLSPEED #ifdef MTEST_NO_FULLSPEED
@ -88,6 +117,27 @@ int main(void)
mp_init(&e); mp_init(&e);
if (argc > 1) {
max = strtol(argv[1], NULL, 0);
printf("%lld\n", max);
if (max < 0) {
max = -max;
printf("%lld\n", max);
if (max < 64) {
unsigned long long m = (1ULL << (max)) + 1;
max = (long long)m;
} else {
max = 1;
}
printf("%lld\n", max);
} else if (max == 0) {
max = 1;
}
}
else {
max = 0;
}
/* initial (2^n - 1)^2 testing, makes sure the comba multiplier works [it has the new carry code] */ /* initial (2^n - 1)^2 testing, makes sure the comba multiplier works [it has the new carry code] */
/* /*
mp_set(&a, 1); mp_set(&a, 1);
@ -105,6 +155,7 @@ int main(void)
} }
*/ */
#ifdef TFM_MTEST_REAL_RAND
rng = fopen("/dev/urandom", "rb"); rng = fopen("/dev/urandom", "rb");
if (rng == NULL) { if (rng == NULL) {
rng = fopen("/dev/random", "rb"); rng = fopen("/dev/random", "rb");
@ -113,6 +164,9 @@ int main(void)
rng = stdin; rng = stdin;
} }
} }
#else
srand(23);
#endif
#ifdef MTEST_NO_FULLSPEED #ifdef MTEST_NO_FULLSPEED
t1 = clock(); t1 = clock();
@ -124,7 +178,12 @@ int main(void)
t1 = clock(); t1 = clock();
} }
#endif #endif
n = fgetc(rng) % 16; n = getRandChar() % 16;
if (max != 0) {
--max;
if (max == 0)
n = 255;
}
if (n == 0) { if (n == 0) {
/* add tests */ /* add tests */
rand_num(&a); rand_num(&a);
@ -188,7 +247,7 @@ int main(void)
/* mul_2d test */ /* mul_2d test */
rand_num(&a); rand_num(&a);
mp_copy(&a, &b); mp_copy(&a, &b);
n = fgetc(rng) & 63; n = getRandChar() & 63;
mp_mul_2d(&b, n, &b); mp_mul_2d(&b, n, &b);
mp_to64(&a, buf); mp_to64(&a, buf);
printf("mul2d\n"); printf("mul2d\n");
@ -200,7 +259,7 @@ int main(void)
/* div_2d test */ /* div_2d test */
rand_num(&a); rand_num(&a);
mp_copy(&a, &b); mp_copy(&a, &b);
n = fgetc(rng) & 63; n = getRandChar() & 63;
mp_div_2d(&b, n, &b, NULL); mp_div_2d(&b, n, &b, NULL);
mp_to64(&a, buf); mp_to64(&a, buf);
printf("div2d\n"); printf("div2d\n");
@ -258,14 +317,14 @@ int main(void)
printf("%s\n", buf); printf("%s\n", buf);
} else if (n == 10) { } else if (n == 10) {
/* invmod test */ /* invmod test */
do {
rand_num2(&a); rand_num2(&a);
rand_num2(&b); rand_num2(&b);
b.dp[0] |= 1; b.dp[0] |= 1;
b.sign = MP_ZPOS; b.sign = MP_ZPOS;
a.sign = MP_ZPOS; a.sign = MP_ZPOS;
mp_gcd(&a, &b, &c); mp_gcd(&a, &b, &c);
if (mp_cmp_d(&c, 1) != 0) continue; } while (mp_cmp_d(&c, 1) != 0 || mp_cmp_d(&b, 1) == 0);
if (mp_cmp_d(&b, 1) == 0) continue;
mp_invmod(&a, &b, &c); mp_invmod(&a, &b, &c);
printf("invmod\n"); printf("invmod\n");
mp_to64(&a, buf); mp_to64(&a, buf);
@ -318,12 +377,13 @@ int main(void)
printf("%s\n%d\n", buf, tmp); printf("%s\n%d\n", buf, tmp);
mp_to64(&b, buf); mp_to64(&b, buf);
printf("%s\n", buf); printf("%s\n", buf);
} else if (n == 255) {
printf("exit\n");
break;
} }
} }
#ifdef TFM_MTEST_REAL_RAND
fclose(rng); fclose(rng);
#endif
return 0; return 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -4,6 +4,7 @@
# wrapped at 80 chars # wrapped at 80 chars
# #
# Tom St Denis # Tom St Denis
# SPDX-License-Identifier: Unlicense
@a = split(" ", $ARGV[1]); @a = split(" ", $ARGV[1]);
$b = "$ARGV[0]="; $b = "$ARGV[0]=";
$len = length($b); $len = length($b);
@ -20,7 +21,3 @@ foreach my $obj (@a) {
#if ($ARGV[0] eq "HEADERS") { print "testprof/tomcrypt_test.h"; } #if ($ARGV[0] eq "HEADERS") { print "testprof/tomcrypt_test.h"; }
print "\n\n"; print "\n\n";
# $Source: /cvs/libtom/tomsfastmath/parsenames.pl,v $
# $Revision: 1.1 $
# $Date: 2006/12/31 21:31:40 $

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_add(fp_int *a, fp_int *b, fp_int *c) void fp_add(fp_int *a, fp_int *b, fp_int *c)
@ -37,7 +30,3 @@ void fp_add(fp_int *a, fp_int *b, fp_int *c)
} }
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a + b */ /* c = a + b */
@ -16,7 +9,3 @@ void fp_add_d(fp_int *a, fp_digit b, fp_int *c)
fp_set(&tmp, b); fp_set(&tmp, b);
fp_add(a,&tmp,c); fp_add(a,&tmp,c);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* d = a + b (mod c) */ /* d = a + b (mod c) */
@ -17,7 +10,3 @@ int fp_addmod(fp_int *a, fp_int *b, fp_int *c, fp_int *d)
fp_add(a, b, &tmp); fp_add(a, b, &tmp);
return fp_mod(&tmp, c, d); return fp_mod(&tmp, c, d);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_cmp(fp_int *a, fp_int *b) int fp_cmp(fp_int *a, fp_int *b)
@ -25,7 +18,3 @@ int fp_cmp(fp_int *a, fp_int *b)
} }
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* compare against a single digit */ /* compare against a single digit */
@ -32,7 +25,3 @@ int fp_cmp_d(fp_int *a, fp_digit b)
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_cmp_mag(fp_int *a, fp_int *b) int fp_cmp_mag(fp_int *a, fp_int *b)
@ -28,8 +21,3 @@ int fp_cmp_mag(fp_int *a, fp_int *b)
} }
return FP_EQ; return FP_EQ;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a - b */ /* c = a - b */
@ -43,8 +36,3 @@ void fp_sub(fp_int *a, fp_int *b, fp_int *c)
} }
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a - b */ /* c = a - b */
@ -16,7 +9,3 @@ void fp_sub_d(fp_int *a, fp_digit b, fp_int *c)
fp_set(&tmp, b); fp_set(&tmp, b);
fp_sub(a, &tmp, c); fp_sub(a, &tmp, c);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* d = a - b (mod c) */ /* d = a - b (mod c) */
@ -17,8 +10,3 @@ int fp_submod(fp_int *a, fp_int *b, fp_int *c, fp_int *d)
fp_sub(a, b, &tmp); fp_sub(a, b, &tmp);
return fp_mod(&tmp, c, d); return fp_mod(&tmp, c, d);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* unsigned addition */ /* unsigned addition */
@ -36,7 +29,3 @@ void s_fp_add(fp_int *a, fp_int *b, fp_int *c)
} }
fp_clamp(c); fp_clamp(c);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* unsigned subtraction ||a|| >= ||b|| ALWAYS! */ /* unsigned subtraction ||a|| >= ||b|| ALWAYS! */
@ -34,7 +27,3 @@ void s_fp_sub(fp_int *a, fp_int *b, fp_int *c)
} }
fp_clamp(c); fp_clamp(c);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_radix_size(fp_int *a, int radix, int *size) int fp_radix_size(fp_int *a, int radix, int *size)
@ -45,7 +38,3 @@ int fp_radix_size(fp_int *a, int radix, int *size)
return FP_OKAY; return FP_OKAY;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_read_radix(fp_int *a, const char *str, int radix) int fp_read_radix(fp_int *a, const char *str, int radix)
@ -64,7 +57,3 @@ int fp_read_radix(fp_int *a, const char *str, int radix)
} }
return FP_OKAY; return FP_OKAY;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_read_signed_bin(fp_int *a, const unsigned char *b, int c) void fp_read_signed_bin(fp_int *a, const unsigned char *b, int c)
@ -21,7 +14,3 @@ void fp_read_signed_bin(fp_int *a, const unsigned char *b, int c)
a->sign = FP_NEG; a->sign = FP_NEG;
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c) void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
@ -14,6 +7,12 @@ void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
/* zero the int */ /* zero the int */
fp_zero (a); fp_zero (a);
if ((unsigned)c > (FP_SIZE * sizeof(fp_digit))) {
int excess = c - (FP_SIZE * sizeof(fp_digit));
c -= excess;
b += excess;
}
/* If we know the endianness of this architecture, and we're using /* If we know the endianness of this architecture, and we're using
32-bit fp_digits, we can optimize this */ 32-bit fp_digits, we can optimize this */
#if (defined(ENDIAN_LITTLE) || defined(ENDIAN_BIG)) && !defined(FP_64BIT) #if (defined(ENDIAN_LITTLE) || defined(ENDIAN_BIG)) && !defined(FP_64BIT)
@ -24,11 +23,6 @@ void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
{ {
unsigned char *pd = (unsigned char *)a->dp; unsigned char *pd = (unsigned char *)a->dp;
if ((unsigned)c > (FP_SIZE * sizeof(fp_digit))) {
int excess = c - (FP_SIZE * sizeof(fp_digit));
c -= excess;
b += excess;
}
a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit); a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit);
/* read the bytes in */ /* read the bytes in */
#ifdef ENDIAN_BIG #ifdef ENDIAN_BIG
@ -55,12 +49,11 @@ void fp_read_unsigned_bin(fp_int *a, const unsigned char *b, int c)
for (; c > 0; c--) { for (; c > 0; c--) {
fp_mul_2d (a, 8, a); fp_mul_2d (a, 8, a);
a->dp[0] |= *b++; a->dp[0] |= *b++;
a->used += 1;
if (a->used == 0) {
a->used = 1;
}
} }
#endif #endif
fp_clamp (a); fp_clamp (a);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* reverse an array, used for radix code */ /* reverse an array, used for radix code */
@ -25,7 +18,3 @@ void fp_reverse (unsigned char *s, int len)
--iy; --iy;
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,17 +1,6 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* chars used in radix conversions */ /* chars used in radix conversions */
const char *fp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; const char *fp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,19 +1,8 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_signed_bin_size(fp_int *a) int fp_signed_bin_size(fp_int *a)
{ {
return 1 + fp_unsigned_bin_size (a); return 1 + fp_unsigned_bin_size (a);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_to_signed_bin(fp_int *a, unsigned char *b) void fp_to_signed_bin(fp_int *a, unsigned char *b)
@ -14,7 +7,3 @@ void fp_to_signed_bin(fp_int *a, unsigned char *b)
fp_to_unsigned_bin (a, b + 1); fp_to_unsigned_bin (a, b + 1);
b[0] = (unsigned char) ((a->sign == FP_ZPOS) ? 0 : 1); b[0] = (unsigned char) ((a->sign == FP_ZPOS) ? 0 : 1);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_to_unsigned_bin(fp_int *a, unsigned char *b) void fp_to_unsigned_bin(fp_int *a, unsigned char *b)
@ -23,7 +16,3 @@ void fp_to_unsigned_bin(fp_int *a, unsigned char *b)
} }
fp_reverse (b, x); fp_reverse (b, x);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/** /**
@ -25,7 +18,3 @@ int fp_toradix(fp_int *a, char *str, int radix)
{ {
return fp_toradix_n(a, str, radix, INT_MAX); return fp_toradix_n(a, str, radix, INT_MAX);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,19 +1,12 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen) int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen)
{ {
int digs; int digs;
fp_int t; fp_int t;
fp_digit d; fp_digit d = 0;
char *_s = str; char *_s = str;
/* check range of the radix */ /* check range of the radix */
@ -65,7 +58,3 @@ int fp_toradix_n(fp_int *a, char *str, int radix, int maxlen)
return FP_VAL; return FP_VAL;
return FP_OKAY; return FP_OKAY;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_unsigned_bin_size(fp_int *a) int fp_unsigned_bin_size(fp_int *a)
@ -14,7 +7,3 @@ int fp_unsigned_bin_size(fp_int *a)
int size = fp_count_bits (a); int size = fp_count_bits (a);
return (size / 8 + ((size & 7) != 0 ? 1 : 0)); return (size / 8 + ((size & 7) != 0 ? 1 : 0));
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
static const int lnz[16] = { static const int lnz[16] = {
@ -39,8 +32,3 @@ int fp_cnt_lsb(fp_int *a)
} }
return x; return x;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
int fp_count_bits (fp_int * a) int fp_count_bits (fp_int * a)
@ -30,7 +23,3 @@ int fp_count_bits (fp_int * a)
} }
return r; return r;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* b = a/2 */ /* b = a/2 */
@ -47,7 +40,3 @@ void fp_div_2(fp_int * a, fp_int * b)
b->sign = a->sign; b->sign = a->sign;
fp_clamp (b); fp_clamp (b);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a / 2**b */ /* c = a / 2**b */
@ -73,7 +66,3 @@ void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d)
fp_copy (&t, d); fp_copy (&t, d);
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_lshd(fp_int *a, int x) void fp_lshd(fp_int *a, int x)
@ -32,7 +25,3 @@ void fp_lshd(fp_int *a, int x)
/* clamp digits */ /* clamp digits */
fp_clamp(a); fp_clamp(a);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a mod 2**d */ /* c = a mod 2**d */
@ -36,7 +29,3 @@ void fp_mod_2d(fp_int *a, int b, fp_int *c)
c->dp[b / DIGIT_BIT] &= ~((fp_digit)0) >> (DIGIT_BIT - b); c->dp[b / DIGIT_BIT] &= ~((fp_digit)0) >> (DIGIT_BIT - b);
fp_clamp (c); fp_clamp (c);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_rshd(fp_int *a, int x) void fp_rshd(fp_int *a, int x)
@ -33,8 +26,3 @@ void fp_rshd(fp_int *a, int x)
a->used -= x; a->used -= x;
fp_clamp(a); fp_clamp(a);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* a/b => cb + d == a */ /* a/b => cb + d == a */
@ -151,7 +144,3 @@ int fp_div(fp_int *a, fp_int *b, fp_int *c, fp_int *d)
return FP_OKAY; return FP_OKAY;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
static int s_is_power_of_two(fp_digit b, int *p) static int s_is_power_of_two(fp_digit b, int *p)
@ -91,8 +84,3 @@ int fp_div_d(fp_int *a, fp_digit b, fp_int *c, fp_digit *d)
return FP_OKAY; return FP_OKAY;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a mod b, 0 <= c < b */ /* c = a mod b, 0 <= c < b */
@ -26,9 +19,3 @@ int fp_mod(fp_int *a, fp_int *b, fp_int *c)
} }
return FP_OKAY; return FP_OKAY;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a mod b, 0 <= c < b */ /* c = a mod b, 0 <= c < b */
@ -14,7 +7,3 @@ int fp_mod_d(fp_int *a, fp_digit b, fp_digit *c)
{ {
return fp_div_d(a, b, NULL, c); return fp_div_d(a, b, NULL, c);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* computes a = 2**b */ /* computes a = 2**b */
@ -32,8 +25,3 @@ void fp_2expt(fp_int *a, int b)
/* put the single bit in its place */ /* put the single bit in its place */
a->dp[z] = ((fp_digit)1) << (b % DIGIT_BIT); a->dp[z] = ((fp_digit)1) << (b % DIGIT_BIT);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
#ifdef TFM_TIMING_RESISTANT #ifdef TFM_TIMING_RESISTANT
@ -270,7 +263,3 @@ int fp_exptmod(fp_int * G, fp_int * X, fp_int * P, fp_int * Y)
return _fp_exptmod(G, X, P, Y); return _fp_exptmod(G, X, P, Y);
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,7 +1,9 @@
comba_mont_gen
comba_mult_gen comba_mult_gen
comba_mult_smallgen comba_mult_smallgen
comba_sqr_gen comba_sqr_gen
comba_sqr_smallgen comba_sqr_smallgen
comba_mont_gen.exe
comba_mult_gen.exe comba_mult_gen.exe
comba_mult_smallgen.exe comba_mult_smallgen.exe
comba_sqr_gen.exe comba_sqr_gen.exe

View File

@ -1,12 +1,19 @@
#include <stdio.h> /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
int main(void) #include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{ {
int x, y, z; int x, y, z, N = 16;
if (argc > 1) N = atoi(argv[1]);
printf( printf(
#if 1 #if 1
"#ifdef TFM_SMALL_SET\n" "/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */\n"
"/* SPDX-License-Identifier: Unlicense */\n"
"#ifdef TFM_SMALL_MONT_SET\n"
"/* computes x/R == x (mod N) via Montgomery Reduction */\n" "/* computes x/R == x (mod N) via Montgomery Reduction */\n"
"void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)\n" "void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)\n"
"{\n" "{\n"
@ -34,7 +41,7 @@ printf(
"\n" "\n"
" switch (pa) {\n"); " switch (pa) {\n");
for (x = 1; x <= 16; x++) { for (x = 1; x <= N; x++) {
if (x > 16 && (x != 32 && x != 48 && x != 64)) continue; if (x > 16 && (x != 32 && x != 48 && x != 64)) continue;
if (x > 16) printf("#ifdef TFM_HUGE\n"); if (x > 16) printf("#ifdef TFM_HUGE\n");

View File

@ -1,15 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
/* program emits a NxN comba multiplier */ /* program emits a NxN comba multiplier */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
@ -18,19 +12,32 @@ int main(int argc, char **argv)
/* print out preamble */ /* print out preamble */
printf( printf(
"/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */\n"
"/* SPDX-License-Identifier: Unlicense */\n"
"#ifndef TFM_PRE_GEN_MPI_C\n"
"#define TFM_DEFINES\n" "#define TFM_DEFINES\n"
"#include \"fp_mul_comba.c\"\n" "#include \"fp_mul_comba.c\"\n"
"#endif\n"
"\n" "\n"
"#if defined(TFM_MUL%d) && FP_SIZE >= %d\n" "#if defined(TFM_MUL%d) && FP_SIZE >= %d\n"
"void fp_mul_comba%d(fp_int *A, fp_int *B, fp_int *C)\n" "void fp_mul_comba%d(fp_int *A, fp_int *B, fp_int *C)\n"
"{\n" "{\n"
" fp_digit c0, c1, c2, at[%d];\n" " fp_digit c0, c1, c2, at[%d];\n", N, N+N, N, N+N);
if (N >= 32) {
printf(
" int out_size;\n"
"\n" "\n"
" out_size = A->used + B->used;\n");
} else {
printf(
"\n");
}
printf(
" memcpy(at, A->dp, %d * sizeof(fp_digit));\n" " memcpy(at, A->dp, %d * sizeof(fp_digit));\n"
" memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\n" " memcpy(at+%d, B->dp, %d * sizeof(fp_digit));\n"
" COMBA_START;\n" " COMBA_START;\n"
"\n" "\n"
" COMBA_CLEAR;\n", N, N+N, N, N+N, N, N, N); " COMBA_CLEAR;\n", N, N, N);
/* now do the rows */ /* now do the rows */
for (x = 0; x < (N+N-1); x++) { for (x = 0; x < (N+N-1); x++) {
@ -50,6 +57,14 @@ printf(
printf( printf(
"\n" "\n"
" COMBA_STORE(C->dp[%d]);\n", x); " COMBA_STORE(C->dp[%d]);\n", x);
if (N >= 32 && N*2 != (x+2) &&(x+2) >= 40 && (x+2)%8 == 0) {
printf(
"\n"
" /* early out at %d digits, %d*32==%d, or two %d bit operands */\n"
" if (out_size <= %d) { COMBA_STORE2(C->dp[%d]); C->used = %d; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }\n"
"\n"
, x+2, x+2, (x+2)*32, (x+2)*16, x+2, x+1, x+2);
}
} }
printf( printf(
" COMBA_STORE2(C->dp[%d]);\n" " COMBA_STORE2(C->dp[%d]);\n"
@ -57,15 +72,8 @@ printf(
" C->sign = A->sign ^ B->sign;\n" " C->sign = A->sign ^ B->sign;\n"
" fp_clamp(C);\n" " fp_clamp(C);\n"
" COMBA_FINI;\n" " COMBA_FINI;\n"
"}\n#endif\n\n\n" "}\n#endif\n"
"/* $Source$ */\n"
"/* $Revision$ */\n"
"/* $Date$ */\n"
, N+N-1, N+N); , N+N-1, N+N);
return 0; return 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,3 +1,6 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
/* program emits a NxN comba multiplier for 1x1 to 16x16 */ /* program emits a NxN comba multiplier for 1x1 to 16x16 */
#include <stdio.h> #include <stdio.h>
@ -7,8 +10,12 @@ int main(int argc, char **argv)
/* print out preamble */ /* print out preamble */
printf( printf(
"/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */\n"
"/* SPDX-License-Identifier: Unlicense */\n"
"#ifndef TFM_PRE_GEN_MPI_C\n"
"#define TFM_DEFINES\n" "#define TFM_DEFINES\n"
"#include \"fp_mul_comba.c\"\n" "#include \"fp_mul_comba.c\"\n"
"#endif\n"
"\n" "\n"
"#if defined(TFM_SMALL_SET)\n" "#if defined(TFM_SMALL_SET)\n"
"void fp_mul_comba_small(fp_int *A, fp_int *B, fp_int *C)\n" "void fp_mul_comba_small(fp_int *A, fp_int *B, fp_int *C)\n"
@ -55,14 +62,7 @@ printf(
" COMBA_FINI;\n" " COMBA_FINI;\n"
" break;\n", N+N-1, N+N); " break;\n", N+N-1, N+N);
} }
printf(" }\n}\n\n#endif\n\n\n" printf(" }\n}\n\n#endif\n");
"/* $Source$ */\n"
"/* $Revision$ */\n"
"/* $Date$ */\n");
return 0; return 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -17,13 +10,24 @@ int main(int argc, char **argv)
N = atoi(argv[1]); N = atoi(argv[1]);
printf( printf(
"/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */\n"
"/* SPDX-License-Identifier: Unlicense */\n"
"#ifndef TFM_PRE_GEN_MPI_C\n"
"#define TFM_DEFINES\n" "#define TFM_DEFINES\n"
"#include \"fp_sqr_comba.c\"\n" "#include \"fp_sqr_comba.c\"\n"
"#endif\n"
"\n" "\n"
"#if defined(TFM_SQR%d) && FP_SIZE >= %d\n" "#if defined(TFM_SQR%d) && FP_SIZE >= %d\n"
"void fp_sqr_comba%d(fp_int *A, fp_int *B)\n" "void fp_sqr_comba%d(fp_int *A, fp_int *B)\n"
"{\n" "{\n"
" fp_digit *a, b[%d], c0, c1, c2, sc0, sc1, sc2;\n" " fp_digit *a, b[%d], c0, c1, c2;\n", N, N+N, N, N+N);
if (N > 4) {
printf(
" fp_digit sc0, sc1, sc2;\n");
}
printf(
"#ifdef TFM_ISO\n" "#ifdef TFM_ISO\n"
" fp_word tt;\n" " fp_word tt;\n"
"#endif\n" "#endif\n"
@ -36,7 +40,7 @@ printf(
"\n" "\n"
" /* output 0 */\n" " /* output 0 */\n"
" SQRADD(a[0],a[0]);\n" " SQRADD(a[0],a[0]);\n"
" COMBA_STORE(b[0]);\n", N, N+N, N, N+N); " COMBA_STORE(b[0]);\n");
for (x = 1; x < N+N-1; x++) { for (x = 1; x < N+N-1; x++) {
printf( printf(
@ -98,15 +102,8 @@ printf(
" B->sign = FP_ZPOS;\n" " B->sign = FP_ZPOS;\n"
" memcpy(B->dp, b, %d * sizeof(fp_digit));\n" " memcpy(B->dp, b, %d * sizeof(fp_digit));\n"
" fp_clamp(B);\n" " fp_clamp(B);\n"
"}\n#endif\n\n\n" "}\n#endif\n"
"/* $Source$ */\n"
"/* $Revision$ */\n"
"/* $Date$ */\n"
, N+N, N+N); , N+N, N+N);
return 0; return 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
/* Generates squaring comba code... it learns it knows our secrets! */ /* Generates squaring comba code... it learns it knows our secrets! */
#include <stdio.h> #include <stdio.h>
@ -16,8 +9,12 @@ int main(int argc, char **argv)
int x, y, z, N, f; int x, y, z, N, f;
printf( printf(
"/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */\n"
"/* SPDX-License-Identifier: Unlicense */\n"
"#ifndef TFM_PRE_GEN_MPI_C\n"
"#define TFM_DEFINES\n" "#define TFM_DEFINES\n"
"#include \"fp_sqr_comba.c\"\n" "#include \"fp_sqr_comba.c\"\n"
"#endif\n"
"\n" "\n"
"#if defined(TFM_SMALL_SET)\n" "#if defined(TFM_SMALL_SET)\n"
"void fp_sqr_comba_small(fp_int *A, fp_int *B)\n" "void fp_sqr_comba_small(fp_int *A, fp_int *B)\n"
@ -106,15 +103,8 @@ printf(
" break;\n\n", N+N, N+N); " break;\n\n", N+N, N+N);
} }
printf("}\n}\n\n#endif /* TFM_SMALL_SET */\n\n" printf("}\n}\n\n#endif /* TFM_SMALL_SET */\n"
"/* $Source$ */\n"
"/* $Revision$ */\n"
"/* $Date$ */\n"
); );
return 0; return 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,6 +1,11 @@
# TomsFastMath, a fast ISO C bignum library. -- Tom St Denis
# SPDX-License-Identifier: Unlicense
all: comba_sqr_gen comba_sqr_smallgen all: comba_sqr_gen comba_sqr_smallgen
clean: clean:
rm -f comba_mont_gen
rm -f comba_mont_gen.exe
rm -f comba_mult_gen rm -f comba_mult_gen
rm -f comba_mult_gen.exe rm -f comba_mult_gen.exe
rm -f comba_mult_smallgen rm -f comba_mult_smallgen
@ -10,6 +15,8 @@ clean:
rm -f comba_sqr_smallgen rm -f comba_sqr_smallgen
rm -f comba_sqr_smallgen.exe rm -f comba_sqr_smallgen.exe
comba_mont_gen: comba_mont_gen.c
gcc -o comba_mont_gen comba_mont_gen.c
comba_mult_gen: comba_mult_gen.c comba_mult_gen: comba_mult_gen.c
gcc -o comba_mult_gen comba_mult_gen.c gcc -o comba_mult_gen comba_mult_gen.c
comba_mult_smallgen: comba_mult_smallgen.c comba_mult_smallgen: comba_mult_smallgen.c
@ -19,7 +26,8 @@ comba_sqr_gen: comba_sqr_gen.c
comba_sqr_smallgen: comba_sqr_smallgen.c comba_sqr_smallgen: comba_sqr_smallgen.c
gcc -o comba_sqr_smallgen comba_sqr_smallgen.c gcc -o comba_sqr_smallgen comba_sqr_smallgen.c
regen: comba_mult_gen comba_mult_smallgen comba_sqr_gen comba_sqr_smallgen regen: comba_mont_gen comba_mult_gen comba_mult_smallgen comba_sqr_gen comba_sqr_smallgen
./comba_mont_gen > ../mont/fp_mont_small.i
for i in 3 4 6 7 8 9 12 17 20 24 28 32 48 64; do \ for i in 3 4 6 7 8 9 12 17 20 24 28 32 48 64; do \
./comba_mult_gen $$i | sed -e 's/ *$$//' > ../mul/fp_mul_comba_$$i.c; \ ./comba_mult_gen $$i | sed -e 's/ *$$//' > ../mul/fp_mul_comba_$$i.c; \
done done
@ -28,4 +36,3 @@ regen: comba_mult_gen comba_mult_smallgen comba_sqr_gen comba_sqr_smallgen
./comba_sqr_gen $$i | sed -e 's/ *$$//' > ../sqr/fp_sqr_comba_$$i.c; \ ./comba_sqr_gen $$i | sed -e 's/ *$$//' > ../sqr/fp_sqr_comba_$$i.c; \
done done
./comba_sqr_smallgen > ../sqr/fp_sqr_comba_small_set.c ./comba_sqr_smallgen > ../sqr/fp_sqr_comba_small_set.c

View File

@ -1,12 +1,11 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis
* *
* This project is meant to fill in where LibTomMath * This project is meant to fill in where LibTomMath
* falls short. That is speed ;-) * falls short. That is speed ;-)
* *
* This project is public domain and free for all purposes. * This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/ */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_H_ #ifndef TFM_H_
#define TFM_H_ #define TFM_H_
@ -16,14 +15,14 @@
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
/* 0xMaMiPaXX /* 0xMaMiPaDe
* Major * Major
* Minor * Minor
* Patch * Patch
* XX - undefined * Development - 00=release, 01=in-development
*/ */
#define TFM_VERSION 0x000D0100 #define TFM_VERSION 0x000D0101
#define TFM_VERSION_S "v0.13.1" #define TFM_VERSION_S "v0.13.1-next"
#ifndef MIN #ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y))
@ -335,7 +334,7 @@ const char *fp_ident(void);
/* zero/even/odd ? */ /* zero/even/odd ? */
#define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO) #define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO)
#define fp_iseven(a) (((a)->used >= 0 && (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO) #define fp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO)
#define fp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? FP_YES : FP_NO) #define fp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? FP_YES : FP_NO)
/* set to a small digit */ /* set to a small digit */
@ -492,7 +491,3 @@ int fp_toradix(fp_int *a, char *str, int radix);
int fp_toradix_n(fp_int * a, char *str, int radix, int maxlen); int fp_toradix_n(fp_int * a, char *str, int radix, int maxlen);
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,16 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#ifndef TFM_PRIVATE_H_ #ifndef TFM_PRIVATE_H_
#define TFM_PRIVATE_H_ #define TFM_PRIVATE_H_
#include <tfm.h> #include "tfm.h"
/* VARIOUS LOW LEVEL STUFFS */ /* VARIOUS LOW LEVEL STUFFS */
void s_fp_add(fp_int *a, fp_int *b, fp_int *c); void s_fp_add(fp_int *a, fp_int *b, fp_int *c);
@ -119,7 +112,3 @@ void fp_sqr_comba64(fp_int *A, fp_int *B);
extern const char *fp_s_rmap; extern const char *fp_s_rmap;
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,21 +1,18 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
#ifndef GIT_VERSION
#define GIT_VERSION TFM_VERSION_S
#endif
const char *fp_ident(void) const char *fp_ident(void)
{ {
static char buf[1024]; static char buf[1024];
memset(buf, 0, sizeof(buf)); memset(buf, 0, sizeof(buf));
snprintf(buf, sizeof(buf)-1, snprintf(buf, sizeof(buf)-1,
"TomsFastMath " TFM_VERSION_S "\n" "TomsFastMath " GIT_VERSION "\n"
#if defined(TFM_IDENT_BUILD_DATE) #if defined(TFM_IDENT_BUILD_DATE)
"Built on " __DATE__ " at " __TIME__ "\n" "Built on " __DATE__ " at " __TIME__ "\n"
#endif #endif
@ -91,8 +88,3 @@ int main(void)
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
#if FP_GEN_RANDOM_MAX == 0xffffffff #if FP_GEN_RANDOM_MAX == 0xffffffff
@ -59,7 +52,3 @@ void fp_rand(fp_int *a, int digits)
return; return;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_set(fp_int *a, fp_digit b) void fp_set(fp_int *a, fp_digit b)
@ -15,7 +8,3 @@ void fp_set(fp_int *a, fp_digit b)
a->dp[0] = b; a->dp[0] = b;
a->used = a->dp[0] ? 1 : 0; a->used = a->dp[0] ? 1 : 0;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,3 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifdef TFM_SMALL_MONT_SET #ifdef TFM_SMALL_MONT_SET
/* computes x/R == x (mod N) via Montgomery Reduction */ /* computes x/R == x (mod N) via Montgomery Reduction */
void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp) void fp_montgomery_reduce_small(fp_int *a, fp_int *m, fp_digit mp)

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* computes a = B**n mod b without division or multiplication useful for /* computes a = B**n mod b without division or multiplication useful for
@ -36,8 +29,3 @@ void fp_montgomery_calc_normalization(fp_int *a, fp_int *b)
} }
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/******************************************************************/ /******************************************************************/
@ -300,7 +293,7 @@ asm( \
" MOVCC %0,#0 \n\t" \ " MOVCC %0,#0 \n\t" \
" UMLAL r0,%0,%3,%4 \n\t" \ " UMLAL r0,%0,%3,%4 \n\t" \
" STR r0,%1 \n\t" \ " STR r0,%1 \n\t" \
:"=r"(cy),"=m"(_c[0]):"0"(cy),"r"(mu),"r"(*tmpm++),"1"(_c[0]):"r0","cc"); :"=r"(cy),"=m"(_c[0]):"0"(cy),"r"(mu),"r"(*tmpm++),"m"(_c[0]):"r0","cc");
#define PROPCARRY \ #define PROPCARRY \
asm( \ asm( \
@ -309,7 +302,7 @@ asm( \
" STR r0,%1 \n\t" \ " STR r0,%1 \n\t" \
" MOVCS %0,#1 \n\t" \ " MOVCS %0,#1 \n\t" \
" MOVCC %0,#0 \n\t" \ " MOVCC %0,#0 \n\t" \
:"=r"(cy),"=m"(_c[0]):"0"(cy),"1"(_c[0]):"r0","cc"); :"=r"(cy),"=m"(_c[0]):"0"(cy),"m"(_c[0]):"r0","cc");
/******************************************************************/ /******************************************************************/
#elif defined(TFM_PPC32) #elif defined(TFM_PPC32)
@ -545,8 +538,3 @@ void fp_montgomery_reduce(fp_int *a, fp_int *m, fp_digit mp)
s_fp_sub (a, m, a); s_fp_sub (a, m, a);
} }
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* setups the montgomery reduction */ /* setups the montgomery reduction */
@ -41,8 +34,3 @@ int fp_montgomery_setup(fp_int *a, fp_digit *rho)
return FP_OKAY; return FP_OKAY;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a * b */ /* c = a * b */
@ -132,8 +125,3 @@ clean:
C->dp[y] = 0; C->dp[y] = 0;
} }
} }
/* $Source: /cvs/libtom/tomsfastmath/src/mul/fp_mul.c,v $ */
/* $Revision: 1.1 $ */
/* $Date: 2006/12/31 21:25:53 $ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
void fp_mul_2(fp_int * a, fp_int * b) void fp_mul_2(fp_int * a, fp_int * b)
@ -60,8 +53,3 @@ void fp_mul_2(fp_int * a, fp_int * b)
} }
b->sign = a->sign; b->sign = a->sign;
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
#include <tfm_private.h> #include <tfm_private.h>
/* c = a * 2**d */ /* c = a * 2**d */
@ -40,8 +33,3 @@ void fp_mul_2d(fp_int *a, int b, fp_int *c)
} }
fp_clamp(c); fp_clamp(c);
} }
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,12 +1,5 @@
/* TomsFastMath, a fast ISO C bignum library. /* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
* /* SPDX-License-Identifier: Unlicense */
* This project is meant to fill in where LibTomMath
* falls short. That is speed ;-)
*
* This project is public domain and free for all purposes.
*
* Tom St Denis, tomstdenis@gmail.com
*/
/* About this file... /* About this file...
@ -366,8 +359,3 @@ void fp_mul_comba(fp_int *A, fp_int *B, fp_int *C)
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL12) && FP_SIZE >= 24 #if defined(TFM_MUL12) && FP_SIZE >= 24
void fp_mul_comba12(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba12(fp_int *A, fp_int *B, fp_int *C)
@ -109,8 +113,3 @@ void fp_mul_comba12(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL17) && FP_SIZE >= 34 #if defined(TFM_MUL17) && FP_SIZE >= 34
void fp_mul_comba17(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba17(fp_int *A, fp_int *B, fp_int *C)
@ -149,8 +153,3 @@ void fp_mul_comba17(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL20) && FP_SIZE >= 40 #if defined(TFM_MUL20) && FP_SIZE >= 40
void fp_mul_comba20(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba20(fp_int *A, fp_int *B, fp_int *C)
@ -173,8 +177,3 @@ void fp_mul_comba20(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL24) && FP_SIZE >= 48 #if defined(TFM_MUL24) && FP_SIZE >= 48
void fp_mul_comba24(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba24(fp_int *A, fp_int *B, fp_int *C)
@ -205,8 +209,3 @@ void fp_mul_comba24(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL28) && FP_SIZE >= 56 #if defined(TFM_MUL28) && FP_SIZE >= 56
void fp_mul_comba28(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba28(fp_int *A, fp_int *B, fp_int *C)
@ -237,8 +241,3 @@ void fp_mul_comba28(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL3) && FP_SIZE >= 6 #if defined(TFM_MUL3) && FP_SIZE >= 6
void fp_mul_comba3(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba3(fp_int *A, fp_int *B, fp_int *C)
@ -37,8 +41,3 @@ void fp_mul_comba3(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL32) && FP_SIZE >= 64 #if defined(TFM_MUL32) && FP_SIZE >= 64
void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
@ -283,8 +287,3 @@ void fp_mul_comba32(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL4) && FP_SIZE >= 8 #if defined(TFM_MUL4) && FP_SIZE >= 8
void fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C)
@ -45,8 +49,3 @@ void fp_mul_comba4(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,11 +1,17 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL48) && FP_SIZE >= 96 #if defined(TFM_MUL48) && FP_SIZE >= 96
void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
{ {
fp_digit c0, c1, c2, at[96]; fp_digit c0, c1, c2, at[96];
int out_size;
out_size = A->used + B->used;
memcpy(at, A->dp, 48 * sizeof(fp_digit)); memcpy(at, A->dp, 48 * sizeof(fp_digit));
memcpy(at+48, B->dp, 48 * sizeof(fp_digit)); memcpy(at+48, B->dp, 48 * sizeof(fp_digit));
COMBA_START; COMBA_START;
@ -166,6 +172,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[0], at[86]); MULADD(at[1], at[85]); MULADD(at[2], at[84]); MULADD(at[3], at[83]); MULADD(at[4], at[82]); MULADD(at[5], at[81]); MULADD(at[6], at[80]); MULADD(at[7], at[79]); MULADD(at[8], at[78]); MULADD(at[9], at[77]); MULADD(at[10], at[76]); MULADD(at[11], at[75]); MULADD(at[12], at[74]); MULADD(at[13], at[73]); MULADD(at[14], at[72]); MULADD(at[15], at[71]); MULADD(at[16], at[70]); MULADD(at[17], at[69]); MULADD(at[18], at[68]); MULADD(at[19], at[67]); MULADD(at[20], at[66]); MULADD(at[21], at[65]); MULADD(at[22], at[64]); MULADD(at[23], at[63]); MULADD(at[24], at[62]); MULADD(at[25], at[61]); MULADD(at[26], at[60]); MULADD(at[27], at[59]); MULADD(at[28], at[58]); MULADD(at[29], at[57]); MULADD(at[30], at[56]); MULADD(at[31], at[55]); MULADD(at[32], at[54]); MULADD(at[33], at[53]); MULADD(at[34], at[52]); MULADD(at[35], at[51]); MULADD(at[36], at[50]); MULADD(at[37], at[49]); MULADD(at[38], at[48]); MULADD(at[0], at[86]); MULADD(at[1], at[85]); MULADD(at[2], at[84]); MULADD(at[3], at[83]); MULADD(at[4], at[82]); MULADD(at[5], at[81]); MULADD(at[6], at[80]); MULADD(at[7], at[79]); MULADD(at[8], at[78]); MULADD(at[9], at[77]); MULADD(at[10], at[76]); MULADD(at[11], at[75]); MULADD(at[12], at[74]); MULADD(at[13], at[73]); MULADD(at[14], at[72]); MULADD(at[15], at[71]); MULADD(at[16], at[70]); MULADD(at[17], at[69]); MULADD(at[18], at[68]); MULADD(at[19], at[67]); MULADD(at[20], at[66]); MULADD(at[21], at[65]); MULADD(at[22], at[64]); MULADD(at[23], at[63]); MULADD(at[24], at[62]); MULADD(at[25], at[61]); MULADD(at[26], at[60]); MULADD(at[27], at[59]); MULADD(at[28], at[58]); MULADD(at[29], at[57]); MULADD(at[30], at[56]); MULADD(at[31], at[55]); MULADD(at[32], at[54]); MULADD(at[33], at[53]); MULADD(at[34], at[52]); MULADD(at[35], at[51]); MULADD(at[36], at[50]); MULADD(at[37], at[49]); MULADD(at[38], at[48]);
COMBA_STORE(C->dp[38]); COMBA_STORE(C->dp[38]);
/* early out at 40 digits, 40*32==1280, or two 640 bit operands */
if (out_size <= 40) { COMBA_STORE2(C->dp[39]); C->used = 40; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
/* 39 */ /* 39 */
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[0], at[87]); MULADD(at[1], at[86]); MULADD(at[2], at[85]); MULADD(at[3], at[84]); MULADD(at[4], at[83]); MULADD(at[5], at[82]); MULADD(at[6], at[81]); MULADD(at[7], at[80]); MULADD(at[8], at[79]); MULADD(at[9], at[78]); MULADD(at[10], at[77]); MULADD(at[11], at[76]); MULADD(at[12], at[75]); MULADD(at[13], at[74]); MULADD(at[14], at[73]); MULADD(at[15], at[72]); MULADD(at[16], at[71]); MULADD(at[17], at[70]); MULADD(at[18], at[69]); MULADD(at[19], at[68]); MULADD(at[20], at[67]); MULADD(at[21], at[66]); MULADD(at[22], at[65]); MULADD(at[23], at[64]); MULADD(at[24], at[63]); MULADD(at[25], at[62]); MULADD(at[26], at[61]); MULADD(at[27], at[60]); MULADD(at[28], at[59]); MULADD(at[29], at[58]); MULADD(at[30], at[57]); MULADD(at[31], at[56]); MULADD(at[32], at[55]); MULADD(at[33], at[54]); MULADD(at[34], at[53]); MULADD(at[35], at[52]); MULADD(at[36], at[51]); MULADD(at[37], at[50]); MULADD(at[38], at[49]); MULADD(at[39], at[48]); MULADD(at[0], at[87]); MULADD(at[1], at[86]); MULADD(at[2], at[85]); MULADD(at[3], at[84]); MULADD(at[4], at[83]); MULADD(at[5], at[82]); MULADD(at[6], at[81]); MULADD(at[7], at[80]); MULADD(at[8], at[79]); MULADD(at[9], at[78]); MULADD(at[10], at[77]); MULADD(at[11], at[76]); MULADD(at[12], at[75]); MULADD(at[13], at[74]); MULADD(at[14], at[73]); MULADD(at[15], at[72]); MULADD(at[16], at[71]); MULADD(at[17], at[70]); MULADD(at[18], at[69]); MULADD(at[19], at[68]); MULADD(at[20], at[67]); MULADD(at[21], at[66]); MULADD(at[22], at[65]); MULADD(at[23], at[64]); MULADD(at[24], at[63]); MULADD(at[25], at[62]); MULADD(at[26], at[61]); MULADD(at[27], at[60]); MULADD(at[28], at[59]); MULADD(at[29], at[58]); MULADD(at[30], at[57]); MULADD(at[31], at[56]); MULADD(at[32], at[55]); MULADD(at[33], at[54]); MULADD(at[34], at[53]); MULADD(at[35], at[52]); MULADD(at[36], at[51]); MULADD(at[37], at[50]); MULADD(at[38], at[49]); MULADD(at[39], at[48]);
@ -198,6 +208,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[0], at[94]); MULADD(at[1], at[93]); MULADD(at[2], at[92]); MULADD(at[3], at[91]); MULADD(at[4], at[90]); MULADD(at[5], at[89]); MULADD(at[6], at[88]); MULADD(at[7], at[87]); MULADD(at[8], at[86]); MULADD(at[9], at[85]); MULADD(at[10], at[84]); MULADD(at[11], at[83]); MULADD(at[12], at[82]); MULADD(at[13], at[81]); MULADD(at[14], at[80]); MULADD(at[15], at[79]); MULADD(at[16], at[78]); MULADD(at[17], at[77]); MULADD(at[18], at[76]); MULADD(at[19], at[75]); MULADD(at[20], at[74]); MULADD(at[21], at[73]); MULADD(at[22], at[72]); MULADD(at[23], at[71]); MULADD(at[24], at[70]); MULADD(at[25], at[69]); MULADD(at[26], at[68]); MULADD(at[27], at[67]); MULADD(at[28], at[66]); MULADD(at[29], at[65]); MULADD(at[30], at[64]); MULADD(at[31], at[63]); MULADD(at[32], at[62]); MULADD(at[33], at[61]); MULADD(at[34], at[60]); MULADD(at[35], at[59]); MULADD(at[36], at[58]); MULADD(at[37], at[57]); MULADD(at[38], at[56]); MULADD(at[39], at[55]); MULADD(at[40], at[54]); MULADD(at[41], at[53]); MULADD(at[42], at[52]); MULADD(at[43], at[51]); MULADD(at[44], at[50]); MULADD(at[45], at[49]); MULADD(at[46], at[48]); MULADD(at[0], at[94]); MULADD(at[1], at[93]); MULADD(at[2], at[92]); MULADD(at[3], at[91]); MULADD(at[4], at[90]); MULADD(at[5], at[89]); MULADD(at[6], at[88]); MULADD(at[7], at[87]); MULADD(at[8], at[86]); MULADD(at[9], at[85]); MULADD(at[10], at[84]); MULADD(at[11], at[83]); MULADD(at[12], at[82]); MULADD(at[13], at[81]); MULADD(at[14], at[80]); MULADD(at[15], at[79]); MULADD(at[16], at[78]); MULADD(at[17], at[77]); MULADD(at[18], at[76]); MULADD(at[19], at[75]); MULADD(at[20], at[74]); MULADD(at[21], at[73]); MULADD(at[22], at[72]); MULADD(at[23], at[71]); MULADD(at[24], at[70]); MULADD(at[25], at[69]); MULADD(at[26], at[68]); MULADD(at[27], at[67]); MULADD(at[28], at[66]); MULADD(at[29], at[65]); MULADD(at[30], at[64]); MULADD(at[31], at[63]); MULADD(at[32], at[62]); MULADD(at[33], at[61]); MULADD(at[34], at[60]); MULADD(at[35], at[59]); MULADD(at[36], at[58]); MULADD(at[37], at[57]); MULADD(at[38], at[56]); MULADD(at[39], at[55]); MULADD(at[40], at[54]); MULADD(at[41], at[53]); MULADD(at[42], at[52]); MULADD(at[43], at[51]); MULADD(at[44], at[50]); MULADD(at[45], at[49]); MULADD(at[46], at[48]);
COMBA_STORE(C->dp[46]); COMBA_STORE(C->dp[46]);
/* early out at 48 digits, 48*32==1536, or two 768 bit operands */
if (out_size <= 48) { COMBA_STORE2(C->dp[47]); C->used = 48; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
/* 47 */ /* 47 */
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[0], at[95]); MULADD(at[1], at[94]); MULADD(at[2], at[93]); MULADD(at[3], at[92]); MULADD(at[4], at[91]); MULADD(at[5], at[90]); MULADD(at[6], at[89]); MULADD(at[7], at[88]); MULADD(at[8], at[87]); MULADD(at[9], at[86]); MULADD(at[10], at[85]); MULADD(at[11], at[84]); MULADD(at[12], at[83]); MULADD(at[13], at[82]); MULADD(at[14], at[81]); MULADD(at[15], at[80]); MULADD(at[16], at[79]); MULADD(at[17], at[78]); MULADD(at[18], at[77]); MULADD(at[19], at[76]); MULADD(at[20], at[75]); MULADD(at[21], at[74]); MULADD(at[22], at[73]); MULADD(at[23], at[72]); MULADD(at[24], at[71]); MULADD(at[25], at[70]); MULADD(at[26], at[69]); MULADD(at[27], at[68]); MULADD(at[28], at[67]); MULADD(at[29], at[66]); MULADD(at[30], at[65]); MULADD(at[31], at[64]); MULADD(at[32], at[63]); MULADD(at[33], at[62]); MULADD(at[34], at[61]); MULADD(at[35], at[60]); MULADD(at[36], at[59]); MULADD(at[37], at[58]); MULADD(at[38], at[57]); MULADD(at[39], at[56]); MULADD(at[40], at[55]); MULADD(at[41], at[54]); MULADD(at[42], at[53]); MULADD(at[43], at[52]); MULADD(at[44], at[51]); MULADD(at[45], at[50]); MULADD(at[46], at[49]); MULADD(at[47], at[48]); MULADD(at[0], at[95]); MULADD(at[1], at[94]); MULADD(at[2], at[93]); MULADD(at[3], at[92]); MULADD(at[4], at[91]); MULADD(at[5], at[90]); MULADD(at[6], at[89]); MULADD(at[7], at[88]); MULADD(at[8], at[87]); MULADD(at[9], at[86]); MULADD(at[10], at[85]); MULADD(at[11], at[84]); MULADD(at[12], at[83]); MULADD(at[13], at[82]); MULADD(at[14], at[81]); MULADD(at[15], at[80]); MULADD(at[16], at[79]); MULADD(at[17], at[78]); MULADD(at[18], at[77]); MULADD(at[19], at[76]); MULADD(at[20], at[75]); MULADD(at[21], at[74]); MULADD(at[22], at[73]); MULADD(at[23], at[72]); MULADD(at[24], at[71]); MULADD(at[25], at[70]); MULADD(at[26], at[69]); MULADD(at[27], at[68]); MULADD(at[28], at[67]); MULADD(at[29], at[66]); MULADD(at[30], at[65]); MULADD(at[31], at[64]); MULADD(at[32], at[63]); MULADD(at[33], at[62]); MULADD(at[34], at[61]); MULADD(at[35], at[60]); MULADD(at[36], at[59]); MULADD(at[37], at[58]); MULADD(at[38], at[57]); MULADD(at[39], at[56]); MULADD(at[40], at[55]); MULADD(at[41], at[54]); MULADD(at[42], at[53]); MULADD(at[43], at[52]); MULADD(at[44], at[51]); MULADD(at[45], at[50]); MULADD(at[46], at[49]); MULADD(at[47], at[48]);
@ -230,6 +244,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[7], at[95]); MULADD(at[8], at[94]); MULADD(at[9], at[93]); MULADD(at[10], at[92]); MULADD(at[11], at[91]); MULADD(at[12], at[90]); MULADD(at[13], at[89]); MULADD(at[14], at[88]); MULADD(at[15], at[87]); MULADD(at[16], at[86]); MULADD(at[17], at[85]); MULADD(at[18], at[84]); MULADD(at[19], at[83]); MULADD(at[20], at[82]); MULADD(at[21], at[81]); MULADD(at[22], at[80]); MULADD(at[23], at[79]); MULADD(at[24], at[78]); MULADD(at[25], at[77]); MULADD(at[26], at[76]); MULADD(at[27], at[75]); MULADD(at[28], at[74]); MULADD(at[29], at[73]); MULADD(at[30], at[72]); MULADD(at[31], at[71]); MULADD(at[32], at[70]); MULADD(at[33], at[69]); MULADD(at[34], at[68]); MULADD(at[35], at[67]); MULADD(at[36], at[66]); MULADD(at[37], at[65]); MULADD(at[38], at[64]); MULADD(at[39], at[63]); MULADD(at[40], at[62]); MULADD(at[41], at[61]); MULADD(at[42], at[60]); MULADD(at[43], at[59]); MULADD(at[44], at[58]); MULADD(at[45], at[57]); MULADD(at[46], at[56]); MULADD(at[47], at[55]); MULADD(at[7], at[95]); MULADD(at[8], at[94]); MULADD(at[9], at[93]); MULADD(at[10], at[92]); MULADD(at[11], at[91]); MULADD(at[12], at[90]); MULADD(at[13], at[89]); MULADD(at[14], at[88]); MULADD(at[15], at[87]); MULADD(at[16], at[86]); MULADD(at[17], at[85]); MULADD(at[18], at[84]); MULADD(at[19], at[83]); MULADD(at[20], at[82]); MULADD(at[21], at[81]); MULADD(at[22], at[80]); MULADD(at[23], at[79]); MULADD(at[24], at[78]); MULADD(at[25], at[77]); MULADD(at[26], at[76]); MULADD(at[27], at[75]); MULADD(at[28], at[74]); MULADD(at[29], at[73]); MULADD(at[30], at[72]); MULADD(at[31], at[71]); MULADD(at[32], at[70]); MULADD(at[33], at[69]); MULADD(at[34], at[68]); MULADD(at[35], at[67]); MULADD(at[36], at[66]); MULADD(at[37], at[65]); MULADD(at[38], at[64]); MULADD(at[39], at[63]); MULADD(at[40], at[62]); MULADD(at[41], at[61]); MULADD(at[42], at[60]); MULADD(at[43], at[59]); MULADD(at[44], at[58]); MULADD(at[45], at[57]); MULADD(at[46], at[56]); MULADD(at[47], at[55]);
COMBA_STORE(C->dp[54]); COMBA_STORE(C->dp[54]);
/* early out at 56 digits, 56*32==1792, or two 896 bit operands */
if (out_size <= 56) { COMBA_STORE2(C->dp[55]); C->used = 56; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
/* 55 */ /* 55 */
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[8], at[95]); MULADD(at[9], at[94]); MULADD(at[10], at[93]); MULADD(at[11], at[92]); MULADD(at[12], at[91]); MULADD(at[13], at[90]); MULADD(at[14], at[89]); MULADD(at[15], at[88]); MULADD(at[16], at[87]); MULADD(at[17], at[86]); MULADD(at[18], at[85]); MULADD(at[19], at[84]); MULADD(at[20], at[83]); MULADD(at[21], at[82]); MULADD(at[22], at[81]); MULADD(at[23], at[80]); MULADD(at[24], at[79]); MULADD(at[25], at[78]); MULADD(at[26], at[77]); MULADD(at[27], at[76]); MULADD(at[28], at[75]); MULADD(at[29], at[74]); MULADD(at[30], at[73]); MULADD(at[31], at[72]); MULADD(at[32], at[71]); MULADD(at[33], at[70]); MULADD(at[34], at[69]); MULADD(at[35], at[68]); MULADD(at[36], at[67]); MULADD(at[37], at[66]); MULADD(at[38], at[65]); MULADD(at[39], at[64]); MULADD(at[40], at[63]); MULADD(at[41], at[62]); MULADD(at[42], at[61]); MULADD(at[43], at[60]); MULADD(at[44], at[59]); MULADD(at[45], at[58]); MULADD(at[46], at[57]); MULADD(at[47], at[56]); MULADD(at[8], at[95]); MULADD(at[9], at[94]); MULADD(at[10], at[93]); MULADD(at[11], at[92]); MULADD(at[12], at[91]); MULADD(at[13], at[90]); MULADD(at[14], at[89]); MULADD(at[15], at[88]); MULADD(at[16], at[87]); MULADD(at[17], at[86]); MULADD(at[18], at[85]); MULADD(at[19], at[84]); MULADD(at[20], at[83]); MULADD(at[21], at[82]); MULADD(at[22], at[81]); MULADD(at[23], at[80]); MULADD(at[24], at[79]); MULADD(at[25], at[78]); MULADD(at[26], at[77]); MULADD(at[27], at[76]); MULADD(at[28], at[75]); MULADD(at[29], at[74]); MULADD(at[30], at[73]); MULADD(at[31], at[72]); MULADD(at[32], at[71]); MULADD(at[33], at[70]); MULADD(at[34], at[69]); MULADD(at[35], at[68]); MULADD(at[36], at[67]); MULADD(at[37], at[66]); MULADD(at[38], at[65]); MULADD(at[39], at[64]); MULADD(at[40], at[63]); MULADD(at[41], at[62]); MULADD(at[42], at[61]); MULADD(at[43], at[60]); MULADD(at[44], at[59]); MULADD(at[45], at[58]); MULADD(at[46], at[57]); MULADD(at[47], at[56]);
@ -262,6 +280,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[15], at[95]); MULADD(at[16], at[94]); MULADD(at[17], at[93]); MULADD(at[18], at[92]); MULADD(at[19], at[91]); MULADD(at[20], at[90]); MULADD(at[21], at[89]); MULADD(at[22], at[88]); MULADD(at[23], at[87]); MULADD(at[24], at[86]); MULADD(at[25], at[85]); MULADD(at[26], at[84]); MULADD(at[27], at[83]); MULADD(at[28], at[82]); MULADD(at[29], at[81]); MULADD(at[30], at[80]); MULADD(at[31], at[79]); MULADD(at[32], at[78]); MULADD(at[33], at[77]); MULADD(at[34], at[76]); MULADD(at[35], at[75]); MULADD(at[36], at[74]); MULADD(at[37], at[73]); MULADD(at[38], at[72]); MULADD(at[39], at[71]); MULADD(at[40], at[70]); MULADD(at[41], at[69]); MULADD(at[42], at[68]); MULADD(at[43], at[67]); MULADD(at[44], at[66]); MULADD(at[45], at[65]); MULADD(at[46], at[64]); MULADD(at[47], at[63]); MULADD(at[15], at[95]); MULADD(at[16], at[94]); MULADD(at[17], at[93]); MULADD(at[18], at[92]); MULADD(at[19], at[91]); MULADD(at[20], at[90]); MULADD(at[21], at[89]); MULADD(at[22], at[88]); MULADD(at[23], at[87]); MULADD(at[24], at[86]); MULADD(at[25], at[85]); MULADD(at[26], at[84]); MULADD(at[27], at[83]); MULADD(at[28], at[82]); MULADD(at[29], at[81]); MULADD(at[30], at[80]); MULADD(at[31], at[79]); MULADD(at[32], at[78]); MULADD(at[33], at[77]); MULADD(at[34], at[76]); MULADD(at[35], at[75]); MULADD(at[36], at[74]); MULADD(at[37], at[73]); MULADD(at[38], at[72]); MULADD(at[39], at[71]); MULADD(at[40], at[70]); MULADD(at[41], at[69]); MULADD(at[42], at[68]); MULADD(at[43], at[67]); MULADD(at[44], at[66]); MULADD(at[45], at[65]); MULADD(at[46], at[64]); MULADD(at[47], at[63]);
COMBA_STORE(C->dp[62]); COMBA_STORE(C->dp[62]);
/* early out at 64 digits, 64*32==2048, or two 1024 bit operands */
if (out_size <= 64) { COMBA_STORE2(C->dp[63]); C->used = 64; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
/* 63 */ /* 63 */
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[16], at[95]); MULADD(at[17], at[94]); MULADD(at[18], at[93]); MULADD(at[19], at[92]); MULADD(at[20], at[91]); MULADD(at[21], at[90]); MULADD(at[22], at[89]); MULADD(at[23], at[88]); MULADD(at[24], at[87]); MULADD(at[25], at[86]); MULADD(at[26], at[85]); MULADD(at[27], at[84]); MULADD(at[28], at[83]); MULADD(at[29], at[82]); MULADD(at[30], at[81]); MULADD(at[31], at[80]); MULADD(at[32], at[79]); MULADD(at[33], at[78]); MULADD(at[34], at[77]); MULADD(at[35], at[76]); MULADD(at[36], at[75]); MULADD(at[37], at[74]); MULADD(at[38], at[73]); MULADD(at[39], at[72]); MULADD(at[40], at[71]); MULADD(at[41], at[70]); MULADD(at[42], at[69]); MULADD(at[43], at[68]); MULADD(at[44], at[67]); MULADD(at[45], at[66]); MULADD(at[46], at[65]); MULADD(at[47], at[64]); MULADD(at[16], at[95]); MULADD(at[17], at[94]); MULADD(at[18], at[93]); MULADD(at[19], at[92]); MULADD(at[20], at[91]); MULADD(at[21], at[90]); MULADD(at[22], at[89]); MULADD(at[23], at[88]); MULADD(at[24], at[87]); MULADD(at[25], at[86]); MULADD(at[26], at[85]); MULADD(at[27], at[84]); MULADD(at[28], at[83]); MULADD(at[29], at[82]); MULADD(at[30], at[81]); MULADD(at[31], at[80]); MULADD(at[32], at[79]); MULADD(at[33], at[78]); MULADD(at[34], at[77]); MULADD(at[35], at[76]); MULADD(at[36], at[75]); MULADD(at[37], at[74]); MULADD(at[38], at[73]); MULADD(at[39], at[72]); MULADD(at[40], at[71]); MULADD(at[41], at[70]); MULADD(at[42], at[69]); MULADD(at[43], at[68]); MULADD(at[44], at[67]); MULADD(at[45], at[66]); MULADD(at[46], at[65]); MULADD(at[47], at[64]);
@ -294,6 +316,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[23], at[95]); MULADD(at[24], at[94]); MULADD(at[25], at[93]); MULADD(at[26], at[92]); MULADD(at[27], at[91]); MULADD(at[28], at[90]); MULADD(at[29], at[89]); MULADD(at[30], at[88]); MULADD(at[31], at[87]); MULADD(at[32], at[86]); MULADD(at[33], at[85]); MULADD(at[34], at[84]); MULADD(at[35], at[83]); MULADD(at[36], at[82]); MULADD(at[37], at[81]); MULADD(at[38], at[80]); MULADD(at[39], at[79]); MULADD(at[40], at[78]); MULADD(at[41], at[77]); MULADD(at[42], at[76]); MULADD(at[43], at[75]); MULADD(at[44], at[74]); MULADD(at[45], at[73]); MULADD(at[46], at[72]); MULADD(at[47], at[71]); MULADD(at[23], at[95]); MULADD(at[24], at[94]); MULADD(at[25], at[93]); MULADD(at[26], at[92]); MULADD(at[27], at[91]); MULADD(at[28], at[90]); MULADD(at[29], at[89]); MULADD(at[30], at[88]); MULADD(at[31], at[87]); MULADD(at[32], at[86]); MULADD(at[33], at[85]); MULADD(at[34], at[84]); MULADD(at[35], at[83]); MULADD(at[36], at[82]); MULADD(at[37], at[81]); MULADD(at[38], at[80]); MULADD(at[39], at[79]); MULADD(at[40], at[78]); MULADD(at[41], at[77]); MULADD(at[42], at[76]); MULADD(at[43], at[75]); MULADD(at[44], at[74]); MULADD(at[45], at[73]); MULADD(at[46], at[72]); MULADD(at[47], at[71]);
COMBA_STORE(C->dp[70]); COMBA_STORE(C->dp[70]);
/* early out at 72 digits, 72*32==2304, or two 1152 bit operands */
if (out_size <= 72) { COMBA_STORE2(C->dp[71]); C->used = 72; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
/* 71 */ /* 71 */
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[24], at[95]); MULADD(at[25], at[94]); MULADD(at[26], at[93]); MULADD(at[27], at[92]); MULADD(at[28], at[91]); MULADD(at[29], at[90]); MULADD(at[30], at[89]); MULADD(at[31], at[88]); MULADD(at[32], at[87]); MULADD(at[33], at[86]); MULADD(at[34], at[85]); MULADD(at[35], at[84]); MULADD(at[36], at[83]); MULADD(at[37], at[82]); MULADD(at[38], at[81]); MULADD(at[39], at[80]); MULADD(at[40], at[79]); MULADD(at[41], at[78]); MULADD(at[42], at[77]); MULADD(at[43], at[76]); MULADD(at[44], at[75]); MULADD(at[45], at[74]); MULADD(at[46], at[73]); MULADD(at[47], at[72]); MULADD(at[24], at[95]); MULADD(at[25], at[94]); MULADD(at[26], at[93]); MULADD(at[27], at[92]); MULADD(at[28], at[91]); MULADD(at[29], at[90]); MULADD(at[30], at[89]); MULADD(at[31], at[88]); MULADD(at[32], at[87]); MULADD(at[33], at[86]); MULADD(at[34], at[85]); MULADD(at[35], at[84]); MULADD(at[36], at[83]); MULADD(at[37], at[82]); MULADD(at[38], at[81]); MULADD(at[39], at[80]); MULADD(at[40], at[79]); MULADD(at[41], at[78]); MULADD(at[42], at[77]); MULADD(at[43], at[76]); MULADD(at[44], at[75]); MULADD(at[45], at[74]); MULADD(at[46], at[73]); MULADD(at[47], at[72]);
@ -326,6 +352,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[31], at[95]); MULADD(at[32], at[94]); MULADD(at[33], at[93]); MULADD(at[34], at[92]); MULADD(at[35], at[91]); MULADD(at[36], at[90]); MULADD(at[37], at[89]); MULADD(at[38], at[88]); MULADD(at[39], at[87]); MULADD(at[40], at[86]); MULADD(at[41], at[85]); MULADD(at[42], at[84]); MULADD(at[43], at[83]); MULADD(at[44], at[82]); MULADD(at[45], at[81]); MULADD(at[46], at[80]); MULADD(at[47], at[79]); MULADD(at[31], at[95]); MULADD(at[32], at[94]); MULADD(at[33], at[93]); MULADD(at[34], at[92]); MULADD(at[35], at[91]); MULADD(at[36], at[90]); MULADD(at[37], at[89]); MULADD(at[38], at[88]); MULADD(at[39], at[87]); MULADD(at[40], at[86]); MULADD(at[41], at[85]); MULADD(at[42], at[84]); MULADD(at[43], at[83]); MULADD(at[44], at[82]); MULADD(at[45], at[81]); MULADD(at[46], at[80]); MULADD(at[47], at[79]);
COMBA_STORE(C->dp[78]); COMBA_STORE(C->dp[78]);
/* early out at 80 digits, 80*32==2560, or two 1280 bit operands */
if (out_size <= 80) { COMBA_STORE2(C->dp[79]); C->used = 80; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
/* 79 */ /* 79 */
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[32], at[95]); MULADD(at[33], at[94]); MULADD(at[34], at[93]); MULADD(at[35], at[92]); MULADD(at[36], at[91]); MULADD(at[37], at[90]); MULADD(at[38], at[89]); MULADD(at[39], at[88]); MULADD(at[40], at[87]); MULADD(at[41], at[86]); MULADD(at[42], at[85]); MULADD(at[43], at[84]); MULADD(at[44], at[83]); MULADD(at[45], at[82]); MULADD(at[46], at[81]); MULADD(at[47], at[80]); MULADD(at[32], at[95]); MULADD(at[33], at[94]); MULADD(at[34], at[93]); MULADD(at[35], at[92]); MULADD(at[36], at[91]); MULADD(at[37], at[90]); MULADD(at[38], at[89]); MULADD(at[39], at[88]); MULADD(at[40], at[87]); MULADD(at[41], at[86]); MULADD(at[42], at[85]); MULADD(at[43], at[84]); MULADD(at[44], at[83]); MULADD(at[45], at[82]); MULADD(at[46], at[81]); MULADD(at[47], at[80]);
@ -358,6 +388,10 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[39], at[95]); MULADD(at[40], at[94]); MULADD(at[41], at[93]); MULADD(at[42], at[92]); MULADD(at[43], at[91]); MULADD(at[44], at[90]); MULADD(at[45], at[89]); MULADD(at[46], at[88]); MULADD(at[47], at[87]); MULADD(at[39], at[95]); MULADD(at[40], at[94]); MULADD(at[41], at[93]); MULADD(at[42], at[92]); MULADD(at[43], at[91]); MULADD(at[44], at[90]); MULADD(at[45], at[89]); MULADD(at[46], at[88]); MULADD(at[47], at[87]);
COMBA_STORE(C->dp[86]); COMBA_STORE(C->dp[86]);
/* early out at 88 digits, 88*32==2816, or two 1408 bit operands */
if (out_size <= 88) { COMBA_STORE2(C->dp[87]); C->used = 88; C->sign = A->sign ^ B->sign; fp_clamp(C); COMBA_FINI; return; }
/* 87 */ /* 87 */
COMBA_FORWARD; COMBA_FORWARD;
MULADD(at[40], at[95]); MULADD(at[41], at[94]); MULADD(at[42], at[93]); MULADD(at[43], at[92]); MULADD(at[44], at[91]); MULADD(at[45], at[90]); MULADD(at[46], at[89]); MULADD(at[47], at[88]); MULADD(at[40], at[95]); MULADD(at[41], at[94]); MULADD(at[42], at[93]); MULADD(at[43], at[92]); MULADD(at[44], at[91]); MULADD(at[45], at[90]); MULADD(at[46], at[89]); MULADD(at[47], at[88]);
@ -397,8 +431,3 @@ void fp_mul_comba48(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

View File

@ -1,5 +1,9 @@
/* TomsFastMath, a fast ISO C bignum library. -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
#ifndef TFM_PRE_GEN_MPI_C
#define TFM_DEFINES #define TFM_DEFINES
#include "fp_mul_comba.c" #include "fp_mul_comba.c"
#endif
#if defined(TFM_MUL6) && FP_SIZE >= 12 #if defined(TFM_MUL6) && FP_SIZE >= 12
void fp_mul_comba6(fp_int *A, fp_int *B, fp_int *C) void fp_mul_comba6(fp_int *A, fp_int *B, fp_int *C)
@ -61,8 +65,3 @@ void fp_mul_comba6(fp_int *A, fp_int *B, fp_int *C)
COMBA_FINI; COMBA_FINI;
} }
#endif #endif
/* $Source$ */
/* $Revision$ */
/* $Date$ */

Some files were not shown because too many files have changed in this diff Show More