Home » Developing U++ » U++ Developers corner » "better" version of Iscale functions
Re: "better" version of Iscale functions [message #15167 is a reply to message #15166] |
Sun, 06 April 2008 20:05   |
mdelfede
Messages: 1308 Registered: September 2007
|
Ultimate Contributor |
|
|
Btw, I guess GCC does some better optimizazions in this case :
int iscale(int x, int y, int z)
{
int64_t res = x;
res *= y;
res /= z;
return (int)res;
}
gets translated as :
.globl _ZN3Upp6iscaleEiii
.type _ZN3Upp6iscaleEiii, @function
_ZN3Upp6iscaleEiii:
.LFB4039:
.file 4 "/home/massimo/sources/upp-svn/uppsrc/Core/mathutil.cpp"
.loc 4 11 0
pushq %rbp
.LCFI15:
movq %rsp, %rbp
.LCFI16:
movl %edi, -20(%rbp)
movl %esi, -24(%rbp)
movl %edx, -28(%rbp)
.LBB2:
.loc 4 17 0
movl -20(%rbp), %eax
cltq
movq %rax, -8(%rbp)
.loc 4 18 0
movl -24(%rbp), %eax
movslq %eax,%rdx
movq -8(%rbp), %rax
imulq %rdx, %rax
movq %rax, -8(%rbp)
.loc 4 19 0
movl -28(%rbp), %eax
cltq
movq -8(%rbp), %rdx
movq %rax, %rcx
movq %rdx, %rax
sarq $63, %rdx
idivq %rcx
movq %rax, -8(%rbp)
.loc 4 20 0
movq -8(%rbp), %rax
.LBE2:
.loc 4 30 0
leave
ret
If you drop assembly directive and/or line references and other stuffs, you can see that work is done with just one imul and one idiv... like your assembly version. The rest is just registry moving stuffs. I don't know what happens if you compile it with full optimization, but I guess mostly of them just disappears.
And I think that's still much quicker than floating point version.
Max
[Updated on: Sun, 06 April 2008 20:06] Report message to a moderator
|
|
|
 |
|
"better" version of Iscale functions
By: mdelfede on Tue, 01 April 2008 23:10
|
 |
|
Re: "better" version of Iscale functions
By: mirek on Wed, 02 April 2008 15:11
|
 |
|
Re: "better" version of Iscale functions
By: mdelfede on Wed, 02 April 2008 16:48
|
 |
|
Re: "better" version of Iscale functions
By: mirek on Sun, 06 April 2008 04:47
|
 |
|
Re: "better" version of Iscale functions
By: mdelfede on Sun, 06 April 2008 19:36
|
 |
|
Re: "better" version of Iscale functions
By: mdelfede on Sun, 06 April 2008 20:05
|
 |
|
Re: "better" version of Iscale functions
By: mdelfede on Sun, 06 April 2008 20:14
|
 |
|
Re: "better" version of Iscale functions
By: mirek on Thu, 10 April 2008 02:44
|
 |
|
Re: "better" version of Iscale functions
By: mirek on Thu, 10 April 2008 02:46
|
 |
|
Re: "better" version of Iscale functions
By: mdelfede on Thu, 10 April 2008 15:07
|
 |
|
Re: "better" version of Iscale functions
By: mirek on Thu, 10 April 2008 18:01
|
 |
|
Re: "better" version of Iscale functions
By: mdelfede on Fri, 11 April 2008 09:26
|
 |
|
Re: "better" version of Iscale functions
By: mirek on Sun, 06 April 2008 04:51
|
Goto Forum:
Current Time: Fri Jul 18 07:24:23 CEST 2025
Total time taken to generate the page: 0.00558 seconds
|