FastCode
Encyclopedia
FastCode is an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

 project aimed at providing enhanced runtime library
Runtime library
In computer programming, a runtime library is a special program library used by a compiler, to implement functions built into a programming language, during the execution of a computer program...

 routines for Embarcadero Delphi and C++ Builder. Since it was started in 2003 by Dennis Kjaer Christensen, it has contributed highly optimised functionality to the Delphi RTL
Runtime library
In computer programming, a runtime library is a special program library used by a compiler, to implement functions built into a programming language, during the execution of a computer program...

. 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
Benchmarking
Benchmarking is the process of comparing one's business processes and performance metrics to industry bests and/or best practices from other industries. Dimensions typically measured are quality, time and cost...

 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 a winner is celebrated. Borland
Borland
Borland Software Corporation is a software company first headquartered in Scotts Valley, California, Cupertino, California and finally Austin, Texas. It is now a Micro Focus subsidiary. It was founded in 1983 by Niels Jensen, Ole Henriksen, Mogens Glad and Philippe Kahn.-The 1980s:...

, Codegear
CodeGear
CodeGear is a wholly owned division of Embarcadero Technologies. CodeGear develops software development tools such as the Delphi IDE, the programming language Delphi, and the database server InterBase. Originally a division of Borland Software Corporation, it was launched on 14 November 2006...

 and Embarcadero
Embarcadero
Embarcadero may refer to:* Embarcadero , California** Embarcadero Circle, waterfront re-development project* Embarcadero , California** Embarcadero Center, office complex** Embarcadero Freeway, former California State Route 480...

, the owners of Delphi
Delphi
Delphi is both an archaeological site and a modern town in Greece on the south-western spur of Mount Parnassus in the valley of Phocis.In Greek mythology, Delphi was the site of the Delphic oracle, the most important oracle in the classical Greek world, and a major site for the worship of the god...

 and C++ Builder
C++ Builder
C++Builder is a rapid application development environment, developed by Borland and owned by Embarcadero Technologies, for writing programs in the C++ programming language. C++Builder combines the Visual Component Library and IDE written in Delphi with a C++ compiler...

, have historically sponsored prizes.

The majority of participants in the competition are assembler developers who often utilize processor-specific code and extra instruction sets, such as MMX
MMX
MMX is a single instruction, multiple data instruction set designed by Intel, introduced in 1996 with their P5-based Pentium line of microprocessors, designated as "Pentium with MMX Technology". It developed out of a similar unit introduced on the Intel i860, and earlier the Intel i750 video pixel...

, SSE
SSE
-Computing:*Server-sent events, a technology to push content to web clients*Simple Sharing Extensions, a specification that extends RSS from unidirectional to bidirectional information flows*SPARQL Syntax Expressions*Microsoft SQL Server Express Edition...

, SSE2
SSE2
SSE2, Streaming SIMD Extensions 2, is one of the Intel SIMD processor supplementary instruction sets first introduced by Intel with the initial version of the Pentium 4 in 2001. It extends the earlier SSE instruction set, and is intended to fully supplant MMX. Intel extended SSE2 to create SSE3...

, SSE3
SSE3
SSE3, Streaming SIMD Extensions 3, also known by its Intel code name Prescott New Instructions , is the third iteration of the SSE instruction set for the IA-32 architecture. Intel introduced SSE3 in early 2004 with the Prescott revision of their Pentium 4 CPU...

, SSSE3
SSSE3
Supplemental Streaming SIMD Extensions 3 is a SIMD instruction set created by Intel and is the fourth iteration of the SSE technology.- History :...

 and SSE4
SSE4
SSE4 is a CPU instruction set used in the Intel Core microarchitecture and AMD K10 . It was announced on 27 September 2006 at the Fall 2006 Intel Developer Forum, with vague details in a white paper; more precise details of 47 instructions became available at the Spring 2007 Intel Developer Forum...

.

The project enjoys the support of Embarcadero
Embarcadero
Embarcadero may refer to:* Embarcadero , California** Embarcadero Circle, waterfront re-development project* Embarcadero , California** Embarcadero Center, office complex** Embarcadero Freeway, former California State Route 480...

 who recognizes the contributions of the FastCode team and incorporates their code into the codebase for Delphi. The default memory manager
Memory manager
In IBM PC compatible computing, DOS memory management refers to software and techniques employed to give applications access to more than 640K of "conventional memory". The 640kB limit was specific to the IBM PC and close compatibles; other machines running MS-DOS had different limits, for example...

 for Embarcadero Delphi, FastMM4, is the winner of the FastCode Memory Manager challenge.

The project was first hosted on Robert Lee
Robert Lee
Robert Lee may refer to:* Robert Lee, 4th Earl of Lichfield , British peer and politician* Robert Lee , Regius Professor of Midwifery, University of Glasgow* Robert E...

's OptimalCode site, and its source code's current home is http://fastcode.sourceforge.net/.

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 CPU's from the target set and very often on other CPU's and OS's (Windows XP
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...

, Windows Vista
Windows Vista
Windows Vista is an operating system released in several variations developed by Microsoft for use on personal computers, including home and business desktops, laptops, tablet PCs, and media center PCs...

, Windows 7 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 CPU's that are part of the current target set at the given time. These CPU's have been or are part of target sets: (Intel Pentium 3, Intel Pentium M, Intel Pentium 4, Intel Core
Intel Core
Yonah was the code name for Intel's first generation of 65 nm process mobile microprocessors, based on the Banias/Dothan-core Pentium M microarchitecture. SIMD performance has been improved through the addition of SSE3 instructions and improvements to SSE and SSE2 implementations, while integer...

, Intel Core2, AMD Athlon XP, AMD Opteron, AMD Phenom).
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 6 CPU's, where 4 are from Intel and 2 are from AMD. This ratio has been selected to mimic the marketshares.
In addition to these 6 CPU targets there are 10 targets defined as a blend of the 6 CPU's. These 10 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 challenges http://fastcode.sourceforge.net/:
  • AES (Advanced Encryption Standard
    Advanced Encryption Standard
    Advanced Encryption Standard is a specification for the encryption of electronic data. It has been adopted by the U.S. government and is now used worldwide. It supersedes DES...

    )
  • 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
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

, released under the MPL license
Mozilla Public License
The Mozilla Public License is a free and open source software license. Version 1.0 was developed by Mitchell Baker when she worked as a lawyer at Netscape Communications Corporation and version 1.1 at the Mozilla Foundation...

. The library can be used in two ways: 1) Calling functions directly. 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 leaks 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 at

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
Skype is a software application that allows users to make voice and video calls and chat over the Internet. Calls to other users within the Skype service are free, while calls to both traditional landline telephones and mobile phones can be made for a fee using a debit-based user account system...

, FL Studio
FL Studio
FL Studio is a digital audio workstation developed by the Belgian company Image-Line. FL Studio features a graphical user interface based on a pattern-based music sequencer...

, and Embarcadero
Embarcadero
Embarcadero may refer to:* Embarcadero , California** Embarcadero Circle, waterfront re-development project* Embarcadero , California** Embarcadero Center, office complex** Embarcadero Freeway, former California State Route 480...

’s own RAD Studio. Hallvard's blog describes FastMM4 and why it is being used as the memory manager in "The Online Trader" application.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK