C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Slow bulky integer types (128-bit)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 29 Mar 2023 23:32:17 +0100
On Wed, Mar 29, 2023 at 8:07 PM Lénárd Szolnoki via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> AFAIK _BitInt(N) is in C23, not sure if integral or if there is a lowish limit to N.


The LLVM compiler, i.e. clang, has _BitInt, see up on Godbolt:

        https://godbolt.org/z/eqhvxjxdG

The following function:

      void Func(_BitInt(256) *const parg)
      {
          *parg += 73;
      }

gets compiled to:

      Func:
      addq $0x49,(%rdi)
      adcq $0x0,0x8(%rdi)
      adcq $0x0,0x10(%rdi)
      adcq $0x0,0x18(%rdi)
      ret

In future I might use this for encryption, e.g. 128-bit blocks for
encryption, and 256-Bit hash digests.

Let me see if it can do a 1024-Bit type. The following function:

void Func(_BitInt(1024) *const parg)
{
    *parg += 73;
}

gets compiled to:

Func:
 addq $0x49,(%rdi)
 adcq $0x0,0x8(%rdi)
 adcq $0x0,0x10(%rdi)
 adcq $0x0,0x18(%rdi)
 adcq $0x0,0x20(%rdi)
 adcq $0x0,0x28(%rdi)
 adcq $0x0,0x30(%rdi)
 adcq $0x0,0x38(%rdi)
 adcq $0x0,0x40(%rdi)
 adcq $0x0,0x48(%rdi)
 adcq $0x0,0x50(%rdi)
 adcq $0x0,0x58(%rdi)
 adcq $0x0,0x60(%rdi)
 adcq $0x0,0x68(%rdi)
 adcq $0x0,0x70(%rdi)
 adcq $0x0,0x78(%rdi)
 ret

That's pretty cool.

Received on 2023-03-29 22:32:29