FastCode

Last updated

FastCode is an open source programming project that aims to provide optimized runtime library routines for Embarcadero Delphi and C++ Builder. This community-driven project was started in 2003 by Dennis Kjaer Christensen and has since contributed optimized functionality to the 32-bit Delphi runtime library (RTL).

Contents

Organized as a competition divided into challenges, FastCode focuses on optimizing specific functions against multiple targets. The project offers benchmarking tools and validation processes for each function contribution. Contributions are scored, with points awarded based on performance against the targets. Embarcadero recognizes and incorporates the code created by the FastCode team into their Delphi codebase. Most participants in this project are assembler developers who utilize processor-specific code. The list of challenges tackled by the FastCode project is extensive; it covers diverse areas ranging from string manipulation functions like PosEx or CompareText to mathematical operations such as Power or Int64Mul.

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 and Embarcadero, the owners of Delphi and C++ Builder, 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, SSE3, SSSE3 and SSE4. [1]

The project enjoys the support of Embarcadero who recognizes the contributions of the FastCode team and incorporates their code into the codebase for Delphi. [2] The default memory manager for Embarcadero Delphi, FastMM4, is the winner of the FastCode Memory Manager challenge. [3]

The project was first hosted on Robert Lee's OptimalCode site, and its source code's home page is , 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 at .

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 Vista, 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 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, Intel Core, Intel Core 2, 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 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 challenges :

Contributions to Delphi RTL

FastCode functions included in the Delphi RTL:

The Mastering Delphi books by Marco Cantu contains a chapter about FastCode listing the contributions to the Delphi RTL. [6]

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, 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. [7] 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, [8] detecting use after memory release or double releases.

FastMM4 is also used as memory manager for applications developed in Lazarus. [9]

FastMM4 is often listed as a "must have" tool for Delphi developers. [10]

Nexus DB comes with FastMM4 integration for leakchecking. [11]

FastMM usage is documented in "The New Memory Manager In BDS 2006". [12]

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, FL Studio, and Embarcadero’s own RAD Studio. Hallvard's blog describes FastMM4 and why it is being used as the memory manager in "The Online Trader" application.

Related Research Articles

<span class="mw-page-title-main">Hash function</span> Mapping arbitrary data to fixed-size values

A hash function is any function that can be used to map data of arbitrary size to fixed-size values, though there are some hash functions that support variable length output. The values returned by a hash function are called hash values, hash codes, hash digests, digests, or simply hashes. The values are usually used to index a fixed-size table called a hash table. Use of a hash function to index a hash table is called hashing or scatter storage addressing.

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

PackBits is a fast, simple lossless compression scheme for run-length encoding of data.

<span class="mw-page-title-main">String (computer science)</span> Sequence of characters, data type

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed. A string is generally considered as a data type and is often implemented as an array data structure of bytes that stores a sequence of elements, typically characters, using some character encoding. String may also denote more general arrays or other sequence data types and structures.

<span class="mw-page-title-main">Endianness</span> Order of bytes in a computer word

In computing, endianness is the order in which bytes within a word of digital data are transmitted over a data communication medium or stored (upwardly) in computer memory, counting only byte significance compared to earliness. Endianness is primarily expressed as big-endian (BE) or little-endian (LE), terms introduced by Danny Cohen into computer science for data ordering in an Internet Experiment Note published in 1980. The adjective endian has its origin in the writings of 18th century Anglo-Irish writer Jonathan Swift. In the 1726 novel Gulliver's Travels, he portrays the conflict between sects of Lilliputians divided into those breaking the shell of a boiled egg from the big end or from the little end. By analogy, a CPU may read a digital word big end first, or little end first.

In computer architecture, 64-bit integers, memory addresses, or other data units are those that are 64 bits wide. Also, 64-bit central processing units (CPU) and arithmetic logic units (ALU) are those that are based on processor registers, address buses, or data buses of that size. A computer that uses such a processor is a 64-bit computer.

x86 assembly language is the name for the family of assembly languages which provide some level of backward compatibility with CPUs back to the Intel 8008 microprocessor, which was launched in April 1972. It is used to produce object code for the x86 class of processors.

C++Builder is a rapid application development (RAD) environment for developing software in the C++ programming language. Originally developed by Borland, as of 2009 it is owned by Embarcadero Technologies, a subsidiary of Idera. C++Builder can compile apps for Windows, iOS, macOS, and Android. It includes tools that allow drag-and-drop visual development, making programming easier by incorporating a WYSIWYG graphical user interface builder.

<span class="mw-page-title-main">Delphi (software)</span> General-purpose programming language and a software product

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, mobile, web, and console software, currently developed and maintained by Embarcadero Technologies.

<span class="mw-page-title-main">Pointer (computer programming)</span> Object which stores memory addresses in a computer program

In computer science, a pointer is an object in many programming languages that stores a memory address. This can be that of another value located in computer memory, or in some cases, that of memory-mapped computer hardware. A pointer references a location in memory, and obtaining the value stored at that location is known as dereferencing the pointer. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number and reading the text found on that page. The actual format and content of a pointer variable is dependent on the underlying computer architecture.

In cryptography, a timing attack is a side-channel attack in which the attacker attempts to compromise a cryptosystem by analyzing the time taken to execute cryptographic algorithms. Every logical operation in a computer takes time to execute, and the time can differ based on the input; with precise measurements of the time for each operation, an attacker can work backwards to the input. Finding secrets through timing information may be significantly easier than using cryptanalysis of known plaintext, ciphertext pairs. Sometimes timing information is combined with cryptanalysis to increase the rate of information leakage.

<span class="mw-page-title-main">TI BASIC (TI 99/4A)</span> Programming language for TI-99 home computers

TI BASIC is an ANSI-compliant interpreter for the BASIC programming language built into the 1979 Texas Instruments TI-99/4 home computer and its improved 1981 version, the TI-99/4A.

In computer science, the Boyer–Moore string-search algorithm is an efficient string-searching algorithm that is the standard benchmark for practical string-search literature. It was developed by Robert S. Boyer and J Strother Moore in 1977. The original paper contained static tables for computing the pattern shifts without an explanation of how to produce them. The algorithm for producing the tables was published in a follow-on paper; this paper contained errors which were later corrected by Wojciech Rytter in 1980.

String functions are used in computer programming languages to manipulate a string or query information about a string.

In the x86 architecture, the CPUID instruction is a processor supplementary instruction allowing software to discover details of the processor. It was introduced by Intel in 1993 with the launch of the Pentium and SL-enhanced 486 processors.

This article describes the calling conventions used when programming x86 architecture microprocessors.

The x32 ABI is an application binary interface (ABI) and one of the interfaces of the Linux kernel. The x32 ABI provides 32-bit integers, long and pointers (ILP32) on Intel and AMD 64-bit hardware. The ABI allows programs to take advantage of the benefits of x86-64 instruction set while using 32-bit pointers and thus avoiding the overhead of 64-bit pointers.

<span class="mw-page-title-main">BASIC interpreter</span> Interpreter that enables users to enter and run programs in the BASIC language

A BASIC interpreter is an interpreter that enables users to enter and run programs in the BASIC language and was, for the first part of the microcomputer era, the default application that computers would launch. Users were expected to use the BASIC interpreter to type in programs or to load programs from storage.

This page details the history of the programming language and software product Delphi.

Acorn System BASIC and Atom BASIC are two closely related dialects of the BASIC programming language developed by Acorn Computers for their early microcomputers like the Acorn System 3 and Acorn Atom. Developed in-house, they have a number of significant idiosyncrasies compared to most BASIC dialects of the home computer era.

References

  1. "How to Optimize Delphi Application Performance to the Max using FastCode Library" . Retrieved 3 September 2015.
  2. "Nick Hodges" . Retrieved 3 September 2015.
  3. 1 2 "The Oracle at Delphi" . Retrieved 3 September 2015.
  4. Long, Brian & Swart, Bob, "Borland Developer Studio 2006 Reviewed", The Delphi Magazine, Issue 124, December 2005
  5. "Community contributions improve Delphi 2007 RTL performance". Archived from the original on 6 March 2016. Retrieved 3 September 2015.
  6. "Mastering Delphi Update for Delphi 2006" . Retrieved 3 September 2015.
  7. Gabrijelcic, Primoz, "To Manage Memory", The Delphi Magazine, Issue 126, February 2006
  8. "FastMM4" . Retrieved 3 September 2015.
  9. "Lazarus Free Pascal" . Retrieved 3 September 2015.
  10. "Good Tools for Delphi Developers". Delphi Programming. Retrieved 3 September 2015.
  11. "NexusDB" . Retrieved 3 September 2015.
  12. "The New Memory Manager In BDS 2006 - by Pierre le Riche" . Retrieved 3 September 2015.