sort {$b cmp $a} and the peephole optimiser
Where does the op for cmp go in this? $ perl -MO=Concise -e '@a = sort {$b cmp $a} @b' I see: c @ leave[1 ref] vKP/REFC -(end) 1 0 enter -2 2 ; nextstate(main 2 -e:1) v -3 b 2 aassign[t2] vKS -c -1 ex-list lK -8 3 0 pushmark s -4 7 @ sort lK/DESC -8 4 0 pushmark s -5 6 1 rv2av[t3] lK/1 -7 5 $ gv(*b) s -6 -1 ex-list lK -b 8 0 pushmark s -9 a 1 rv2av[t1] lKRM*/1 -b 9 $ gv(*a) s -a I expected to see an ex-scmp in there. Is the cmp ever compiled to ops? Nicholas Clark '
Re: sort {$b cmp $a} and the peephole optimiser
Nicholas Clark wrote: Where does the op for cmp go in this? $ perl -MO=Concise -e '@a = sort {$b cmp $a} @b' I see: c @ leave[1 ref] vKP/REFC -(end) 1 0 enter -2 2 ; nextstate(main 2 -e:1) v -3 b 2 aassign[t2] vKS -c -1 ex-list lK -8 3 0 pushmark s -4 7 @ sort lK/DESC -8 4 0 pushmark s -5 6 1 rv2av[t3] lK/1 -7 5 $ gv(*b) s -6 -1 ex-list lK -b 8 0 pushmark s -9 a 1 rv2av[t1] lKRM*/1 -b 9 $ gv(*a) s -a I expected to see an ex-scmp in there. Is the cmp ever compiled to ops? yes, but it's freed in S_simplify_sort, called by ck_sort during optree construction, i.e. before the peephole optimizer is called. Concise shows the DESC flag on the sort op that indicates this is a reverse sort.
Re: sort {$b cmp $a} and the peephole optimiser
On Thu, Sep 01, 2005 at 10:59:52AM +0200, Rafael Garcia-Suarez wrote: Nicholas Clark wrote: I expected to see an ex-scmp in there. Is the cmp ever compiled to ops? yes, but it's freed in S_simplify_sort, called by ck_sort during optree construction, i.e. before the peephole optimizer is called. Aha. This was what I was wondering, and also why the departure from perl's usual policy of not free-ing ops during optimisation. Concise shows the DESC flag on the sort op that indicates this is a reverse sort. and there are also NUM and now REVERSE (IIRC) Nicholas Clark