Skip to content

Instantly share code, notes, and snippets.

@stedolan
Last active July 21, 2020 14:01
Show Gist options
  • Save stedolan/0b37837260ee3cc8e355339f992c448a to your computer and use it in GitHub Desktop.
Save stedolan/0b37837260ee3cc8e355339f992c448a to your computer and use it in GitHub Desktop.
external unsafe_set_imm : ('a : immediate) . 'a array -> int -> 'a -> unit = "%array_unsafe_set"
type ('a : value) is_immediate =
| Immediate : ('b : immediate) . 'b is_immediate
| Value : 'a is_immediate
let fill (type a) (e : a is_immediate) (arr : a array) (x : a) =
match e with
| Immediate ->
for i = 0 to Array.length arr - 1 do
unsafe_set_imm arr i x
done
| Value ->
for i = 0 to Array.length arr - 1 do
Array.unsafe_set arr i x
done
(function{hax/gadt.ml:8,9-275} camlGadt__fill_84
(e/86: val arr/87: val x/88: val)
(if (!= e/86 1)
(seq
(let_mut i/141: int 1
(let bound/149 (+ (or (>>u (load_mut int (+a arr/87 -8)) 9) 1) -2)
(catch
(if (> i/141 bound/149) (exit 3)
(catch rec (exit 4) with(4)
(if (!= (load_mut unsigned int8 (+a arr/87 -8)) 254)
(extcall "caml_modify"{hax/gadt.ml:16,7-31}
(+a (+a arr/87 (<< i/141 2)) -4) x/88 unit)
(store float64u (+a (+a arr/87 (<< i/141 2)) -4)
(load float64u x/88)))
(let *id_prev*/148 i/141 (assign i/141 (+ i/141 2))
(if (== *id_prev*/148 bound/149) (exit 3) []))
(exit 4)))
with(3) [])))
1a)
(seq
(let_mut i/140: int 1
(let bound/147 (+ (or (>>u (load_mut int (+a arr/87 -8)) 9) 1) -2)
(catch
(if (> i/140 bound/147) (exit 1)
(catch rec (exit 2) with(2)
(store int (+a (+a arr/87 (<< i/140 2)) -4) x/88)
(let *id_prev*/146 i/140 (assign i/140 (+ i/140 2))
(if (== *id_prev*/146 bound/147) (exit 1) []))
(exit 2)))
with(1) [])))
1a)))
camlGadt__fill_84:
.cfi_startproc
subq $8, %rsp
.cfi_adjust_cfa_offset 8
.L108:
movq %rdi, %r13
cmpq $1, %rax
je .L103
movl $1, %r12d
movq -8(%rbx), %rbp
shrq $9, %rbp
orq $1, %rbp
addq $-2, %rbp
cmpq %rbp, %r12
jg .L104
.L105:
movzbq -8(%rbx), %rax
cmpq $254, %rax
je .L107
leaq -4(%rbx,%r12,4), %rdi
movq %r13, %rsi
call caml_modify@PLT
jmp .L106
.align 4
.L107:
movsd (%r13), %xmm0
movsd %xmm0, -4(%rbx,%r12,4)
.L106:
movq %r12, %rax
addq $2, %r12
cmpq %rbp, %rax
jne .L105
.L104:
movl $1, %eax
addq $8, %rsp
.cfi_adjust_cfa_offset -8
ret
.cfi_adjust_cfa_offset 8
.align 4
.L103:
movl $1, %eax
movq -8(%rbx), %rdi
shrq $9, %rdi
orq $1, %rdi
addq $-2, %rdi
cmpq %rdi, %rax
jg .L101
.L102:
movq %r13, -4(%rbx,%rax,4)
movq %rax, %rsi
addq $2, %rax
cmpq %rdi, %rsi
jne .L102
.L101:
movl $1, %eax
addq $8, %rsp
.cfi_adjust_cfa_offset -8
ret
.cfi_adjust_cfa_offset 8
.cfi_adjust_cfa_offset -8
.cfi_endproc
.type camlGadt__fill_84,@function
.size camlGadt__fill_84,. - camlGadt__fill_84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment