Changeset 1585 for Deliverables/D2.2/8051/src/RTLabs
 Timestamp:
 Dec 2, 2011, 7:49:19 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Deliverables/D2.2/8051/src/RTLabs/RTLabsToRTL.ml
r1584 r1585 294 294  I8051.Add > 295 295 (* we perform a first add followed by Addc's *) 296 let f destr srcr1 srcr2 (op, insts) = 297 (I8051.Addc, f_add op destr srcr1 srcr2 :: insts) in 298 snd (MiscPottier.fold3_right 299 f destrs_common srcrs1_common srcrs2_common (I8051.Add, [])) 296 begin match destrs_common, srcrs1_common, srcrs2_common with 297  destr :: destrs, srcr1 :: srcrs1, srcr2 :: srcrs2 > 298 f_add op destr srcr1 srcr2 :: 299 MiscPottier.map3 (f_add I8051.Addc) destrs srcrs1 srcrs2 300  [], [], [] > [] 301  _ > assert false 302 end 300 303  _ > 301 304 (* we just do the same operation on all *) … … 332 335 (* the next must be an invariant *) 333 336 assert (srcrs1_n = destrs_n && destrs_n = srcrs1_n); 334 (* we pad destrs with a copy of itself that will be added to it at the end 335 (when the multiplication overflows) and then three more. The routine 336 should thus handle overflow nicely, but it must be checked *) 337 let all_destrs = MiscPottier.fill destrs (2 * destrs_n + 3) in 337 (* we pad destrs with itself until we have two times as much 338 registers. The routine should thus handle overflow nicely. *) 339 let all_destrs = MiscPottier.fill destrs (2 * destrs_n) in 338 340 let init = translate_cst (AST.Cst_int 0) destrs :: init in 339 341 (* the registries to hold the temporary results of 8bit mutliplication *) 340 342 let (def, a) = fresh_reg def in 341 343 let (def, b) = fresh_reg def in 342 (* when getting the result, this is what is used (padded to 3 bytes *) 343 let mul_arg = [RTL.Reg a ; RTL.Reg b ; RTL.Imm 0] in 344 (* when getting the result, this is what is used (padded as necessary) *) 345 let mul_arg k = [RTL.Reg a ; RTL.Reg b] @ 346 MiscPottier.make (RTL.Imm 0) (2*destrs_n  k  2) in 347 (* multiplication between the ith byte of srcrs1 and the jth byte of 348 srcrs2 *) 344 349 let mul i j = 345 let s1i, s2j = List.nth fresh_srcrs1 i, List.nth fresh_srcrs2 i in 350 let s1i, s2j = List.nth fresh_srcrs1 i, List.nth fresh_srcrs2 j in 351 (* the position in the result where the resulting bytes must be added *) 346 352 let k = i + j in 347 let dloc = MiscPottier.sublist all_destrs k ( k+3) in353 let dloc = MiscPottier.sublist all_destrs k (2*destrs_n) in 348 354 let dloc_arg = List.map (fun r > RTL.Reg r) dloc in 355 (* we add until the end to propagate the carry bit. 356 At the beginning this will be useless, but we rely on 357 RTL's constant propagation and later dead register elimination 358 to amend that *) 349 359 [ adds_graph [RTL.St_opaccs (I8051.Mul, a, b, s1i, s2j, start_lbl)] ; 350 translate_op I8051.Add dloc dloc_arg mul_arg] in360 translate_op I8051.Add dloc dloc_arg (mul_arg k)] in 351 361 let insts = List.flatten (List.flatten 352 362 (MiscPottier.makei (fun i >
Note: See TracChangeset
for help on using the changeset viewer.