Path: chuka.playstation.co.uk!news From: "Jon Prestidge (Jon@surfed.to)" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Daft Question [long] Date: Mon, 3 Sep 2001 15:02:05 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 91 Message-ID: <9n02je$s3h11@www.netyaroze-europe.com> References: <9m9c88$ioj5@www.netyaroze-europe.com> <01c12edc$cc2bf440$991fe4d5@pal-s-omnibook> <9me1g1$1sb13@www.netyaroze-europe.com> <9meajl$1sb17@www.netyaroze-europe.com> <9med8s$1sb18@www.netyaroze-europe.com> <9mekaq$1sb20@www.netyaroze-europe.com> <3b915bb2.83462112@www.netyaroze-europe.com> <9mm6uc$h6i10@www.netyaroze-europe.com> <9mmc13$ijv4@www.netyaroze-europe.com> <3b910a19.35654388@www.netyaroze-europe.com> <9mnuqp$ijv10@www.netyaroze-europe.com> <3b91fcdf.71163828@www.netyaroze-europe.com> NNTP-Posting-Host: host213-122-165-16.btinternet.com X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 I did a few little experiments. It seems that CW does convert /1024 to a right shift 10 (when in optimized mode) but it also has to put in an add 1023 and a conditional branch (I guess it's incase the number is negative since I don't think right shifts on negative numbers work quit the same). So it's still worth doing >>10 instead of /1024 -- it'll save a couple instructions I think. I've pasted the disassemblies etc below. See example 3 for the optimized one. I've not bothered putting in the optimized example of ">>10" because thats basically all it was: a right shift 10 (it even bypassed loading the paremeter from the stack etc and it just jumped straight to the single CPU instruction from the calling code and straight back again) Jon EXAMPLE1--------------------------- (no optimization) long test( long a ) { a >>= 10; return a; } addiu sp,sp,-4 sw s0,0(sp) addu s0,a0,$0 sra s0,s0,10 addu v0,s0,$0 lw s0,0(sp) jr ra addiu sp,sp,4 EXAMPLE 2------------------------------- (no optimization) long test( long a ) { a /= 1024; return a; } addiu sp,sp,-4 sw s0,0(sp) addu s0,a0,$0 bgez s0,*+16 ; 0x00000048 sra t9,s0,10 addiu a0,s0,1023 sra t9,a0,10 addu s0,t9,$0 addu v0,s0,$0 lw s0,0(sp) jr ra addiu sp,sp,4 EXAMPLE 3----------------------------------------- (optimization level 4) long test( long a ) { a /= 1024; return a; } bgez a0,*+16 ; 0x00000018 sra t9,a0,10 addiu a0,a0,1023 sra t9,a0,10 addu a0,t9,$0 jr ra addu v0,a0,$0 ----------------------------------------------