Arm64 backend detail

in arm64/proc.ml there is this mapping of integer index to names of registers:


let int_reg_name =
  [| "x0";  "x1";  "x2";  "x3";  "x4";  "x5";  "x6";  "x7";  (* 0 - 7 *)
     "x8";  "x9";  "x10"; "x11"; "x12"; "x13"; "x14"; "x15"; (* 8 - 15 *)
     "x19"; "x20"; "x21"; "x22"; "x23"; "x24"; "x25";        (* 16 - 22 *)
     "x26"; "x27"; "x28";                                    (* 23 - 25 *)
     "x16"; "x17" |]                                         (* 26 - 27 *)

given that x16 is not at index 16 but 26 and x26 is at index 23, is this a hardware scheme (I can’t find anything on it in the ARM reference) or a reflection of something else, perhaps priority?

This is just an implementation detail. The number of each register is used to represent registers by integers in the register allocator and also to propagate the information of which registers are live at each program point to the garbage collector (the “frame table”). All native backends are treated similarly.

Cheers,
Nicolas

gaps due to unuseable registers (eg x18) I can understand but x16/x17 placed at the end - why the disordering?

I don’t know exactly for arm64, but in general allocatable registers (those used by the register allocator) should be in sequential order so that can be interpreted as array indices. And the role for each register is also a function of whether it is caller- or callee- save in the standard C calling convention in order to work well in OCaml/C function calls. These factors often lead to numberings which may not be the most natural ones.

Cheers,
Nicolas