From: Luke Kenneth Casson Leighton Date: Tue, 14 Nov 2023 11:58:09 +0000 (+0000) Subject: fix maxloc X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=097d1fd52b15113f11b90446d060931618ed06c5;p=openpower-isa.git fix maxloc --- diff --git a/maxloc/maxloc.c b/maxloc/maxloc.c index e37160c6..f0786e73 100644 --- a/maxloc/maxloc.c +++ b/maxloc/maxloc.c @@ -1,23 +1,22 @@ -#include +#include int m2(int *a, int n) { - int m, nm; - int i; + int m = 0; + int nm = -1; + int i = 0; - m = 0; - nm = -1; - i=0; while (i m) { - m = a[i]; - nm = i; - } - i++; + while (i < n && a[i] > m) { + printf("%d idx %d > m %d\n", i, a[i], m); + m = a[i]; + nm = i; + i++; + } } return nm; }