emRun

Most toolchains using GCC or LLVM also use either newlib, newlib-nano or glibc. Unfortunately, these libraries have significant disadvantages over professional runtime libraries for embedded systems. This is where emRun comes in. It can be used with GCC, LLVM, and other toolchains to provide a runtime library designed and engineered for embedded systems. Written from the ground up for embedded devices, emRun enables a high degree of optimization with low requirements.

emRun is a complete C runtime library for use with any toolchain. It converts any GCC/LLVM-based toolchain into a professional development choice. emRun is used in SEGGER’s Embedded Studio IDE and has proven its value for years.

  • Highly optimized functions that, when used, avoid the inclusion of additional support functions (e.g. printf) that are aren’t needed
  • Formatted input and output functions are customizable from basic I/O to fully featured I/O, enabling reduction of final code footprint
  • Full support for localization, UTF-8, code pages, and locale codecs is only linked if used

In many cases, the ROM-savings of emRun enable the use of a smaller microcontroller with less on-chip memory. This can result in significant cost savings, especially for devices built in large quantities for the mass market.

Being a simple replacement for libraries, such as newlib or newlib-nano, emRun shrinks and accelerates embedded applications. Whether the main concern with newlib is flash size, performance, or the attribution clause of the viral licensing, the SEGGER Runtime Library emRun is the solution.

Key features

  • High performance, with time-critical routines written in assembly language
  • Significant code size reduction
  • Configurable for high speed or small size
  • Includes SEGGER’s optimized floating-point library emFloat
  • Designed for use with various toolchains
  • EABI compatible functions
  • Minimum RAM usage
  • No heap requirements
  • No viral licensing, no attribution clause

Licensing

emRun can be licensed in source code to individual companies as well as be included as libraries by providers of toolchains.

  • Source code makes it possible to step through library functions
  • Many functions can be tuned with different implementations for size-optimized code and speed-optimized code

emRun is also available in generic “C” code to run on any system. Additionally assembly optimized variants are available for:

  • Arm (Cortex-M and Cortex-A 32-bit)
  • RISC-V (RV32M)

Ports for other CPUs can be made available on request.

Performance tuning — speed and size

The performance of a runtime library can have a huge impact on the speed of an application. Despite trying to avoid library functions (sprintf(), memcpy(), memcmp() etc) the compiler will make you call library functions, such as for division and multiplication, that you do not see, especially when dealing with floating point or 64-bit operations, Here the choice of the right runtime library makes all the difference.

emRun uses enhanced, highly advanced low-level implementations for such operations, which can be fine-tuned for speed or size. With the assembly-optimized variants, performance can be even more optimized by using the target platform to its full potential.

Performance

RISC-V (32-Bit)

Runtime [Cycles]
Test ProjectemRun [2]gcc / newlib [3]
Floating-Point Arithmetic1097.41907.0
Floating-Point Math714.031814.36
Integer Arithmetic251.21041.77
String and Memory Functions1714120733

RISC-V (64-Bit)

Runtime [Cycles]
Test ProjectemRun [4]gcc / newlib [5]
Floating-Point Arithmetic826.81684.4
Floating-Point Math734.711712.70
Integer Arithmetic19.01560.6
String and Memory Functions1043017633

ARM (32-Bit)

Runtime [Cycles]
Test ProjectemRun [6]gcc / newlib [7]
Floating-Point Arithmetic821.02618.8
Floating-Point Math544.321003.35
Integer Arithmetic122.3195.7
String and Memory Functions1069617332

[2] SEGGER Embedded Studio for RISC-V version 6.40, GNU Toolchain, emRun 4.22.0, RV32IMAC

[3] SEGGER Embedded Studio for RISC-V version 6.34, GNU Toolchain, libgcc 12.1.0 and newlib 4.1.0, RV32IMAC

[4] SEGGER Embedded Studio for RISC-V version 6.40, GNU Toolchain, emRun 4.22.0, RV64IMAC

[5] SEGGER Embedded Studio for RISC-V version 6.34, GNU Toolchain, libgcc 12.1.0 and newlib 4.1.0, RV64IMAC

[6] SEGGER Embedded Studio for ARM version 6.34, GNU Toolchain, emRun 4.18.0, ARMv7M

[7] SEGGER Embedded Studio for ARM version 6.34, GNU Toolchain, libgcc 9.0 and newlib 3.3.0, ARMv7M

Memory requirements

emRun offers significant savings in flash memory. This is partly due to some functions being hand-coded in assembly language, but primarily due to a structure that minimizes internal library dependencies, for example the file I/O not being linked in with printf() or scanf().

emRun also uses less static RAM due to a structure designed from the ground up for embedded systems.

Benchmark code:

emRun Benchmark Code

SEGGER did some benchmarking on emRun using NXP’s MCUXpresso as a representative IDE that might benefit from using emRun. The benchmark consists of a simple “printf()” with output to a debug terminal. We compared the results for emRun with the results for three other C libraries (Newlib, Newlib-nano, and Redlib). In each case, printf() was configured for the smallest possible size (size-optimized libraries, no floating point…). We then also tested with our own IDE, Embedded Studio, with the same code, using emRun, in one case using the GNU Linker, in another case using the SEGGER Linker.

Test EnvironmentTest project: Simple “main” project with “printf()”
ROM UsageRAM Usage
MCUXpresso1, Newlib31888 bytes2864 bytes
MCUXpresso, Redlib9940 bytes728 bytes
MCUXpresso, Newlib-nano9552 bytes416 bytes
MCUXpresso, SEGGER RunTime Library4392 bytes184 bytes
Embedded Studio2, SEGGER emRun, GNU Linker2502 bytes0 bytes
Embedded Studio, SEGGER emRun, SEGGER Linker1868 bytes0 bytes
Embedded Studio, SEGGER emRun, SEGGER Linker, Host Formatting818 bytes8 bytes

1: MCUXpresso IDE v3.1.0-2200 and SDK 2.5.0 for the Freedom K66F board
2: Embedded Studio 4.16 with the Kinetis K60 CPU Support Package v1.02

Implementation & configuration

emRun can be used with any GCC-based IDE/toolchain by replacing the runtime library delivered with that toolchain (usually newlib, newlib-nano, or some other variant) with emRun.

Examples include:

  • AC6 System Workbench for STM32 (SW4STM32)
  • Atmel Studio 7
  • Atollic TrueStudio for STM32
  • NXP MCUXpresso
  • Renesas e2 studio (for Synergy or RZ targets)
  • SiLabs Simplicity Studio

In SEGGER Embedded Studio and Rowley CrossWorks, emRun is already included as the default C library.

Library verification

To verify the functionality of emRun, we created and used our verification test suite. It checks the entire functionality of all library functions, including the entire floating point library with all corner cases.

More than 450 different tests with millions of test cases are executed. Below an exert for just a single test for sys_float64_add(), adding 64-bit doubles:

emRUN Library

If you are interested in replaying our results, or want to verify the library you currently use, or plan to develop your own runtime library, the SEGGER Runtime Library Verification Test Suite is available.