Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does OCaml have a popcnt function?

Can the popcnt, bsf, bsr and lzcnt instructions be generated in native OCaml on x86 CPUs?

like image 839
Anthony Scemama Avatar asked Feb 21 '26 18:02

Anthony Scemama


1 Answers

I have OCaml 4.01.0 sources handy, and for this it's pretty easy to check. If you look for these instructions in the code generation sources, they do not appear.

$ pwd
/home/jeffsco/oc41/asmcomp/i386
$ ls
arch.ml       emit_nt.mlp   reload.ml     selection.ml
emit.mlp      proc.ml       scheduling.ml
$ grep -w popcnt *
$ grep -w bsf *
$ grep -w bsr *
$ grep -w lzcnt *

If I look for something like movl I get plenty of hits:

$ grep -w movl *
emit.mlp:              `    movl    {emit_reg src}, {emit_reg dst}\n`
emit.mlp:          | _     -> ` movl    $0, {emit_reg i.res.(0)}\n`
. . .

So, I strongly suspect the answer is no. Perhaps things have changed for OCaml 4.02, but I doubt it.

like image 124
Jeffrey Scofield Avatar answered Feb 24 '26 06:02

Jeffrey Scofield