# The New Clang \_ExtInt Feature Provides Exact Bitwidth Integer Types

DevFeed: [The New Clang \_ExtInt Feature Provides Exact Bitwidth Integer Types](<https://devfeed.tech/articles/the-new-clang-extint-feature-provides-exact-bitwidth-integer-types-43068.md>)

Original publisher: [Read original article](<https://blog.llvm.org/2020/04/the-new-clang-extint-feature-provides.html>)

Author: Erich Keane

Published: 2020-04-21T17:13:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [clang](<https://devfeed.tech/topics/clang.md>), [C](<https://devfeed.tech/topics/c.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [fpga](<https://devfeed.tech/topics/fpga.md>), [LLVM](<https://devfeed.tech/topics/llvm.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Hardware](<https://devfeed.tech/topics/hardware.md>)

Tags: [c](<https://devfeed.tech/tags/c.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [fpga](<https://devfeed.tech/tags/fpga.md>), [hardware](<https://devfeed.tech/tags/hardware.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

The article introduces Clang's _ExtInt feature for exact-width integer types, such as 13-bit signed integers. It explains how the feature connects C and LLVM integer capabilities and addresses inefficient integer widths in FPGA high-level synthesis.

## Source excerpt

Author: Erich Keane, Compiler Frontend Engineer, Intel Corporation Earlier this month I finally committed a patch to implement the extended-integer type class, _ExtInt after nearly two and a half years of design and implementation. These types allow developers to use custom width integers, such as a 13-bit signed integer. This patch is currently designed to track N2472, a proposal being actively considered by the ISO WG14 C Language Committee. We feel that these types are going to be extremely useful to many downstream users of Clang, and provides a language interface for LLVM's extremely powerful integer type class. MotivationLLVM-IR has the ability to represent integers with a bitwidth from 1 all the way to 16,777,215((1<<24)-1), however the C language is limited to just a few power-of-two sizes. Historically, these types have been sufficient for nearly all programming architectures, since power-of-two representation of integers is convenient and practical. Recently, Field-Programmable Gate Array (FPGA) tooling, called High Level Synthesis Compilers (HLS), has become practical and powerful enough to use a general purpose programming language for their generation. These tools take C or C++ code and produce a transistor layout to be used by the FPGA. However, once programmers gained experience in these tools, it was discovered that the standard C integer types are incredibly wasteful for two main reasons. First, a vast majority of the time programmers are not using the full width of their integer types. It is rare for someone to use all 16, 32, or 64 bits of their integer representation. On traditional CPUs this isn't much of a problem as the hardware is already in place, so having bits never set comes at zero cost. On the other hand, on FPGAs logic gates are an incredibly valuable resource, and HLS compilers should not be required to waste bits on large power of two integers when they only need a small subset of that! While the optimizer passes are capable of remov