LLVM arbitrary precision integer

GdelP

LLVM language reference states that

The integer type is a very simple type that simply specifies an arbitrary bit width for the integer type desired. Any bit width from 1 bit to 223-1 (about 8 million) can be specified.

Does that mean that I can make use of arbitrary fixed length integers for free? That's to say, if I declare an i100, will I have a variable with 100 bits width?

Stephen Diehl

I'm not entirely sure what you mean by "free", but yes LLVM will let you do it and compile it on some platforms. But it's going to come at a cost as opposed to types sized on multiples of the CPU registers.

If you create a i100 it allocate a block of 100 bits on the stack. If you do operations over it you will be limited to to whatever the CPU provides for instruction set. If you want to add two 64 bit integers the IR would look like:

define i64 @add(i64 %a, i64 %b) {
  %1 = add i64 %a, %b
  ret i64 %1
}

Then we get our generated assembly which is usually one instruction:

add:                                    # @add
    .cfi_startproc
# BB#0:
    addq    %rsi, %rdi
    movq    %rdi, %rax
    ret

But for instance, if you work we wanted to add two i1024 integers in the following IR:

define i1024 @add(i1024 %a, i1024 %b) {
  %1 = add i1024 %a, %b
  ret i1024 %1
}

Then the generated assembly on for x86-64 system is this not-terribly efficient collection of instructions, a lot of which are just mov'ing memory around memory.

add:                                    # @add
    .cfi_startproc
# BB#0:
    pushq   %r15
.Ltmp5:
    .cfi_def_cfa_offset 16
    pushq   %r14
.Ltmp6:
    .cfi_def_cfa_offset 24
    pushq   %r12
.Ltmp7:
    .cfi_def_cfa_offset 32
    pushq   %rbx
.Ltmp8:
    .cfi_def_cfa_offset 40
.Ltmp9:
    .cfi_offset %rbx, -40
.Ltmp10:
    .cfi_offset %r12, -32
.Ltmp11:
    .cfi_offset %r14, -24
.Ltmp12:
    .cfi_offset %r15, -16
    movq    40(%rsp), %r10
    addq    128(%rsp), %rsi
    adcq    136(%rsp), %rdx
    adcq    144(%rsp), %rcx
    adcq    152(%rsp), %r8
    adcq    160(%rsp), %r9
    movq    96(%rsp), %r14
    movq    104(%rsp), %r11
    movq    80(%rsp), %r12
    movq    88(%rsp), %r15
    adcq    168(%rsp), %r10
    movq    64(%rsp), %rax
    movq    72(%rsp), %rbx
    movq    %rsi, (%rdi)
    movq    %rdx, 8(%rdi)
    movq    48(%rsp), %rsi
    movq    56(%rsp), %rdx
    movq    %rcx, 16(%rdi)
    movq    %r8, 24(%rdi)
    movq    %r9, 32(%rdi)
    movq    112(%rsp), %rcx
    movq    120(%rsp), %r8
    adcq    176(%rsp), %rsi
    adcq    184(%rsp), %rdx
    adcq    192(%rsp), %rax
    adcq    200(%rsp), %rbx
    adcq    208(%rsp), %r12
    adcq    216(%rsp), %r15
    adcq    224(%rsp), %r14
    movq    %r10, 40(%rdi)
    movq    %rsi, 48(%rdi)
    movq    %rdx, 56(%rdi)
    movq    %rax, 64(%rdi)
    movq    %rbx, 72(%rdi)
    movq    %r12, 80(%rdi)
    movq    %r15, 88(%rdi)
    movq    %r14, 96(%rdi)
    adcq    232(%rsp), %r11
    movq    %r11, 104(%rdi)
    adcq    240(%rsp), %rcx
    movq    %rcx, 112(%rdi)
    adcq    248(%rsp), %r8
    movq    %r8, 120(%rdi)
    popq    %rbx
    popq    %r12
    popq    %r14
    popq    %r15
    ret

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

LLVM arbitrary precision integer

From Dev

Is Python incorrectly handling this "arbitrary precision integer"?

From Dev

Python mpmath not arbitrary precision?

From Dev

VIVADO HLS:How to declare arbitrary precision (or bit-accurate) integer data types for 2D array?

From Dev

Fixed precision vs. arbitrary precision

From Dev

arbitrary floating precision number to string

From Dev

"Multiplication of Arbitrary Precision Numbers" in Scheme

From Dev

stripe node arbitrary precision number

From Dev

Fortran integer precision mixing

From Dev

Specify Integer Precision gfortran

From Dev

Arbitrary precision for decimals square roots in golang

From Dev

Fast arbitrary-precision logarithms with bcmath

From Dev

postgresql date_trunc to arbitrary precision?

From Dev

Arbitrary precision arithmetic with very big factorials

From Dev

Arbitrary precision arithmetic with very big factorials

From Dev

Calculate Pi with arbitrary precision digit by digit

From Dev

Getting the size in bytes of an arbitrary integer

From Dev

LLVM, Global integer array zeroinitializer

From Dev

LLVM, Global integer array zeroinitializer

From Dev

Python - Precision Loss With Large Integer

From Dev

Python - Precision Loss With Large Integer

From Dev

fast double multiplication with integer precision

From Dev

meaning of llvm[n] when compiling llvm, where n is an integer

From Dev

Python float precision with no integer precision after decimal point

From Dev

BBP-Algorithm in Python - Working with Arbitrary-precision arithmetic

From Dev

Calculating pi without arbitrary precision and only basic arithmetic

From Dev

Which programming languages have arbitrary precision floating-point literals?

From Dev

Is it possible to achieve arbitrary-precision arithmetic with no rounding issues in JavaScript?

From Dev

Hash an arbitrary precision value (boost::multiprecision::cpp_int)

Related Related

  1. 1

    LLVM arbitrary precision integer

  2. 2

    Is Python incorrectly handling this "arbitrary precision integer"?

  3. 3

    Python mpmath not arbitrary precision?

  4. 4

    VIVADO HLS:How to declare arbitrary precision (or bit-accurate) integer data types for 2D array?

  5. 5

    Fixed precision vs. arbitrary precision

  6. 6

    arbitrary floating precision number to string

  7. 7

    "Multiplication of Arbitrary Precision Numbers" in Scheme

  8. 8

    stripe node arbitrary precision number

  9. 9

    Fortran integer precision mixing

  10. 10

    Specify Integer Precision gfortran

  11. 11

    Arbitrary precision for decimals square roots in golang

  12. 12

    Fast arbitrary-precision logarithms with bcmath

  13. 13

    postgresql date_trunc to arbitrary precision?

  14. 14

    Arbitrary precision arithmetic with very big factorials

  15. 15

    Arbitrary precision arithmetic with very big factorials

  16. 16

    Calculate Pi with arbitrary precision digit by digit

  17. 17

    Getting the size in bytes of an arbitrary integer

  18. 18

    LLVM, Global integer array zeroinitializer

  19. 19

    LLVM, Global integer array zeroinitializer

  20. 20

    Python - Precision Loss With Large Integer

  21. 21

    Python - Precision Loss With Large Integer

  22. 22

    fast double multiplication with integer precision

  23. 23

    meaning of llvm[n] when compiling llvm, where n is an integer

  24. 24

    Python float precision with no integer precision after decimal point

  25. 25

    BBP-Algorithm in Python - Working with Arbitrary-precision arithmetic

  26. 26

    Calculating pi without arbitrary precision and only basic arithmetic

  27. 27

    Which programming languages have arbitrary precision floating-point literals?

  28. 28

    Is it possible to achieve arbitrary-precision arithmetic with no rounding issues in JavaScript?

  29. 29

    Hash an arbitrary precision value (boost::multiprecision::cpp_int)

HotTag

Archive