FastCode is an
open source programming
Open-source software (OSS) is computer software that is released under a license in which the copyright holder grants users the rights to use, study, change, and distribute the software and its source code to anyone and for any purpose. Open ...
project aimed at providing enhanced
runtime library
In computer programming, a runtime library is a set of low-level routines used by a compiler to invoke some of the behaviors of a runtime environment, by inserting calls to the runtime library into compiled executable binary. The runtime enviro ...
routines for
Embarcadero Delphi
Delphi is a general-purpose programming language and a software product that uses the Delphi dialect of the Object Pascal programming language and provides an integrated development environment (IDE) for rapid application development of desktop, ...
and
C++ Builder
C, or c, is the third letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''cee'' (pronounced ), plural ''cees''.
History
"C ...
. Since it was started in 2003 by
Dennis Kjaer Christensen, it has contributed highly optimised functionality to the 32-bit Delphi
runtime library
In computer programming, a runtime library is a set of low-level routines used by a compiler to invoke some of the behaviors of a runtime environment, by inserting calls to the runtime library into compiled executable binary. The runtime enviro ...
(RTL). FastCode is unique among contributions to commercial compiler runtime libraries for its community-driven and open source nature.
Structure
The project is organized as a competition divided into challenges. Each challenge takes one function and optimizes it against a number of targets. The project provides tools for
benchmarking and validating each function contribution. One point is given per contribution (maximally one function per target is given points) and ten points are awarded for a target winner. A list with all contributors and their scores is maintained, and at the end of each year, until 2008, a winner was celebrated.
Borland,
Codegear
CodeGear is a wholly owned division of Embarcadero Technologies. CodeGear develops software development tools such as the Delphi Integrated development environment, the programming language Delphi, and the database server InterBase. Originally ...
and
Embarcadero, the owners of
Delphi
Delphi (; ), in legend previously called Pytho (Πυθώ), in ancient times was a sacred precinct that served as the seat of Pythia, the major oracle who was consulted about important decisions throughout the ancient classical world. The oracl ...
and
C++ Builder
C, or c, is the third letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''cee'' (pronounced ), plural ''cees''.
History
"C ...
, have historically sponsored prizes.
The majority of participants in the competition are assembler developers who often utilize processor-specific 32-bit code and extra instruction sets, such as
MMX,
SSE,
SSE2
SSE2 (Streaming SIMD Extensions 2) is one of the Intel SIMD (Single Instruction, Multiple Data) processor supplementary instruction sets first introduced by Intel with the initial version of the Pentium 4 in 2000. It extends the earlier SSE ins ...
,
SSE3
SSE3, Streaming SIMD Extensions 3, also known by its Intel code name Prescott New Instructions (PNI), is the third iteration of the SSE instruction set for the IA-32 (x86) architecture. Intel introduced SSE3 in early 2004 with the Prescott revi ...
,
SSSE3
Supplemental Streaming SIMD Extensions 3 (SSSE3 or SSE3S) is a SIMD instruction set created by Intel and is the fourth iteration of the SSE technology.
History
SSSE3 was first introduced with Intel processors based on the Core microarchitectu ...
and
SSE4
SSE4 (Streaming SIMD Extensions 4) is a SIMD CPU instruction set used in the Intel Core microarchitecture and AMD K10 (K8L). It was announced on September 27, 2006, at the Fall 2006 Intel Developer Forum, with vague details in a white paper; more ...
.
The project enjoys the support of Embarcadero who recognizes the contributions of the FastCode team and incorporates their code into the codebase for Delphi. The default
memory manager for
Embarcadero Delphi
Delphi is a general-purpose programming language and a software product that uses the Delphi dialect of the Object Pascal programming language and provides an integrated development environment (IDE) for rapid application development of desktop, ...
, FastMM4, is the winner of the FastCode Memory Manager challenge.
The project was first hosted on Robert Lee's
OptimalCode site, and its source code's home page i
last updated in 2008. The source code contains both the enhanced routines and the testing suites to benchmark the routines. In 2017, the benchmark routines for Move, FillChar and the memory manager have been ported for 64-bit, available a
Testing
The FastCode project puts a lot of effort into testing and focus is on providing very high quality software. Testing is split into two categories - testing for correctness and testing for speed.
Validation
Validation is done on all CPUs from the target set and very often on other CPUs and OSs (
Windows XP
Windows XP is a major release of Microsoft's Windows NT operating system. It was release to manufacturing, released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct upgrade to its predecessors, Wind ...
,
Windows Vista
Windows Vista is a major release of the Windows NT operating system developed by Microsoft. It was the direct successor to Windows XP, which was released five years before, at the time being the longest time span between successive releases of ...
,
Windows 7
Windows 7 is a major release of the Windows NT operating system developed by Microsoft. It was released to manufacturing on July 22, 2009, and became generally available on October 22, 2009. It is the successor to Windows Vista, released nearl ...
etc.) as well. Validation is done across many different function inputs, both normal usage cases and error usage cases. Validation is done against known correct values and against reference implementations such existing RTL functions.
Benchmarking
Benchmarking is done on all the CPUs that are part of the current target set at the given time. These CPUs have been or are part of target sets: (
Intel Pentium 3,
Intel Pentium M,
Intel Pentium 4
Pentium 4 is a series of single-core CPUs for desktops, laptops and entry-level servers manufactured by Intel. The processors were shipped from November 20, 2000 until August 8, 2008. The production of Netburst processors was active from 2000 ...
,
Intel Core
Intel Core is a line of streamlined midrange consumer, workstation and enthusiast computer central processing units (CPUs) marketed by Intel Corporation. These processors displaced the existing mid- to high-end Pentium processors at the time ...
,
Intel Core 2
Intel Core 2 is the processor family encompassing a range of Intel's consumer 64-bit x86-64 single-, dual-, and quad-core microprocessors based on the Core microarchitecture. The single- and dual-core models are single- die, whereas the quad-co ...
,
AMD Athlon XP
Athlon is the brand name applied to a series of x86-compatible microprocessors designed and manufactured by Advanced Micro Devices (AMD). The original Athlon (now called Athlon Classic) was the first seventh-generation x86 processor and the fi ...
,
AMD Opteron
Opteron is Advanced Micro Devices, AMD's x86 former server and workstation Microprocessor, processor line, and was the first processor which supported the AMD64 instruction set architecture (known generically as x86-64 or AMD64). It was release ...
,
AMD Phenom
Phenom is the 64-bit AMD desktop processor line based on the K10 microarchitecture, in what AMD calls family 10h (10 hex, i.e. 16 in normal decimal numbers) processors, sometimes incorrectly called "K10h". Triple-core versions (codenamed ''T ...
).
Great care has been taken to make the benchmarks stable and realistic. Especially the memory manager challenge benchmark was hard to get fair and memory manager usage logs were made from normal usage of real world applications, and then played back by the benchmark.
Targets
Testing done on the entire targetset. A new targetset is decided each year from a poll where the FastCode community can vote. A targetset will typically consist of six CPUs, where four are from Intel and two are from AMD. This ratio has been selected to mimic the marketshares. In addition to these six CPU targets there are ten targets defined as a blend of the six CPUs. These ten targets are called computed targets and can be speed only or a combination of speed and size. The maximum allowed instruction set is different for each target. A target could be "IA32 size penalty" or "SSE2".
The penalty for size is decided for each challenge by a poll.
List of challenges
The FastCode project has run the following challenge
*AES (
Advanced Encryption Standard
The Advanced Encryption Standard (AES), also known by its original name Rijndael (), is a specification for the encryption of electronic data established by the U.S. National Institute of Standards and Technology (NIST) in 2001.
AES is a variant ...
)
*AnsiStringReplace (Replaces occurrences of a substring within a string.)
*ArcCos (Calculates inverse cosinus. Overloaded versions for Single, Double and Extended precision.)
*ArcSin (Calculates inverse sinus. Overloaded versions for Single, Double and Extended precision.)
*Ceil32 (Returns the largest near 32 bit integer number.)
*Ceil64 (Returns the largest near 64 bit integer number.)
*CharPos (Searches for the first occurrence of a Char in a String. It returns the position of this occurrence.)
*CharPosIEx (Case insensitive search for the first occurrence of a Char in a String starting from an index passed as parameter. It returns the position of this occurrence.)
*CharPosEy (Searches for the n'th occurrence of a Char in a string starting from an index passed as parameter. It returns the position of this occurrence.)
*CharPosRev (Searches for the last occurrence of a Char in a String. It returns the position of this occurrence.)
*CompareMem (Compares two blocks of memory.)
*CompareStr (Compares two strings of type AnsiString.)
*CompareText (Compares two strings.)
*Fillchar (Fills out a section of storage Buffer with the same byte or character FillValue FillCount times.)
*Floor32 (Returns the smallest near 32 bit integer number.)
*Floor64 (Returns the smallest near 64 bit integer number.)
*GCD32 (Greatest Common Divisor 32 bit)
*IDCT (Inverse Discrete Cosine Transform)
*Int64Div (Divides two 64 bit integers)
*Int64Mul (Multiplicates two 64 bit integers)
*IntToStr (Converts an integer to a string)
*IsPrime (Tests a 32 bit integer for primality)
*LowerCase (Converts a string to lowercase)
*MaxFP (Returns the maximum of two Single, Double or Extended floating point values)
*MaxInt (Returns the maximum of two integer values)
*MaxInt64 (Returns the maximum of two 64 bit integer values)
*Memory Manager
*MinFP (Returns the minimum of two Single, Double or Extended floating point values)
*MinInt (Returns the minimum of two integer values)
*MinInt64 (Returns the minimum of two 64 bit integer values)
*Move (Copies N bytes from source to destination)
*Polar Complex Number Addition
*Polar Complex Number Subtraction
*Polar Complex Number Multiplication
*Polar Complex Number Division
*Polar To Rectangular Format Conversion
*Pos (Searches for the first occurrence of a substring in a String. It returns the position of this occurrence.)
*PosEx (search for the first occurrence of a substring in a String starting from an index passed as parameter. It returns the position of this occurrence.)
*PosIEx (Case insensitive search for the first occurrence of a substring in a String starting from an index passed as parameter. It returns the position of this occurrence.)
*Power (Returns base raised to exponent)
*Rectangular Complex Number Addition
*Rectangular Complex Number Subtraction
*Rectangular Complex Number Multiplication
*Rectangular Complex Number Division
*Rectangular To Polar Format Conversion
*RGBA To BGRA (Bitmap Format Conversion)
*Round (Bankers rounding on Single, Double or Extended value. Returns 64 bit integer)
*RoundToEx (Rounds a, Extended precision floating-point value to a specified digit or power of ten using "Banker's rounding".)
*Round32 (Bankers rounding on Single, Double or Extended value. Returns 32 bit integer)
*Scale Down (Bitmap Scaling)
*Sort
*StrComp (Compares two null-terminated strings, with case sensitivity)
*StrCopy (Copies one null-terminated string to another)
*StrIComp (Compares two null-terminated strings, without case sensitivity)
*StrLen (returns the length of a zero terminated string)
*StrLComp (Compares two null-terminated strings up to a length, with case sensitivity)
*StrLIComp (Compares two null-terminated strings up to a length, without case sensitivity)
*StrToInt32 (Converts a string to a 32 bit integer)
*Trim (Removes blank and control characters from the start and end of a string)
*TList.Sort
*Trunc (Truncates Single, Double or Extended value. Returns 64 bit integer)
*Trunc32 (Truncates Single, Double or Extended value. Returns 32 bit integer)
*UpperCase (Converts a string to uppercase)
*Val
Contributions to Delphi RTL
FastCode functions included in the Delphi RTL:
*Delphi 2005: CompareText, Int64Div and FillChar
*Delphi 2006: CompareText, Int64Div and FillChar, FastMM4 memory manager
*Delphi 2007—Delphi XE: ArcCos, ArcSin, Power, PosEx, Move, Memory Manager, FillChar, Pos, __lldiv, LowerCase, UpperCase, CompareStr, CompareMem, CompareText, StrLen, StrCopy, StrComp.
The ''Mastering Delphi'' books by Marco Cantu contains a chapter about FastCode listing the contributions to the Delphi RTL.
The FastCode Library
All the challenge winners are included in the FastCode library (http://fastcode.sourceforge.net/challenge_content/rtl_replcmnt_pkg.html). This library is
open source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use the source code, design documents, or content of the product. The open-source model is a decentralized sof ...
, released under the
MPL license. The library can be used in two ways: 1) calling functions directly, and 2) using the patching functionality.
When calling functions directly it is entirely up to the application developer to call the version of a function he thinks is fastest.
When using the patching functionality the library automatically detects the CPU type at application load, and uses this information to redirect all function calls to the FastCode winner function for that specific CPU.
FastMM4 Memory Manager
The FastMM memory manager used by Delphi and C++ Builder since 2006 is also the winner of a FastCode competition. It replaced the standard memory manager of Delphi and is not only less prone to memory fragmentation, it also provides improved debugging possibilities like being able to report
memory leak
In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. A memory leak may also happen when an object ...
s when the application is being closed, detecting use after memory release or double releases.
FastMM4 is also used as memory manager for applications developed in Lazarus.
FastMM4 is often listed as a "must have" tool for Delphi developers.
Nexus DB comes with FastMM4 integration for leakchecking.
FastMM usage is documented in "The New Memory Manager In BDS 2006".
Applications using FastCode
An application developed in Delphi or C++ Builder will typically use the default memory manager which is FastMM4. FastCode functions in the RTL have been selected to be the most commonly used ones and an application will also typically use some of these, especially if any string handling is done. Most Delphi/C++ Builder applications will therefore use code developed by the FastCode project. Some examples are
Skype
Skype () is a proprietary telecommunications application operated by Skype Technologies, a division of Microsoft, best known for VoIP-based videotelephony, videoconferencing and voice calls. It also has instant messaging, file transfer, ...
,
FL Studio
FL Studio (previously known as FruityLoops before 2003) is a digital audio workstation (DAW) developed by the Belgian company Image-Line.
FL Studio features a graphical user interface with a pattern-based music sequencer. The program is avail ...
, and
Embarcadero’s own
RAD Studio
Delphi is a general-purpose programming language and a software product that uses the Delphi dialect of the Object Pascal programming language and provides an integrated development environment (IDE) for rapid application development of desktop, ...
.
Hallvard's blogdescribes FastMM4 and why it is being used as the memory manager i
"The Online Trader"application.
References
{{DEFAULTSORT:Fastcode
Computer libraries
Programming contests
Delphi (programming language)