Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"In the file called test_asm.ml the function f

    let f a = a+1
"The generated asm looks like the following:"

      camlTest_asm__f_33700:
      .L119:
          addq    $2, %rax
          ret
You sure about that? $2?


From the article:

Unlike floats, ints are represented as immediates, i.e., they are not allocated on the heap. To tag ints OCaml steals the LSB bit of an int and sets it to 1 always. This means that we get 63 bits of precision in OCaml ints and any int value n will appear in the assembly as 2*n+1 (the LSB is always 1 and the bits of the number shifted one place in).


"Unlike floats, ints are represented as immediates, i.e., they are not allocated on the heap. To tag ints OCaml steals the LSB bit of an int and sets it to 1 always. This means that we get 63 bits of precision in OCaml ints and any int value n will appear in the assembly as 2n+1 (the LSB is always 1 and the bits of the number shifted one place in).*"

Crap. Forgot about the tag bit. :-)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: