Changeset 641


Ignore:
Timestamp:
Mar 7, 2011, 2:18:53 PM (9 years ago)
Author:
ayache
Message:

Improvement in the code of the cost computation in D2.2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D2.2/8051/src/ASM/ASMCosts.ml

    r634 r641  
    4444
    4545
    46 let compare pc1 cost1 pc2 cost2 =
    47   if cost1 <> cost2 then
     46let rec compare = function
     47  | [] -> assert false (* do not use an this argument *)
     48  | [(_, cost)] -> cost
     49  | (pc1, cost1) :: (pc2, cost2) :: l when cost1 <> cost2 ->
    4850    warning
    4951      (Printf.sprintf
    5052         "Warning: branching to %s has cost %d, branching to %s has cost %d"
    51          "*fixme*" (* pc1 *) cost1 "*fixme*" (* pc2 *) cost2) ;
    52   max cost1 cost2
     53         (string_of_int (BitVectors.int_of_vect pc1)) cost1
     54         (string_of_int (BitVectors.int_of_vect pc2)) cost2) ;
     55    max cost1 (compare ((pc2, cost2) :: l))
     56  | _ :: l -> compare l
    5357
    5458let rec block_costl mem costs = function
    5559  | [] -> 0
    5660  | [pc] when BitVectors.WordMap.mem pc costs -> 0
    57   | [pc] ->
    58     let (_, _, next_pcs, cost) = inst_infos mem pc in
    59     cost + (block_costl mem costs next_pcs)
    60   | pc1 :: pc2 :: _ ->
    61     let cost1 = block_costl mem costs [pc1] in
    62     let cost2 = block_costl mem costs [pc2] in
    63     compare pc1 cost1 pc2 cost2
     61  | next_pcs ->
     62    compare (List.map (fun pc -> (pc, block_cost mem costs pc)) next_pcs)
    6463
    65 let block_cost mem costs pc = block_costl mem costs [pc]
     64and block_cost mem costs pc =
     65  let (_, _, next_pcs, cost) = inst_infos mem pc in
     66  cost + (block_costl mem costs next_pcs)
    6667
    6768
     
    7374      | _::tl when BitVectors.WordMap.mem pc p.ASM.cost_labels ->
    7475        let lbl = BitVectors.WordMap.find pc p.ASM.cost_labels in
    75         let cost = block_cost mem p.ASM.cost_labels newpc in
     76        let cost = block_cost mem p.ASM.cost_labels pc in
    7677        let costs_mapping = aux newpc tl in
    7778        CostLabel.Map.add lbl cost costs_mapping
Note: See TracChangeset for help on using the changeset viewer.