Daniel Lemire's blog

, 3 min read

Packing a string of digits into an integer quickly

5 thoughts on “Packing a string of digits into an integer quickly”

  1. Costin says:

    Small typo:
    “Recent Intel processors have performance on par with Intel”
    should be Recent AMD (or Zen) processors have performance…

  2. jerch says:

    (offtopic)

    I wonder if there is a really fast SIMD-based calculation possible for itoa, maybe something along bitfield multiplication and pext extraction steps. Had to deal with it recently and was quite surprised, how hard the binary number to decimal digits conversion still is.

    @Lemire Do you happen to have dealt with that in the past, or have some good pointers? Sorry if I overlooked it.

      1. jerch says:

        Many thanks you for the link. At a first glance it seems that I also went with the small table approach (2 digits lookup after divmod 100). Will see if I can get that somewhat faster without going into big table realms.

    1. Here is the optimized implementation from ClickHouse:
      https://github.com/ClickHouse/ClickHouse/blob/master/base/base/itoa.h

      No SIMD there, though.