ArticleslgStudy

computer science

FastCode

FastCode is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand FastCode rather than just read about it. In short: 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).

Key takeaways

  • FastCode belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect FastCode to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of FastCode from memory before moving on to harder problems.

Reference excerpt

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). 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. 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, 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 is [1], 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 [2].

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 [3]:

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 (https://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. 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 in "The New Memory Manager In BDS 2006".

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with FastCode

Start with the simplest possible case. Write down what FastCode claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to FastCode before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about FastCode ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of FastCode

In research
FastCode appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses FastCode in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
FastCode is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer libraries, Delphi (software), Programming contests, so understanding it makes those chapters shorter.
In everyday life
Look for FastCode outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “FastCode” →

How to study FastCode in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what FastCode means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain FastCode out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is FastCode in simple terms?

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…

Why does FastCode matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study FastCode?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on FastCode.

Tags

  • Computer libraries
  • Delphi (software)
  • Programming contests

Keep exploring