libqbe/test/max.ssa

35 lines
574 B
Text
Raw Normal View History

2015-08-09 19:34:20 -04:00
# find the maximum value
# in a nul-terminated array
# of unsigned bytes
#
2015-10-07 22:32:58 -04:00
# the output is stored in $a
data $arr = { b 10, b -60, b 10, b 100, b 200, b 0 }
2015-08-09 19:34:20 -04:00
2016-03-28 10:30:55 -04:00
export
2015-09-18 12:27:50 -04:00
function $test() {
2015-09-14 18:06:29 -04:00
@start
@loop
2015-08-09 19:34:20 -04:00
%max =w phi @start -1, @new %byt, @old %max
2015-10-07 22:32:58 -04:00
%loc =l phi @start $arr, @new %loc1, @old %loc1
2015-08-09 19:34:20 -04:00
%byt =w loadub %loc
%loc1 =l add 1, %loc
2015-08-09 19:34:20 -04:00
jnz %byt, @iter, @end
2015-09-14 18:06:29 -04:00
@iter
2016-02-11 20:02:31 -05:00
%cmp =w cslew %max, %byt
2015-08-09 19:34:20 -04:00
jnz %cmp, @new, @old
2015-09-14 18:06:29 -04:00
@new
2015-08-09 19:34:20 -04:00
jmp @loop
2015-09-14 18:06:29 -04:00
@old
2015-08-09 19:34:20 -04:00
jmp @loop
2015-09-14 18:06:29 -04:00
@end
2015-08-11 16:39:05 -04:00
storew %max, $a
2015-08-09 19:34:20 -04:00
ret
}
# >>> driver
# extern void test(void);
# int a;
# int main() { test(); return !(a == 200); }
# <<<