         Edinburgh IMP77 Compiler - Version 8.4
    1 !
				.machine ppc
				.section	".text"
		.Ltext0:
				.align 2
				.globl main
		main:
		.LFB185:
    2 ! The hand-generated code below should be producable by PSR's compiler if it:
    3 ! A) delays stores as late as possible
    4 !
    5 ! B) remembers registers over procedure calls
    6 !
    7 ! C) has a general algorithm for drop-through conditionally executed
    8 !    instructions, i.e. if there are no instructions between a conditional
    9 !    branch and its destination which set the condition codes, and the
   10 !    sequence is less that a certain length, then all the instructions
   11 !    within the sequence can be made conditional.
   12 !
   13 ! D) does as above, but also allows instructions within the sequence
   14 !    whose subsequent execution depends on the same condition, e.g.
   15 !
   16 !    %if a=b %and c=d %then a=b
   17 !
   18 !    CmpS   R0,R1            NAIVE STYLE
   19 !    Bne    elsepart
   20 !    Cmps   R2,R3
   21 !    Bne    elsepart
   22 !    Mov    R0,R2
   23 !
   24 !    CmpS   R0,R1            RULE (C) ABOVE
   25 !    Bne    elsepart
   26 !    CmpS   R2,R3
   27 !    MovEQ  R0,R2
   28 !
   29 !    CmpS   R0,R1            RULE (D) SPECIAL CASE
   30 !    CmpSEQ R2,R3
   31 !    MovEQ  R0,R2
   32 !
   33 ! E) alters conditions to generate similar condition codes on
   34 !    condition AND condition AND condition to generate more cases
   35 !    to which rule (D) can be applied.
   36 !
   37 ! F) adjusts constants in < or <= cases to favour above, i.e. turning
   38 !    CMP R,#const & BLE ... into CMP R,#const-1 & BLT ... etc.
   39 !
   40 ! G) changes Newline back from the current implicit printsymbol(10) -
   41 !    there is no run-time overhead in moving the MOV R0,#10 over to
   42 !    the procedure body instead of having it in every call where it
   43 !    takes up space - after all, Peter's code-moving stuff ought to
   44 !    get %permroutine newline;printsymbol(10);%end correct - it will
   45 !    place the Mov R0,#10 before the body of %permroutine printsymbol
   46 !    and generate a suitable entry point for it...
   47 !       Personally, I would recommend stacking/restoring R0 as well
   48 !    as it might keep another variable in a register for a bit longer...
   49 !
   50 ! I've only suggested optimisations which fit into the style of PSR's
   51 ! compilers...
   52 !
   53
   54
   55 %begin
		.LVL0:
				stwu 1,-32(1)
				mflr 0
				stw 0,36(1)
				lwz 9,-28680(2)
				stw 9,28(1)
				li 9,0
   56 %integer a,i,b
				bl _imp_initialise
		.LVL1:
   57
   58   read(a)
				addi 3,1,16
				bl _imp_readint
		.LVL2:
   59 ! BL     read_fn
   60
   61 ! Str    R0,a
   62   read(i)
				addi 3,1,20
				bl _imp_readint
		.LVL3:
   63 ! BL     read_fn
   64
   65 ! Str    R0,i
   66   read(b)
				addi 3,1,24
				bl _imp_readint
		.LVL4:
		.LBB14:
   67 ! BL     read_fn
   68
   69   %if a <= i <= b %start
   70 ! Ldr R1,a
   71 ! Ldr R2,i
   72 ! CmpS   R1,R2
				lwz 9,20(1)
		.LVL5:
				lwz 3,16(1)
				cmpw 7,9,3
				blt 7,.L2
   73 ! CmpSLE R2,R0
   74     i = 22
				lwz 10,24(1)
				cmpw 7,9,10
				bgt 7,.L3
		.LBE14:
				li 9,22
		.LVL6:
				stw 9,20(1)
		.LVL7:
		.LBB15:
   75 ! MovLE  R2,#22
   76   %finish
   77
   78   %if 22 <= i <= b %start
   79 ! CmpS   R2,#22-1
   80 ! CmpSGT R2,R0
   81     i = 44
				cmpwi 7,9,21
				ble 7,.L9
		.LVL10:
		.L4:
		.LBE16:
		.LBB17:
				cmpwi 7,9,21
				bgt 7,.L13
		.LVL14:
		.L7:
		.LBE18:
		.LBB19:
				lwz 9,20(1)
				addi 9,9,-11
				cmplwi 7,9,89
				ble 7,.L5
		.LVL15:
		.L8:
		.LBE19:
   82 ! MovGT  R2,#44
   83   %finish
				cmpwi 7,10,21
				ble 7,.L4
		.LVL8:
		.L5:
		.LBE15:
				lwz 10,24(1)
				cmpw 7,9,10
				ble 7,.L5
				b .L7
		.LBE28:
		.LFE185:
		.Letext0:
   84
   85   %if a <= i <= 77 %start
   86 ! CmpS   R1,R2
   87 ! CmpSLE R2,#77
   88     i = 99
				lwz 9,20(1)
		.LVL11:
				cmpw 7,3,9
				bgt 7,.L7
		.LVL12:
		.L9:
   89 ! MovLE  R2,#99
   90   %finish
				cmpwi 7,9,77
				bgt 7,.L7
				b .L5
		.LVL13:
		.L2:
		.LBE17:
		.LBB18:
   91
   92   %if 11 <= i <= 100 %start     ;! Peter's special case when both const is good
   93 ! Sub   R2,#11                  ;! but usually corrupts a register needed later
   94 ! CmpS  R2,#100-11
   95     i = 1
				li 9,1
				stw 9,20(1)
				b .L8
		.LVL9:
		.L3:
		.LBB16:
   96 ! MovLS R2,#1
   97   %finish
   98
   99 ! Str   R0,b
  100   write(a,0)
				li 4,0
				bl _imp_writeint
		.LVL16:
		.LBB20:
		.LBB21:
				bl _imp_newline
		.LVL17:
		.LBE21:
		.LBE20:
  101 ! Mov   R0,R1
  102 ! Mov   R1,#0
  103 ! Bl    Write
  104
  105   newline
  106 ! Bl    Newline
  107
  108 ! Mov   R0,R2
  109   write(i,0)
				li 4,0
				lwz 3,20(1)
				bl _imp_writeint
		.LVL18:
		.LBB22:
		.LBB23:
				bl _imp_newline
		.LVL19:
		.LBE23:
		.LBE22:
  110 ! Bl    write
  111
  112   newline
  113 ! Bl    newline
  114
  115   write(b,0)
				li 4,0
				lwz 3,24(1)
				bl _imp_writeint
		.LVL20:
		.LBB24:
		.LBB25:
				bl _imp_newline
		.LVL21:
		.LBE25:
		.LBE24:
		.LBB26:
		.LBB27:
				li 3,0
				bl exit
		.LVL22:
		.L13:
		.LBE27:
		.LBE26:
		.LBB28:
  116 ! Ldr   R0,b
  117 ! Bl    write
  118
  119   newline
  120 ! Bl    newline
  121
  122 %endofprogram
   24 Statements compiled
