qbe

Internal scc patchset buffer for QBE
Log | Files | Refs | README | LICENSE

max.ssa (574B)


      1 # find the maximum value
      2 # in a nul-terminated array
      3 # of unsigned bytes
      4 #
      5 # the output is stored in $a
      6 
      7 data $arr = { b 10, b -60, b 10, b 100, b 200, b 0 }
      8 
      9 export
     10 function $test() {
     11 @start
     12 @loop
     13 	%max =w phi @start -1, @new %byt, @old %max
     14 	%loc =l phi @start $arr,  @new %loc1, @old %loc1
     15 	%byt =w loadub %loc
     16 	%loc1 =l add 1, %loc
     17 	jnz %byt, @iter, @end
     18 @iter
     19 	%cmp =w cslew %max, %byt
     20 	jnz %cmp, @new, @old
     21 @new
     22 	jmp @loop
     23 @old
     24 	jmp @loop
     25 @end
     26 	storew %max, $a
     27 	ret
     28 }
     29 
     30 # >>> driver
     31 # extern void test(void);
     32 # int a;
     33 # int main() { test(); return !(a == 200); }
     34 # <<<