[Libre-soc-bugs] [Bug 676] FORTRAN MAXLOC SVP64 example
bugzilla-daemon at libre-soc.org
bugzilla-daemon at libre-soc.org
Sat Oct 1 01:31:41 BST 2022
https://bugs.libre-soc.org/show_bug.cgi?id=676
--- Comment #4 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Luke Kenneth Casson Leighton from comment #0)
this one is remarkably simple: use the characteristics
of mapreduce mode to overwrite nm from a parallel
comparison
> int m2(int * const restrict a, int n)
> {
> int m, nm;
> int i;
>
> m = INT_MIN;
> nm = -1;
first prepare offsets
setvl vl=16
sv.svstep offs, srcstep
and nm-potential
li nm, -1
li nmbase, 0
next use CTR mode
> for (i=0; i<n; i++)
> {
setvl r1,0,16,0,1,1 # VL=r1=MIN(MAXVL,CTR)
perform the load of the vector data, elstrided:
sv.ld/els *a, 8(nmbase)
> if (a[i] > m)
> {
comparison:
sv.cmp cr0.gt, *a, m
next, these two both use mapreduce mode with predication
> m = a[i];
sv.ori/mr/m=gt m,*a,0
> nm = i;
add-overwriting base with vector-offset into nm
sv.add/mr/m=gt nm, nmbase, *offs
> }
nmbase must be incremented by vl
add nmbase, nmbase, r1 # r1 contains copy of vl
branch and subtract VL from CTR if not end of loop
sv.bc/all 16, *0, loop
> }
> return nm;
mr r3, nmbase
blr
the trick here is the multiple overwrites of nm and m, even though
they are scalar, the usual "termination of looping because scalar result"
is switched *off* in mapreduce mode.
thus due to the predication the last successful conditional overwrite
"wins"
the second trick was to use a base nm which increments by VL, from a
vector of sequential constants.
there will be better/other methods, using data-dependent failfirst
will stop at the first compare-fail but will need "continuation"
(2 nested loops) whereas the mapreduce one is really simple but
relies on WaW hazards to be eliminated
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the libre-soc-bugs
mailing list