Skip to content

Instantly share code, notes, and snippets.

@thata
Created June 16, 2022 13:19
Show Gist options
  • Save thata/12bef4c84ca82bd250d88eab33f0da53 to your computer and use it in GitHub Desktop.
Save thata/12bef4c84ca82bd250d88eab33f0da53 to your computer and use it in GitHub Desktop.
diff min-caml-ppc min-caml-x86
Common subdirectories: min-caml-ppc/.git and min-caml-x86/.git
Common subdirectories: min-caml-ppc/PowerPC and min-caml-x86/PowerPC
Common subdirectories: min-caml-ppc/SPARC and min-caml-x86/SPARC
diff min-caml-ppc/asm.ml min-caml-x86/asm.ml
1c1
< (* PowerPC assembly with a few virtual instructions *)
---
> (* 2オペランドではなく3オペランドのx86アセンブリもどき *)
9,10c9
< | Li of int
< | FLi of Id.l
---
> | Set of int
12c11
< | Mr of Id.t
---
> | Mov of Id.t
16,26c15,24
< | Slw of Id.t * id_or_imm
< | Lwz of Id.t * id_or_imm
< | Stw of Id.t * Id.t * id_or_imm
< | FMr of Id.t
< | FNeg of Id.t
< | FAdd of Id.t * Id.t
< | FSub of Id.t * Id.t
< | FMul of Id.t * Id.t
< | FDiv of Id.t * Id.t
< | Lfd of Id.t * id_or_imm
< | Stfd of Id.t * Id.t * id_or_imm
---
> | Ld of Id.t * id_or_imm * int
> | St of Id.t * Id.t * id_or_imm * int
> | FMovD of Id.t
> | FNegD of Id.t
> | FAddD of Id.t * Id.t
> | FSubD of Id.t * Id.t
> | FMulD of Id.t * Id.t
> | FDivD of Id.t * Id.t
> | LdDF of Id.t * id_or_imm * int
> | StDF of Id.t * Id.t * id_or_imm * int
46,51c44,46
< let regs = (* Array.init 27 (fun i -> Printf.sprintf "_R_%d" i) *)
< [| "%r2"; "%r5"; "%r6"; "%r7"; "%r8"; "%r9"; "%r10";
< "%r11"; "%r12"; "%r13"; "%r14"; "%r15"; "%r16"; "%r17"; "%r18";
< "%r19"; "%r20"; "%r21"; "%r22"; "%r23"; "%r24"; "%r25"; "%r26";
< "%r27"; "%r28"; "%r29"; "%r30" |]
< let fregs = Array.init 32 (fun i -> Printf.sprintf "%%f%d" i)
---
> let regs = (* Array.init 16 (fun i -> Printf.sprintf "%%r%d" i) *)
> [| "%eax"; "%ebx"; "%ecx"; "%edx"; "%esi"; "%edi" |]
> let fregs = Array.init 8 (fun i -> Printf.sprintf "%%xmm%d" i)
55c50,51
< let reg_sw = regs.(Array.length regs - 2) (* temporary for swap *)
---
> (*
> let reg_sw = regs.(Array.length regs - 1) (* temporary for swap *)
57,60c53,57
< let reg_sp = "%r3" (* stack pointer *)
< let reg_hp = "%r4" (* heap pointer (caml2html: sparcasm_reghp) *)
< let reg_tmp = "%r31" (* [XX] ad hoc *)
< let is_reg x = (x.[0] = '%')
---
> *)
> let reg_sp = "%ebp" (* stack pointer *)
> let reg_hp = "min_caml_hp" (* heap pointer (caml2html: sparcasm_reghp) *)
> (* let reg_ra = "%eax" (* return address *) *)
> let is_reg x = (x.[0] = '%' || x = reg_hp)
71,76c68,73
< | Nop | Li(_) | FLi(_) | SetL(_) | Comment(_) | Restore(_) -> []
< | Mr(x) | Neg(x) | FMr(x) | FNeg(x) | Save(x, _) -> [x]
< | Add(x, y') | Sub(x, y') | Slw(x, y') | Lfd(x, y') | Lwz(x, y') -> x :: fv_id_or_imm y'
< | Stw(x, y, z') | Stfd(x, y, z') -> x :: y :: fv_id_or_imm z'
< | FAdd(x, y) | FSub(x, y) | FMul(x, y) | FDiv(x, y) -> [x; y]
< | IfEq(x, y', e1, e2) | IfLE(x, y', e1, e2) | IfGE(x, y', e1, e2) -> x :: fv_id_or_imm y' @ remove_and_uniq S.empty (fv e1 @ fv e2) (* uniq here just for efficiency *)
---
> | Nop | Set(_) | SetL(_) | Comment(_) | Restore(_) -> []
> | Mov(x) | Neg(x) | FMovD(x) | FNegD(x) | Save(x, _) -> [x]
> | Add(x, y') | Sub(x, y') | Ld(x, y', _) | LdDF(x, y', _) -> x :: fv_id_or_imm y'
> | St(x, y, z', _) | StDF(x, y, z', _) -> x :: y :: fv_id_or_imm z'
> | FAddD(x, y) | FSubD(x, y) | FMulD(x, y) | FDivD(x, y) -> [x; y]
> | IfEq(x, y', e1, e2) | IfLE(x, y', e1, e2) | IfGE(x, y', e1, e2) -> x :: fv_id_or_imm y' @ remove_and_uniq S.empty (fv e1 @ fv e2) (* uniq here just for efficiency *)
diff min-caml-ppc/asm.mli min-caml-x86/asm.mli
7,8c7
< | Li of int
< | FLi of Id.l
---
> | Set of int
10c9
< | Mr of Id.t
---
> | Mov of Id.t
14,24c13,22
< | Slw of Id.t * id_or_imm
< | Lwz of Id.t * id_or_imm
< | Stw of Id.t * Id.t * id_or_imm
< | FMr of Id.t
< | FNeg of Id.t
< | FAdd of Id.t * Id.t
< | FSub of Id.t * Id.t
< | FMul of Id.t * Id.t
< | FDiv of Id.t * Id.t
< | Lfd of Id.t * id_or_imm
< | Stfd of Id.t * Id.t * id_or_imm
---
> | Ld of Id.t * id_or_imm * int
> | St of Id.t * Id.t * id_or_imm * int
> | FMovD of Id.t
> | FNegD of Id.t
> | FAddD of Id.t * Id.t
> | FSubD of Id.t * Id.t
> | FMulD of Id.t * Id.t
> | FDivD of Id.t * Id.t
> | LdDF of Id.t * id_or_imm * int
> | StDF of Id.t * Id.t * id_or_imm * int
47a46
> (*
49a49,50
> val reg_ra : Id.t
> *)
52d52
< val reg_tmp : Id.t
Common subdirectories: min-caml-ppc/bytemark and min-caml-x86/bytemark
diff min-caml-ppc/emit.ml min-caml-x86/emit.ml
25c25
< let stacksize () = align ((List.length !stackmap + 1) * 4)
---
> let stacksize () = align (List.length !stackmap * 4)
27,36c27,29
< let reg r =
< if is_reg r
< then String.sub r 1 (String.length r - 1)
< else r
<
< let load_label r label =
< let r' = reg r in
< Printf.sprintf
< "\tlis\t%s, ha16(%s)\n\taddi\t%s, %s, lo16(%s)\n"
< r' label r' r' label
---
> let pp_id_or_imm = function
> | V(x) -> x
> | C(i) -> "$" ^ string_of_int i
62,99c55,118
< | NonTail(x), Li(i) when -32768 <= i && i < 32768 -> Printf.fprintf oc "\tli\t%s, %d\n" (reg x) i
< | NonTail(x), Li(i) ->
< let n = i lsr 16 in
< let m = i lxor (n lsl 16) in
< let r = reg x in
< Printf.fprintf oc "\tlis\t%s, %d\n" r n;
< Printf.fprintf oc "\tori\t%s, %s, %d\n" r r m
< | NonTail(x), FLi(Id.L(l)) ->
< let s = load_label (reg reg_tmp) l in
< Printf.fprintf oc "%s\tlfd\t%s, 0(%s)\n" s (reg x) (reg reg_tmp)
< | NonTail(x), SetL(Id.L(y)) ->
< let s = load_label x y in
< Printf.fprintf oc "%s" s
< | NonTail(x), Mr(y) when x = y -> ()
< | NonTail(x), Mr(y) -> Printf.fprintf oc "\tmr\t%s, %s\n" (reg x) (reg y)
< | NonTail(x), Neg(y) -> Printf.fprintf oc "\tneg\t%s, %s\n" (reg x) (reg y)
< | NonTail(x), Add(y, V(z)) -> Printf.fprintf oc "\tadd\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), Add(y, C(z)) -> Printf.fprintf oc "\taddi\t%s, %s, %d\n" (reg x) (reg y) z
< | NonTail(x), Sub(y, V(z)) -> Printf.fprintf oc "\tsub\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), Sub(y, C(z)) -> Printf.fprintf oc "\tsubi\t%s, %s, %d\n" (reg x) (reg y) z
< | NonTail(x), Slw(y, V(z)) -> Printf.fprintf oc "\tslw\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), Slw(y, C(z)) -> Printf.fprintf oc "\tslwi\t%s, %s, %d\n" (reg x) (reg y) z
< | NonTail(x), Lwz(y, V(z)) -> Printf.fprintf oc "\tlwzx\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), Lwz(y, C(z)) -> Printf.fprintf oc "\tlwz\t%s, %d(%s)\n" (reg x) z (reg y)
< | NonTail(_), Stw(x, y, V(z)) -> Printf.fprintf oc "\tstwx\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(_), Stw(x, y, C(z)) -> Printf.fprintf oc "\tstw\t%s, %d(%s)\n" (reg x) z (reg y)
< | NonTail(x), FMr(y) when x = y -> ()
< | NonTail(x), FMr(y) -> Printf.fprintf oc "\tfmr\t%s, %s\n" (reg x) (reg y)
< | NonTail(x), FNeg(y) -> Printf.fprintf oc "\tfneg\t%s, %s\n" (reg x) (reg y)
< | NonTail(x), FAdd(y, z) -> Printf.fprintf oc "\tfadd\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), FSub(y, z) -> Printf.fprintf oc "\tfsub\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), FMul(y, z) -> Printf.fprintf oc "\tfmul\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), FDiv(y, z) -> Printf.fprintf oc "\tfdiv\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), Lfd(y, V(z)) -> Printf.fprintf oc "\tlfdx\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(x), Lfd(y, C(z)) -> Printf.fprintf oc "\tlfd\t%s, %d(%s)\n" (reg x) z (reg y)
< | NonTail(_), Stfd(x, y, V(z)) -> Printf.fprintf oc "\tstfdx\t%s, %s, %s\n" (reg x) (reg y) (reg z)
< | NonTail(_), Stfd(x, y, C(z)) -> Printf.fprintf oc "\tstfd\t%s, %d(%s)\n" (reg x) z (reg y)
< | NonTail(_), Comment(s) -> Printf.fprintf oc "#\t%s\n" s
---
> | NonTail(x), Set(i) -> Printf.fprintf oc "\tmovl\t$%d, %s\n" i x
> | NonTail(x), SetL(Id.L(y)) -> Printf.fprintf oc "\tmovl\t$%s, %s\n" y x
> | NonTail(x), Mov(y) ->
> if x <> y then Printf.fprintf oc "\tmovl\t%s, %s\n" y x
> | NonTail(x), Neg(y) ->
> if x <> y then Printf.fprintf oc "\tmovl\t%s, %s\n" y x;
> Printf.fprintf oc "\tnegl\t%s\n" x
> | NonTail(x), Add(y, z') ->
> if V(x) = z' then
> Printf.fprintf oc "\taddl\t%s, %s\n" y x
> else
> (if x <> y then Printf.fprintf oc "\tmovl\t%s, %s\n" y x;
> Printf.fprintf oc "\taddl\t%s, %s\n" (pp_id_or_imm z') x)
> | NonTail(x), Sub(y, z') ->
> if V(x) = z' then
> (Printf.fprintf oc "\tsubl\t%s, %s\n" y x;
> Printf.fprintf oc "\tnegl\t%s\n" x)
> else
> (if x <> y then Printf.fprintf oc "\tmovl\t%s, %s\n" y x;
> Printf.fprintf oc "\tsubl\t%s, %s\n" (pp_id_or_imm z') x)
> | NonTail(x), Ld(y, V(z), i) -> Printf.fprintf oc "\tmovl\t(%s,%s,%d), %s\n" y z i x
> | NonTail(x), Ld(y, C(j), i) -> Printf.fprintf oc "\tmovl\t%d(%s), %s\n" (j * i) y x
> | NonTail(_), St(x, y, V(z), i) -> Printf.fprintf oc "\tmovl\t%s, (%s,%s,%d)\n" x y z i
> | NonTail(_), St(x, y, C(j), i) -> Printf.fprintf oc "\tmovl\t%s, %d(%s)\n" x (j * i) y
> | NonTail(x), FMovD(y) ->
> if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x
> | NonTail(x), FNegD(y) ->
> if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x;
> Printf.fprintf oc "\txorpd\tmin_caml_fnegd, %s\n" x
> | NonTail(x), FAddD(y, z) ->
> if x = z then
> Printf.fprintf oc "\taddsd\t%s, %s\n" y x
> else
> (if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x;
> Printf.fprintf oc "\taddsd\t%s, %s\n" z x)
> | NonTail(x), FSubD(y, z) ->
> if x = z then (* [XXX] ugly *)
> let ss = stacksize () in
> Printf.fprintf oc "\tmovsd\t%s, %d(%s)\n" z ss reg_sp;
> if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x;
> Printf.fprintf oc "\tsubsd\t%d(%s), %s\n" ss reg_sp x
> else
> (if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x;
> Printf.fprintf oc "\tsubsd\t%s, %s\n" z x)
> | NonTail(x), FMulD(y, z) ->
> if x = z then
> Printf.fprintf oc "\tmulsd\t%s, %s\n" y x
> else
> (if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x;
> Printf.fprintf oc "\tmulsd\t%s, %s\n" z x)
> | NonTail(x), FDivD(y, z) ->
> if x = z then (* [XXX] ugly *)
> let ss = stacksize () in
> Printf.fprintf oc "\tmovsd\t%s, %d(%s)\n" z ss reg_sp;
> if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x;
> Printf.fprintf oc "\tdivsd\t%d(%s), %s\n" ss reg_sp x
> else
> (if x <> y then Printf.fprintf oc "\tmovsd\t%s, %s\n" y x;
> Printf.fprintf oc "\tdivsd\t%s, %s\n" z x)
> | NonTail(x), LdDF(y, V(z), i) -> Printf.fprintf oc "\tmovsd\t(%s,%s,%d), %s\n" y z i x
> | NonTail(x), LdDF(y, C(j), i) -> Printf.fprintf oc "\tmovsd\t%d(%s), %s\n" (j * i) y x
> | NonTail(_), StDF(x, y, V(z), i) -> Printf.fprintf oc "\tmovsd\t%s, (%s,%s,%d)\n" x y z i
> | NonTail(_), StDF(x, y, C(j), i) -> Printf.fprintf oc "\tmovsd\t%s, %d(%s)\n" x (j * i) y
> | NonTail(_), Comment(s) -> Printf.fprintf oc "\t# %s\n" s
103c122
< Printf.fprintf oc "\tstw\t%s, %d(%s)\n" (reg x) (offset y) (reg reg_sp)
---
> Printf.fprintf oc "\tmovl\t%s, %d(%s)\n" x (offset y) reg_sp
106c125
< Printf.fprintf oc "\tstfd\t%s, %d(%s)\n" (reg x) (offset y) (reg reg_sp)
---
> Printf.fprintf oc "\tmovsd\t%s, %d(%s)\n" x (offset y) reg_sp
110c129
< Printf.fprintf oc "\tlwz\t%s, %d(%s)\n" (reg x) (offset y) (reg reg_sp)
---
> Printf.fprintf oc "\tmovl\t%d(%s), %s\n" (offset y) reg_sp x
113,115c132,134
< Printf.fprintf oc "\tlfd\t%s, %d(%s)\n" (reg x) (offset y) (reg reg_sp)
< (* 末尾だったら計算結果を第一レジスタにセットしてリターン (caml2html: emit_tailret) *)
< | Tail, (Nop | Stw _ | Stfd _ | Comment _ | Save _ as exp) ->
---
> Printf.fprintf oc "\tmovsd\t%d(%s), %s\n" (offset y) reg_sp x
> (* 末尾だったら計算結果を第一レジスタにセットしてret (caml2html: emit_tailret) *)
> | Tail, (Nop | St _ | StDF _ | Comment _ | Save _ as exp) ->
117,118c136,137
< Printf.fprintf oc "\tblr\n";
< | Tail, (Li _ | SetL _ | Mr _ | Neg _ | Add _ | Sub _ | Slw _ | Lwz _ as exp) ->
---
> Printf.fprintf oc "\tret\n";
> | Tail, (Set _ | SetL _ | Mov _ | Neg _ | Add _ | Sub _ | Ld _ as exp) ->
120,121c139,140
< Printf.fprintf oc "\tblr\n";
< | Tail, (FLi _ | FMr _ | FNeg _ | FAdd _ | FSub _ | FMul _ | FDiv _ | Lfd _ as exp) ->
---
> Printf.fprintf oc "\tret\n";
> | Tail, (FMovD _ | FNegD _ | FAddD _ | FSubD _ | FMulD _ | FDivD _ | LdDF _ as exp) ->
123c142
< Printf.fprintf oc "\tblr\n";
---
> Printf.fprintf oc "\tret\n";
129,147c148,157
< Printf.fprintf oc "\tblr\n";
< | Tail, IfEq(x, V(y), e1, e2) ->
< Printf.fprintf oc "\tcmpw\tcr7, %s, %s\n" (reg x) (reg y);
< g'_tail_if oc e1 e2 "beq" "bne"
< | Tail, IfEq(x, C(y), e1, e2) ->
< Printf.fprintf oc "\tcmpwi\tcr7, %s, %d\n" (reg x) y;
< g'_tail_if oc e1 e2 "beq" "bne"
< | Tail, IfLE(x, V(y), e1, e2) ->
< Printf.fprintf oc "\tcmpw\tcr7, %s, %s\n" (reg x) (reg y);
< g'_tail_if oc e1 e2 "ble" "bgt"
< | Tail, IfLE(x, C(y), e1, e2) ->
< Printf.fprintf oc "\tcmpwi\tcr7, %s, %d\n" (reg x) y;
< g'_tail_if oc e1 e2 "ble" "bgt"
< | Tail, IfGE(x, V(y), e1, e2) ->
< Printf.fprintf oc "\tcmpw\tcr7, %s, %s\n" (reg x) (reg y);
< g'_tail_if oc e1 e2 "bge" "blt"
< | Tail, IfGE(x, C(y), e1, e2) ->
< Printf.fprintf oc "\tcmpwi\tcr7, %s, %d\n" (reg x) y;
< g'_tail_if oc e1 e2 "bge" "blt"
---
> Printf.fprintf oc "\tret\n";
> | Tail, IfEq(x, y', e1, e2) ->
> Printf.fprintf oc "\tcmpl\t%s, %s\n" (pp_id_or_imm y') x;
> g'_tail_if oc e1 e2 "je" "jne"
> | Tail, IfLE(x, y', e1, e2) ->
> Printf.fprintf oc "\tcmpl\t%s, %s\n" (pp_id_or_imm y') x;
> g'_tail_if oc e1 e2 "jle" "jg"
> | Tail, IfGE(x, y', e1, e2) ->
> Printf.fprintf oc "\tcmpl\t%s, %s\n" (pp_id_or_imm y') x;
> g'_tail_if oc e1 e2 "jge" "jl"
149,150c159,160
< Printf.fprintf oc "\tfcmpu\tcr7, %s, %s\n" (reg x) (reg y);
< g'_tail_if oc e1 e2 "beq" "bne"
---
> Printf.fprintf oc "\tcomisd\t%s, %s\n" y x;
> g'_tail_if oc e1 e2 "je" "jne"
152,171c162,172
< Printf.fprintf oc "\tfcmpu\tcr7, %s, %s\n" (reg x) (reg y);
< g'_tail_if oc e1 e2 "ble" "bgt"
< | NonTail(z), IfEq(x, V(y), e1, e2) ->
< Printf.fprintf oc "\tcmpw\tcr7, %s, %s\n" (reg x) (reg y);
< g'_non_tail_if oc (NonTail(z)) e1 e2 "beq" "bne"
< | NonTail(z), IfEq(x, C(y), e1, e2) ->
< Printf.fprintf oc "\tcmpwi\tcr7, %s, %d\n" (reg x) y;
< g'_non_tail_if oc (NonTail(z)) e1 e2 "beq" "bne"
< | NonTail(z), IfLE(x, V(y), e1, e2) ->
< Printf.fprintf oc "\tcmpw\tcr7, %s, %s\n" (reg x) (reg y);
< g'_non_tail_if oc (NonTail(z)) e1 e2 "ble" "bgt"
< | NonTail(z), IfLE(x, C(y), e1, e2) ->
< Printf.fprintf oc "\tcmpwi\tcr7, %s, %d\n" (reg x) y;
< g'_non_tail_if oc (NonTail(z)) e1 e2 "ble" "bgt"
< | NonTail(z), IfGE(x, V(y), e1, e2) ->
< Printf.fprintf oc "\tcmpw\tcr7, %s, %s\n" (reg x) (reg y);
< g'_non_tail_if oc (NonTail(z)) e1 e2 "bge" "blt"
< | NonTail(z), IfGE(x, C(y), e1, e2) ->
< Printf.fprintf oc "\tcmpwi\tcr7, %s, %d\n" (reg x) y;
< g'_non_tail_if oc (NonTail(z)) e1 e2 "bge" "blt"
---
> Printf.fprintf oc "\tcomisd\t%s, %s\n" y x;
> g'_tail_if oc e1 e2 "jbe" "ja"
> | NonTail(z), IfEq(x, y', e1, e2) ->
> Printf.fprintf oc "\tcmpl\t%s, %s\n" (pp_id_or_imm y') x;
> g'_non_tail_if oc (NonTail(z)) e1 e2 "je" "jne"
> | NonTail(z), IfLE(x, y', e1, e2) ->
> Printf.fprintf oc "\tcmpl\t%s, %s\n" (pp_id_or_imm y') x;
> g'_non_tail_if oc (NonTail(z)) e1 e2 "jle" "jg"
> | NonTail(z), IfGE(x, y', e1, e2) ->
> Printf.fprintf oc "\tcmpl\t%s, %s\n" (pp_id_or_imm y') x;
> g'_non_tail_if oc (NonTail(z)) e1 e2 "jge" "jl"
173,174c174,175
< Printf.fprintf oc "\tfcmpu\tcr7, %s, %s\n" (reg x) (reg y);
< g'_non_tail_if oc (NonTail(z)) e1 e2 "beq" "bne"
---
> Printf.fprintf oc "\tcomisd\t%s, %s\n" y x;
> g'_non_tail_if oc (NonTail(z)) e1 e2 "je" "jne"
176,177c177,178
< Printf.fprintf oc "\tfcmpu\tcr7, %s, %s\n" (reg x) (reg y);
< g'_non_tail_if oc (NonTail(z)) e1 e2 "ble" "bgt"
---
> Printf.fprintf oc "\tcomisd\t%s, %s\n" y x;
> g'_non_tail_if oc (NonTail(z)) e1 e2 "jbe" "ja"
181,182c182
< Printf.fprintf oc "\tlwz\t%s, 0(%s)\n" (reg reg_sw) (reg reg_cl);
< Printf.fprintf oc "\tmtctr\t%s\n\tbctr\n" (reg reg_sw);
---
> Printf.fprintf oc "\tjmp\t*(%s)\n" reg_cl;
185c185
< Printf.fprintf oc "\tb\t%s\n" x
---
> Printf.fprintf oc "\tjmp\t%s\n" x;
187d186
< Printf.fprintf oc "\tmflr\t%s\n" (reg reg_tmp);
190,196c189,191
< Printf.fprintf oc "\tstw\t%s, %d(%s)\n" (reg reg_tmp) (ss - 4) (reg reg_sp);
< Printf.fprintf oc "\taddi\t%s, %s, %d\n" (reg reg_sp) (reg reg_sp) ss;
< Printf.fprintf oc "\tlwz\t%s, 0(%s)\n" (reg reg_tmp) (reg reg_cl);
< Printf.fprintf oc "\tmtctr\t%s\n" (reg reg_tmp);
< Printf.fprintf oc "\tbctrl\n";
< Printf.fprintf oc "\tsubi\t%s, %s, %d\n" (reg reg_sp) (reg reg_sp) ss;
< Printf.fprintf oc "\tlwz\t%s, %d(%s)\n" (reg reg_tmp) (ss - 4) (reg reg_sp);
---
> if ss > 0 then Printf.fprintf oc "\taddl\t$%d, %s\n" ss reg_sp;
> Printf.fprintf oc "\tcall\t*(%s)\n" reg_cl;
> if ss > 0 then Printf.fprintf oc "\tsubl\t$%d, %s\n" ss reg_sp;
198c193
< Printf.fprintf oc "\tmr\t%s, %s\n" (reg a) (reg regs.(0))
---
> Printf.fprintf oc "\tmovl\t%s, %s\n" regs.(0) a
200,203c195,196
< Printf.fprintf oc "\tfmr\t%s, %s\n" (reg a) (reg fregs.(0));
< Printf.fprintf oc "\tmtlr\t%s\n" (reg reg_tmp)
< | (NonTail(a), CallDir(Id.L(x), ys, zs)) ->
< Printf.fprintf oc "\tmflr\t%s\n" (reg reg_tmp);
---
> Printf.fprintf oc "\tmovsd\t%s, %s\n" fregs.(0) a
> | NonTail(a), CallDir(Id.L(x), ys, zs) ->
206,210c199,201
< Printf.fprintf oc "\tstw\t%s, %d(%s)\n" (reg reg_tmp) (ss - 4) (reg reg_sp);
< Printf.fprintf oc "\taddi\t%s, %s, %d\n" (reg reg_sp) (reg reg_sp) ss;
< Printf.fprintf oc "\tbl\t%s\n" x;
< Printf.fprintf oc "\tsubi\t%s, %s, %d\n" (reg reg_sp) (reg reg_sp) ss;
< Printf.fprintf oc "\tlwz\t%s, %d(%s)\n" (reg reg_tmp) (ss - 4) (reg reg_sp);
---
> if ss > 0 then Printf.fprintf oc "\taddl\t$%d, %s\n" ss reg_sp;
> Printf.fprintf oc "\tcall\t%s\n" x;
> if ss > 0 then Printf.fprintf oc "\tsubl\t$%d, %s\n" ss reg_sp;
212c203
< Printf.fprintf oc "\tmr\t%s, %s\n" (reg a) (reg regs.(0))
---
> Printf.fprintf oc "\tmovl\t%s, %s\n" regs.(0) a
214,215c205
< Printf.fprintf oc "\tfmr\t%s, %s\n" (reg a) (reg fregs.(0));
< Printf.fprintf oc "\tmtlr\t%s\n" (reg reg_tmp)
---
> Printf.fprintf oc "\tmovsd\t%s, %s\n" fregs.(0) a
218c208
< Printf.fprintf oc "\t%s\tcr7, %s\n" bn b_else;
---
> Printf.fprintf oc "\t%s\t%s\n" bn b_else;
227c217
< Printf.fprintf oc "\t%s\tcr7, %s\n" bn b_else;
---
> Printf.fprintf oc "\t%s\t%s\n" bn b_else;
231c221
< Printf.fprintf oc "\tb\t%s\n" b_cont;
---
> Printf.fprintf oc "\tjmp\t%s\n" b_cont;
238a229,231
> assert (List.length ys <= Array.length regs - List.length x_reg_cl);
> assert (List.length zs <= Array.length fregs);
> let sw = Printf.sprintf "%d(%s)" (stacksize ()) reg_sp in
245,246c238,239
< (fun (y, r) -> Printf.fprintf oc "\tmr\t%s, %s\n" (reg r) (reg y))
< (shuffle reg_sw yrs);
---
> (fun (y, r) -> Printf.fprintf oc "\tmovl\t%s, %s\n" y r)
> (shuffle sw yrs);
253,254c246,247
< (fun (z, fr) -> Printf.fprintf oc "\tfmr\t%s, %s\n" (reg fr) (reg z))
< (shuffle reg_fsw zfrs)
---
> (fun (z, fr) -> Printf.fprintf oc "\tmovsd\t%s, %s\n" z fr)
> (shuffle sw zfrs)
264,275c257,265
< if data <> [] then
< (Printf.fprintf oc "\t.data\n\t.literal8\n";
< List.iter
< (fun (Id.L(x), d) ->
< Printf.fprintf oc "\t.align 3\n";
< Printf.fprintf oc "%s:\t # %f\n" x d;
< Printf.fprintf oc "\t.long\t%ld\n" (gethi d);
< Printf.fprintf oc "\t.long\t%ld\n" (getlo d))
< data);
< Printf.fprintf oc "\t.text\n";
< Printf.fprintf oc "\t.globl _min_caml_start\n";
< Printf.fprintf oc "\t.align 2\n";
---
> Printf.fprintf oc ".data\n";
> Printf.fprintf oc ".balign\t8\n";
> List.iter
> (fun (Id.L(x), d) ->
> Printf.fprintf oc "%s:\t# %f\n" x d;
> Printf.fprintf oc "\t.long\t0x%lx\n" (gethi d);
> Printf.fprintf oc "\t.long\t0x%lx\n" (getlo d))
> data;
> Printf.fprintf oc ".text\n";
277,282c267,280
< Printf.fprintf oc "_min_caml_start: # main entry point\n";
< Printf.fprintf oc "\tmflr\tr0\n";
< Printf.fprintf oc "\tstmw\tr30, -8(r1)\n";
< Printf.fprintf oc "\tstw\tr0, 8(r1)\n";
< Printf.fprintf oc "\tstwu\tr1, -96(r1)\n";
< Printf.fprintf oc "#\tmain program starts\n";
---
> Printf.fprintf oc ".globl\tmin_caml_start\n";
> Printf.fprintf oc "min_caml_start:\n";
> Printf.fprintf oc ".globl\t_min_caml_start\n";
> Printf.fprintf oc "_min_caml_start: # for cygwin\n";
> Printf.fprintf oc "\tpushl\t%%eax\n";
> Printf.fprintf oc "\tpushl\t%%ebx\n";
> Printf.fprintf oc "\tpushl\t%%ecx\n";
> Printf.fprintf oc "\tpushl\t%%edx\n";
> Printf.fprintf oc "\tpushl\t%%esi\n";
> Printf.fprintf oc "\tpushl\t%%edi\n";
> Printf.fprintf oc "\tpushl\t%%ebp\n";
> Printf.fprintf oc "\tmovl\t32(%%esp),%s\n" reg_sp;
> Printf.fprintf oc "\tmovl\t36(%%esp),%s\n" regs.(0);
> Printf.fprintf oc "\tmovl\t%s,%s\n" regs.(0) reg_hp;
285,292c283,291
< g oc (NonTail("_R_0"), e);
< Printf.fprintf oc "#\tmain program ends\n";
< (* Printf.fprintf oc "\tmr\tr3, %s\n" regs.(0); *)
< Printf.fprintf oc "\tlwz\tr1, 0(r1)\n";
< Printf.fprintf oc "\tlwz\tr0, 8(r1)\n";
< Printf.fprintf oc "\tmtlr\tr0\n";
< Printf.fprintf oc "\tlmw\tr30, -8(r1)\n";
< Printf.fprintf oc "\tblr\n"
---
> g oc (NonTail(regs.(0)), e);
> Printf.fprintf oc "\tpopl\t%%ebp\n";
> Printf.fprintf oc "\tpopl\t%%edi\n";
> Printf.fprintf oc "\tpopl\t%%esi\n";
> Printf.fprintf oc "\tpopl\t%%edx\n";
> Printf.fprintf oc "\tpopl\t%%ecx\n";
> Printf.fprintf oc "\tpopl\t%%ebx\n";
> Printf.fprintf oc "\tpopl\t%%eax\n";
> Printf.fprintf oc "\tret\n";
diff min-caml-ppc/libmincaml.S min-caml-x86/libmincaml.S
1,15c1,18
< .cstring
< .align 2
< LC0:
< .ascii "%d\0"
< .align 2
< LC1:
< .ascii "%lf\0"
< .literal8
< .align 3
< LC2:
< .long 1127219200
< .long -2147483648
< .text
< .align 2
< .globl min_caml_print_newline
---
> #if defined(__CYGWIN__) || defined(__MACH__)
> #define U(x) _##x
> #else
> #define U(x) x
> #endif
> #if defined(__MACH__)
> #define ALIGNSTACK0 andl $0xfffffff0, %esp
> #define ALIGNSTACK1 andl $0xfffffff0, %esp; pushl %eax; pushl %eax; pushl %eax
> #define ALIGNSTACK2 andl $0xfffffff0, %esp; pushl %eax; pushl %eax
> #define ALIGNSTACK3 andl $0xfffffff0, %esp; pushl %eax
> #else
> #define ALIGNSTACK0
> #define ALIGNSTACK1
> #define ALIGNSTACK2
> #define ALIGNSTACK3
> #endif
> .text
> .globl min_caml_print_newline
17,54c20,28
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -80(r1)
< mr r30, r1
< li r3, 10
< bl putchar
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< putchar:
< .indirect_symbol _putchar
< mflr r0
< bcl 20, 31, L1spb
< L1spb:
< mflr r11
< addis r11, r11, ha16(putchar_lazy-L1spb)
< mtlr r0
< lwzu r12, lo16(putchar_lazy-L1spb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< putchar_lazy:
< .indirect_symbol _putchar
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # print_int
< .text
< .align 2
< .globl min_caml_print_int
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK1
> pushl $10
> call U(putchar)
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_print_int
56,98c30,39
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -80(r1)
< mr r30, r1
< bcl 20, 31, L2pb
< L2pb:
< mflr r31
< mr r4, r2
< addis r2, r31, ha16(LC0 - L2pb)
< la r3, lo16(LC0 - L2pb)(r2)
< bl printf
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< printf:
< .indirect_symbol _printf$LDBLStub
< mflr r0
< bcl 20, 31, L2spb
< L2spb:
< mflr r11
< addis r11, r11, ha16(printf_lazy-L2spb)
< mtlr r0
< lwzu r12, lo16(printf_lazy-L2spb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< printf_lazy:
< .indirect_symbol _printf$LDBLStub
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # print_byte
< .text
< .align 2
< .globl min_caml_print_byte
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK2
> pushl %eax
> pushl $format_int
> call U(printf)
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_print_byte
100,120c41,49
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -80(r1)
< mr r30, r1
< stw r3, 104(r30)
< mr r3, r2
< bl putchar
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< # prerr_int
< .text
< .align 2
< .globl min_caml_prerr_int
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK1
> pushl %eax
> call U(putchar)
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_prerr_int
122,174c51,61
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -80(r1)
< mr r30, r1
< bcl 20, 31, L3pb
< L3pb:
< mflr r31
< mr r6, r2
< mr r2, r5
< mr r5, r6
< addis r2, r31, ha16(L - L3pb)
< lwz r2, lo16(L - L3pb)(r2)
< addi r0, r2, 176
< mr r3, r0
< addis r2, r31, ha16(LC0 - L3pb)
< la r4, lo16(LC0 - L3pb)(r2)
< bl fprintf
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .non_lazy_symbol_pointer
< L:
< .indirect_symbol ___sF
< .long 0
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< fprintf:
< .indirect_symbol _fprintf$LDBLStub
< mflr r0
< bcl 20, 31, L3spb
< L3spb:
< mflr r11
< addis r11, r11, ha16(fprintf_lazy - L3spb)
< mtlr r0
< lwzu r12, lo16(fprintf_lazy - L3spb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< fprintf_lazy:
< .indirect_symbol _fprintf$LDBLStub
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # prerr_byte
< .text
< .align 2
< .globl min_caml_prerr_byte
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK3
> pushl %eax
> pushl $format_int
> pushl U(min_caml_stderr)
> call U(fprintf)
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_prerr_byte
176,220c63,72
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -80(r1)
< mr r30, r1
< bcl 20, 31, L4pb
< L4pb:
< mflr r31
< mr r3, r2
< addis r2, r31, ha16(L - L4pb)
< lwz r2, lo16(L - L4pb)(r2)
< addi r0, r2, 176
< mr r4, r0
< bl fputc
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< fputc:
< .indirect_symbol _fputc
< mflr r0
< bcl 20, 31, L4spb
< L4spb:
< mflr r11
< addis r11, r11, ha16(fputc_lazy - L4spb)
< mtlr r0
< lwzu r12, lo16(fputc_lazy - L4spb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< fputc_lazy:
< .indirect_symbol _fputc
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # prerr_float
< .text
< .align 2
< .globl min_caml_prerr_float
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK2
> pushl U(min_caml_stderr)
> pushl %eax
> call U(fputc)
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_prerr_float
222,261c74,85
< mflr r0
< stmw r29, -12(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -96(r1)
< mr r30, r1
< bcl 20, 31, L5pb
< L5pb:
< mflr r31
< addis r2, r31, ha16(L - L5pb)
< lwz r2, lo16(L - L5pb)(r2)
< addi r29, r2, 176
< stfd f0, 64(r30)
< lwz r2, 64(r30)
< lwz r3, 68(r30)
< mr r10, r3
< mr r9, r2
< stw r2, 64(r30)
< stw r3, 68(r30)
< lfd f13, 64(r30)
< # fmr f0, f13
< mr r3, r29
< addis r2, r31, ha16(LC1 - L5pb)
< la r4, lo16(LC1 - L5pb)(r2)
< mr r5, r9
< mr r6, r10
< fmr f1, f0
< bl fprintf
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r29, -12(r1)
< blr
< # read_int
< .text
< .align 2
< .globl min_caml_read_int
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK0
> subl $8, %esp
> movsd %xmm0, (%esp)
> pushl $format_float
> pushl U(min_caml_stderr)
> call U(fprintf)
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_read_int
263,336c87,123
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -96(r1)
< mr r30, r1
< bcl 20, 31, L6pb
< L6pb:
< mflr r31
< addis r2, r31, ha16(LC0 - L6pb)
< la r3, lo16(LC0 - L6pb)(r2)
< addi r4, r30, 56
< bl scanf
< lwz r2, 56(r30)
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< scanf:
< .indirect_symbol _scanf$LDBLStub
< mflr r0
< bcl 20, 31, L6spb
< L6spb:
< mflr r11
< addis r11, r11, ha16(scanf_lazy - L6spb)
< mtlr r0
< lwzu r12, lo16(scanf_lazy - L6spb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< scanf_lazy:
< .indirect_symbol _scanf$LDBLStub
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # read_float
< .text
< .align 2
< .globl min_caml_read_float
< min_caml_read_float:
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -112(r1)
< mr r30, r1
< bcl 20, 31, L7pb
< L7pb:
< mflr r31
< addis r2, r31, ha16(LC1 - L7pb)
< la r3, lo16(LC1 - L7pb)(r2)
< addi r4, r30, 56
< bl scanf
< lfd f0, 56(r30)
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< # create_array
< .text
< .align 2
< .globl min_caml_create_array
< min_caml_create_array:
< mr r6, r2
< mr r2, r4
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK3
> subl $4, %esp
> leal -4(%ebp), %eax
> pushl %eax
> pushl $format_int
> call U(scanf)
> movl -4(%ebp), %eax
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_read_float
> min_caml_read_float:
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK0
> subl $8, %esp
> leal -8(%ebp), %eax
> pushl %eax
> pushl $format_float
> call U(scanf)
> movsd -8(%ebp), %xmm0
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_create_array
> min_caml_create_array:
> pushl %ebp
> movl %esp, %ebp
> pushl %ecx
> pushl %edx
> movl %eax, %ecx
> movl min_caml_hp, %eax
> movl %ecx, %edx
> shll $2, %edx
> addl %edx, min_caml_hp
338,340c125,126
< cmpwi cr7, r6, 0
< bne cr7, create_array_cont
< b create_array_exit
---
> cmpl $0, %ecx
> jne create_array_cont
342c128,132
< blr
---
> popl %edx
> popl %ecx
> movl %ebp, %esp
> popl %ebp
> ret
344,349c134,137
< stw r5, 0(r4)
< subi r6, r6, 1
< addi r4, r4, 4
< b create_array_loop
< # create_float_array
< .globl min_caml_create_float_array
---
> decl %ecx
> movl %ebx, (%eax,%ecx,4)
> jmp create_array_loop
> .globl min_caml_create_float_array
351,352c139,147
< mr r5, r2
< mr r2, r4
---
> pushl %ebp
> movl %esp, %ebp
> pushl %ecx
> pushl %edx
> movl %eax, %ecx
> movl min_caml_hp, %eax
> movl %ecx, %edx
> shll $3, %edx
> addl %edx, min_caml_hp
354,356c149,156
< cmpwi cr7, r5, 0
< bne cr7, create_float_array_cont
< blr
---
> cmpl $0, %ecx
> jne create_float_array_cont
> create_float_array_exit:
> popl %edx
> popl %ecx
> movl %ebp, %esp
> popl %ebp
> ret
358,362c158,161
< stfd f0, 0(r4)
< subi r5, r5, 1
< addi r4, r4, 8
< b create_float_array_loop
< .globl min_caml_abs_float
---
> decl %ecx
> movsd %xmm0, (%eax,%ecx,8)
> jmp create_float_array_loop
> .globl min_caml_abs_float
364,369c163,174
< fabs f0, f0
< blr
< # sqrt
< .text
< .align 2
< .globl min_caml_sqrt
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK2
> subl $8, %esp
> movsd %xmm0, (%esp)
> call U(fabs)
> fstpl (%esp)
> movsd (%esp), %xmm0
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_sqrt
371,412c176,178
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -96(r1)
< mr r30, r1
< bcl 20, 31, L8pb
< L8pb:
< mflr r31
< fmr f1, f0
< bl sqrt
< fmr f0, f1
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< sqrt:
< .indirect_symbol _sqrt
< mflr r0
< bcl 20, 31, L8spb
< L8spb:
< mflr r11
< addis r11, r11, ha16(sqrt_lazy - L8spb)
< mtlr r0
< lwzu r12, lo16(sqrt_lazy - L8spb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< sqrt_lazy:
< .indirect_symbol _sqrt
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # floor
< .text
< .align 2
< .globl min_caml_floor
---
> sqrtsd %xmm0, %xmm0
> ret
> .globl min_caml_floor
414,454c180,191
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -80(r1)
< mr r30, r1
< fmr f1, f0
< stfd f1, 56(r30)
< lfd f1, 56(r30)
< bl floor
< fmr f0, f1
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< floor:
< .indirect_symbol _floor
< mflr r0
< bcl 20, 31, L9spb
< L9spb:
< mflr r11
< addis r11, r11, ha16(floor_lazy - L9spb)
< mtlr r0
< lwzu r12, lo16(floor_lazy - L9spb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< floor_lazy:
< .indirect_symbol _floor
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # int_of_float, truncate
< .text
< .align 2
< .globl min_caml_int_of_float
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK2
> subl $8, %esp
> movsd %xmm0, (%esp)
> call U(floor)
> fstpl (%esp)
> movsd (%esp), %xmm0
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_int_of_float
456c193
< .globl min_caml_truncate
---
> .globl min_caml_truncate
458,471c195,197
< stmw r30, -8(r1)
< stwu r1, -64(r1)
< mr r30, r1
< stfd f0, 24(r30)
< lfd f1, 24(r30)
< fctiwz f1, f1
< stfd f1, 32(r30)
< lwz r31, 36(r30)
< mr r2, r31
< lwz r1, 0(r1)
< lmw r30, -8(r1)
< blr
< # float_of_int
< .globl min_caml_float_of_int
---
> cvttsd2si %xmm0, %eax
> ret
> .globl min_caml_float_of_int
473,501c199,201
< stmw r30, -8(r1)
< stw r3, 8(r1)
< stw r4, 12(r1)
< stwu r1, -48(r1)
< mr r30, r1
< mflr r0
< bcl 20, 31, Lapb
< Lapb:
< mflr r10
< mtlr r0
< stw r2, 72(r30)
< lwz r0, 72(r30)
< lis r2, 0x4330
< addis r9, r10, ha16(LC2 - Lapb)
< lfd f13, lo16(LC2 - Lapb)(r9)
< xoris r0, r0, 0x8000
< stw r0, 28(r30)
< stw r2, 24(r30)
< lfd f0, 24(r30)
< fsub f0, f0, f13
< lwz r1, 0(r1)
< lwz r3, 8(r1)
< lwz r4, 12(r1)
< lmw r30, -8(r1)
< blr
< # cos
< .text
< .align 2
< .globl min_caml_cos
---
> cvtsi2sd %eax, %xmm0
> ret
> .globl min_caml_cos
503,544c203,214
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -96(r1)
< mr r30, r1
< bcl 20, 31, Lbpb
< Lbpb:
< mflr r31
< fmr f1, f0
< bl cos
< fmr f0, f1
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< cos:
< .indirect_symbol _cos
< mflr r0
< bcl 20, 31, Lbspb
< Lbspb:
< mflr r11
< addis r11, r11, ha16(cos_lazy - Lbspb)
< mtlr r0
< lwzu r12,lo16(cos_lazy - Lbspb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< cos_lazy:
< .indirect_symbol _cos
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # sin
< .text
< .align 2
< .globl min_caml_sin
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK2
> subl $8, %esp
> movsd %xmm0, (%esp)
> call U(cos)
> fstpl (%esp)
> movsd (%esp), %xmm0
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_sin
546,587c216,227
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -96(r1)
< mr r30, r1
< bcl 20, 31, Lcpb
< Lcpb:
< mflr r31
< fmr f1, f0
< bl sin
< fmr f0, f1
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< sin:
< .indirect_symbol _sin
< mflr r0
< bcl 20, 31, Lcspb
< Lcspb:
< mflr r11
< addis r11, r11, ha16(sin_lazy - Lcspb)
< mtlr r0
< lwzu r12, lo16(sin_lazy - Lcspb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< sin_lazy:
< .indirect_symbol _sin
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< # atan
< .text
< .align 2
< .globl min_caml_atan
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK2
> subl $8, %esp
> movsd %xmm0, (%esp)
> call U(sin)
> fstpl (%esp)
> movsd (%esp), %xmm0
> movl %ebp, %esp
> popl %ebp
> ret
> .globl min_caml_atan
589,628c229,245
< mflr r0
< stmw r30, -8(r1)
< stw r0, 8(r1)
< stw r3, 12(r1)
< stw r4, 16(r1)
< stwu r1, -96(r1)
< mr r30, r1
< bcl 20, 31, Ldpb
< Ldpb:
< mflr r31
< fmr f1, f0
< bl atan
< fmr f0, f1
< lwz r1, 0(r1)
< lwz r0, 8(r1)
< lwz r3, 12(r1)
< lwz r4, 16(r1)
< mtlr r0
< lmw r30, -8(r1)
< blr
< .section __TEXT, __picsymbolstub1, symbol_stubs, pure_instructions, 32
< .align 5
< atan:
< .indirect_symbol _atan
< mflr r0
< bcl 20, 31, Ldspb
< Ldspb:
< mflr r11
< addis r11, r11, ha16(atan_lazy - Ldspb)
< mtlr r0
< lwzu r12, lo16(atan_lazy - Ldspb)(r11)
< mtctr r12
< bctr
< .lazy_symbol_pointer
< atan_lazy:
< .indirect_symbol _atan
< .long dyld_stub_binding_helper
< .subsections_via_symbols
< .const
< .align 8
---
> pushl %ebp
> movl %esp, %ebp
> ALIGNSTACK2
> subl $8, %esp
> movsd %xmm0, (%esp)
> call U(atan)
> fstpl (%esp)
> movsd (%esp), %xmm0
> movl %ebp, %esp
> popl %ebp
> ret
> .data
> format_int:
> .asciz "%d"
> format_float:
> .asciz "%lf"
> .balign 8
632a250
> .long 0x0
633a252,260
> .balign 16
> .globl min_caml_fnegd
> min_caml_fnegd:
> .long 0
> .long 0x80000000
> .long 0
> .long 0
> .globl min_caml_hp
> min_caml_hp:
635,636d261
<
<
Common subdirectories: min-caml-ppc/min-rt and min-caml-x86/min-rt
diff min-caml-ppc/regAlloc.ml min-caml-x86/regAlloc.ml
7c7
< | Mr(x) when x = src && is_reg dest ->
---
> | Mov(x) when x = src && is_reg dest ->
11c11
< | FMr(x) when x = src && is_reg dest ->
---
> | FMovD(x) when x = src && is_reg dest ->
36c36,37
< | y :: ys when src = y -> all.(n) :: target_args src all (n + 1) ys
---
> | y :: ys when src = y (* && n <= List.length all - 2 *) ->
> all.(n) :: target_args src all (n + 1) ys
37a39,50
> (* "register sourcing" (?) as opposed to register targeting *)
> (* (x86の2オペランド命令のためのregister coalescing) *)
> let rec source t = function
> | Ans(exp) -> source' t exp
> | Let(_, _, e) -> source t e
> and source' t = function
> | Mov(x) | Neg(x) | Add(x, C _) | Sub(x, _) | FMovD(x) | FNegD(x) | FSubD(x, _) | FDivD(x, _) -> [x]
> | Add(x, V y) | FAddD(x, y) | FMulD(x, y) -> [x; y]
> | IfEq(_, _, e1, e2) | IfLE(_, _, e1, e2) | IfGE(_, _, e1, e2) | IfFEq(_, _, e1, e2) | IfFLE(_, _, e1, e2) ->
> source t e1 @ source t e2
> | CallCls _ | CallDir _ -> (match t with Type.Unit -> [] | Type.Float -> [fregs.(0)] | _ -> [regs.(0)])
> | _ -> []
42c55
< let rec alloc dest cont regenv x t =
---
> let rec alloc cont regenv x t prefer =
47c60
< | Type.Unit -> ["%r0"] (* dummy *)
---
> | Type.Unit -> [] (* dummy *)
50c63
< if all = ["%r0"] then Alloc("%r0") else (* [XX] ad hoc optimization *)
---
> if all = [] then Alloc("%unit") else (* [XX] ad hoc *)
54d66
< let (c, prefer) = target x dest cont in
103c115,118
< (match alloc dest cont' regenv1 x t with
---
> let (_call, targets) = target x dest cont' in
> let sources = source t e1' in
> (* レジスタ間のmovよりメモリを介するswapのほうが問題なので、sourcesよりtargetsを優先 *)
> (match alloc cont' regenv1 x t (targets @ sources) with
109c124
< with Not_found -> Nop in
---
> with Not_found -> Nop in
120,121c135,136
< | Nop | Li _ | SetL _ | Comment _ | Restore _ | FLi _ as exp -> (Ans(exp), regenv)
< | Mr(x) -> (Ans(Mr(find x Type.Int regenv)), regenv)
---
> | Nop | Set _ | SetL _ | Comment _ | Restore _ as exp -> (Ans(exp), regenv)
> | Mov(x) -> (Ans(Mov(find x Type.Int regenv)), regenv)
125,135c140,149
< | Slw(x, y') -> (Ans(Slw(find x Type.Int regenv, find' y' regenv)), regenv)
< | Lwz(x, y') -> (Ans(Lwz(find x Type.Int regenv, find' y' regenv)), regenv)
< | Stw(x, y, z') -> (Ans(Stw(find x Type.Int regenv, find y Type.Int regenv, find' z' regenv)), regenv)
< | FMr(x) -> (Ans(FMr(find x Type.Float regenv)), regenv)
< | FNeg(x) -> (Ans(FNeg(find x Type.Float regenv)), regenv)
< | FAdd(x, y) -> (Ans(FAdd(find x Type.Float regenv, find y Type.Float regenv)), regenv)
< | FSub(x, y) -> (Ans(FSub(find x Type.Float regenv, find y Type.Float regenv)), regenv)
< | FMul(x, y) -> (Ans(FMul(find x Type.Float regenv, find y Type.Float regenv)), regenv)
< | FDiv(x, y) -> (Ans(FDiv(find x Type.Float regenv, find y Type.Float regenv)), regenv)
< | Lfd(x, y') -> (Ans(Lfd(find x Type.Int regenv, find' y' regenv)), regenv)
< | Stfd(x, y, z') -> (Ans(Stfd(find x Type.Float regenv, find y Type.Int regenv, find' z' regenv)), regenv)
---
> | Ld(x, y', i) -> (Ans(Ld(find x Type.Int regenv, find' y' regenv, i)), regenv)
> | St(x, y, z', i) -> (Ans(St(find x Type.Int regenv, find y Type.Int regenv, find' z' regenv, i)), regenv)
> | FMovD(x) -> (Ans(FMovD(find x Type.Float regenv)), regenv)
> | FNegD(x) -> (Ans(FNegD(find x Type.Float regenv)), regenv)
> | FAddD(x, y) -> (Ans(FAddD(find x Type.Float regenv, find y Type.Float regenv)), regenv)
> | FSubD(x, y) -> (Ans(FSubD(find x Type.Float regenv, find y Type.Float regenv)), regenv)
> | FMulD(x, y) -> (Ans(FMulD(find x Type.Float regenv, find y Type.Float regenv)), regenv)
> | FDivD(x, y) -> (Ans(FDivD(find x Type.Float regenv, find y Type.Float regenv)), regenv)
> | LdDF(x, y', i) -> (Ans(LdDF(find x Type.Int regenv, find' y' regenv, i)), regenv)
> | StDF(x, y, z', i) -> (Ans(StDF(find x Type.Float regenv, find y Type.Int regenv, find' z' regenv, i)), regenv)
142c156
< if List.length ys > Array.length regs - 2 || List.length zs > Array.length fregs - 1 then
---
> if List.length ys > Array.length regs - 1 || List.length zs > Array.length fregs then
147c161
< if List.length ys > Array.length regs - 1 || List.length zs > Array.length fregs - 1 then
---
> if List.length ys > Array.length regs || List.length zs > Array.length fregs then
185a200,201
> if List.length ys > Array.length regs || List.length zs > Array.length fregs then
> Format.eprintf "too many arguments for function %s@." x;
212c228
< let (e', regenv') = g (a, t) (Ans(Mr(a))) regenv e in
---
> let (e', regenv') = g (a, t) (Ans(Mov(a))) regenv e in
Common subdirectories: min-caml-ppc/shootout and min-caml-x86/shootout
diff min-caml-ppc/simm.ml min-caml-x86/simm.ml
3c3
< let rec g env = function (* 命令列の16bit即値最適化 (caml2html: simm13_g) *)
---
> let rec g env = function (* 命令列の即値最適化 (caml2html: simm13_g) *)
5,6c5,6
< | Let((x, t), Li(i), e) when -32768 <= i && i < 32768 ->
< (* Format.eprintf "found simm16 %s = %d@." x i; *)
---
> | Let((x, t), Set(i), e) ->
> (* Format.eprintf "found simm %s = %d@." x i; *)
8c8
< if List.mem x (fv e') then Let((x, t), Li(i), e') else
---
> if List.mem x (fv e') then Let((x, t), Set(i), e') else
11,13d10
< | Let(xt, Slw(y, C(i)), e) when M.mem y env -> (* for array access *)
< (* Format.eprintf "erased redundant Slw on %s@." x; *)
< g env (Let(xt, Li((M.find y env) lsl i), e))
15c12
< and g' env = function (* 各命令の16bit即値最適化 (caml2html: simm13_gprime) *)
---
> and g' env = function (* 各命令の即値最適化 (caml2html: simm13_gprime) *)
19,23c16,19
< | Slw(x, V(y)) when M.mem y env -> Slw(x, C(M.find y env))
< | Lwz(x, V(y)) when M.mem y env -> Lwz(x, C(M.find y env))
< | Stw(x, y, V(z)) when M.mem z env -> Stw(x, y, C(M.find z env))
< | Lfd(x, V(y)) when M.mem y env -> Lfd(x, C(M.find y env))
< | Stfd(x, y, V(z)) when M.mem z env -> Stfd(x, y, C(M.find z env))
---
> | Ld(x, V(y), i) when M.mem y env -> Ld(x, C(M.find y env), i)
> | St(x, y, V(z), i) when M.mem z env -> St(x, y, C(M.find z env), i)
> | LdDF(x, V(y), i) when M.mem y env -> LdDF(x, C(M.find y env), i)
> | StDF(x, y, V(z), i) when M.mem z env -> StDF(x, y, C(M.find z env), i)
37c33
< let h { name = l; args = xs; fargs = ys; body = e; ret = t } = (* トップレベル関数の16bit即値最適化 *)
---
> let h { name = l; args = xs; fargs = ys; body = e; ret = t } = (* トップレベル関数の即値最適化 *)
40c36
< let f (Prog(data, fundefs, e)) = (* プログラム全体の16bit即値最適化 *)
---
> let f (Prog(data, fundefs, e)) = (* プログラム全体の即値最適化 *)
Common subdirectories: min-caml-ppc/test and min-caml-x86/test
diff min-caml-ppc/virtual.ml min-caml-x86/virtual.ml
1c1
< (* translation into PowerPC assembly with infinite number of virtual registers *)
---
> (* translation into assembly with infinite number of virtual registers *)
36c36
< | Closure.Int(i) -> Ans(Li(i))
---
> | Closure.Int(i) -> Ans(Set(i))
47c47,48
< Ans(FLi(l))
---
> let x = Id.genid "l" in
> Let((x, Type.Int), SetL(l), Ans(LdDF(x, C(0), 1)))
51,55c52,56
< | Closure.FNeg(x) -> Ans(FNeg(x))
< | Closure.FAdd(x, y) -> Ans(FAdd(x, y))
< | Closure.FSub(x, y) -> Ans(FSub(x, y))
< | Closure.FMul(x, y) -> Ans(FMul(x, y))
< | Closure.FDiv(x, y) -> Ans(FDiv(x, y))
---
> | Closure.FNeg(x) -> Ans(FNegD(x))
> | Closure.FAdd(x, y) -> Ans(FAddD(x, y))
> | Closure.FSub(x, y) -> Ans(FSubD(x, y))
> | Closure.FMul(x, y) -> Ans(FMulD(x, y))
> | Closure.FDiv(x, y) -> Ans(FDivD(x, y))
73,74c74,75
< | Type.Float -> Ans(FMr(x))
< | _ -> Ans(Mr(x)))
---
> | Type.Float -> Ans(FMovD(x))
> | _ -> Ans(Mov(x)))
82,84c83,85
< (fun y offset store_fv -> seq(Stfd(y, x, C(offset)), store_fv))
< (fun y _ offset store_fv -> seq(Stw(y, x, C(offset)), store_fv)) in
< Let((x, t), Mr(reg_hp),
---
> (fun y offset store_fv -> seq(StDF(y, x, C(offset), 1), store_fv))
> (fun y _ offset store_fv -> seq(St(y, x, C(offset), 1), store_fv)) in
> Let((x, t), Mov(reg_hp),
88c89
< seq(Stw(z, x, C(0)),
---
> seq(St(z, x, C(0), 1),
101,104c102,105
< (0, Ans(Mr(y)))
< (fun x offset store -> seq(Stfd(x, y, C(offset)), store))
< (fun x _ offset store -> seq(Stw(x, y, C(offset)), store)) in
< Let((y, Type.Tuple(List.map (fun x -> M.find x env) xs)), Mr(reg_hp),
---
> (0, Ans(Mov(y)))
> (fun x offset store -> seq(StDF(x, y, C(offset), 1), store))
> (fun x _ offset store -> seq(St(x, y, C(offset), 1), store)) in
> Let((y, Type.Tuple(List.map (fun x -> M.find x env) xs)), Mov(reg_hp),
115c116
< fletd(x, Lfd(y, C(offset)), load))
---
> fletd(x, LdDF(y, C(offset), 1), load))
118c119
< Let((x, t), Lwz(y, C(offset)), load)) in
---
> Let((x, t), Ld(y, C(offset), 1), load)) in
121d121
< let offset = Id.genid "o" in
124,129c124,125
< | Type.Array(Type.Float) ->
< Let((offset, Type.Int), Slw(y, C(3)),
< Ans(Lfd(x, V(offset))))
< | Type.Array(_) ->
< Let((offset, Type.Int), Slw(y, C(2)),
< Ans(Lwz(x, V(offset))))
---
> | Type.Array(Type.Float) -> Ans(LdDF(x, V(y), 8))
> | Type.Array(_) -> Ans(Ld(x, V(y), 4))
132d127
< let offset = Id.genid "o" in
135,140c130,131
< | Type.Array(Type.Float) ->
< Let((offset, Type.Int), Slw(y, C(3)),
< Ans(Stfd(z, x, V(offset))))
< | Type.Array(_) ->
< Let((offset, Type.Int), Slw(y, C(2)),
< Ans(Stw(z, x, V(offset))))
---
> | Type.Array(Type.Float) -> Ans(StDF(z, x, V(y), 8))
> | Type.Array(_) -> Ans(St(z, x, V(y), 4))
151,152c142,143
< (fun z offset load -> fletd(z, Lfd(x, C(offset)), load))
< (fun z t offset load -> Let((z, t), Lwz(x, C(offset)), load)) in
---
> (fun z offset load -> fletd(z, LdDF(x, C(offset), 1), load))
> (fun z t offset load -> Let((z, t), Ld(x, C(offset), 1), load)) in
Common subdirectories: min-caml-ppc/x86 and min-caml-x86/x86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment