帮我。 [英] Help Me.

查看:54
本文介绍了帮我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我...

我有以下代码,我使用不同的优化方法优化了

优化技术

就像循环展开一样使用指针。


extern long mac(const short * a,const short * b,long sqr,long * sum)

{

int i;

long dotp = * sum;

short c = * b ++;

short d;

for(i = 0; i< 74; i ++)

{

sqr + =(long)c * c;

d = * a ++;

dotp + =(长)c * d;

c = * b ++;

sqr + =(长) c * c;

d = * a ++;

dotp + =(long)c * d;

c = * b ++;

}

sqr + =(长)c * c; / *循环结语* /

d = * a ++;

d = * a ++;

dotp + =(long)c * d;

c = * b ++;

sqr + =(长)c * c;

d = * a ++;

dotp + =(长)c * d;

* sum = dotp;

返回sqr;

}

可以有人建议我在上面的

代码中进一步优化吗?

请帮帮我。


Sumkari

解决方案

ku ******* *@gmail.com 写道:


任何人都可以帮助我...

我有以下代码我已优化使用不同的

优化技术

像循环展开,使用指针。



< snip>


>

有人建议我在上面的

代码中进一步优化吗?



您的探查者告诉您什么?我假设你在优化之前对你的代码进行了描述。


-

Ian Collins。


Ian Collins写道:

ku ** ******@gmail.com 写道:


>任何人都可以帮助我...
我有以下代码我已经使用不同的优化技术进行了优化,例如循环展开,使用指针。



< snip>


>有人建议我在上面的代码中进一步优化吗?



你的探查者告诉你什么?我假设你在优化它之前对你的代码进行了分析。



完全正确。记住Hoare'的定律/ Knuth'定律(归因各不相同):

过早优化是所有邪恶的根源。


< blockquote> Hi Sukumari,


我有以下代码,我使用不同的优化优化

优化技术

like循环展开,使用指针。



使用指针并不意味着优化代码。


你没有提到你的代码是什么意思。很抱歉,它说它是b $ b有一些错误。


short c = * b ++;



这里指针b增加而不是b的值。即使你想要增加价值,你也不能这样做,因为它是一个常数。


和a,b的所有增量都会导致指针增加你的代码

和输出是未定义的。


简要说明mac函数的作用。


- - Murali Krishna


Can anybody help me...
I have following code which I have optimized using different
optimization techniques
like loop unrolling, use of pointers.

extern long mac(const short *a, const short *b, long sqr, long * sum)
{
int i;
long dotp = *sum;
short c = *b++;
short d;
for (i = 0; i < 74; i++)
{
sqr += (long)c * c;
d = *a++;
dotp += (long)c * d;
c = *b++;
sqr += (long)c * c;
d = *a++;
dotp += (long)c * d;
c = *b++;
}
sqr += (long)c * c; /* Loop epilogue */
d = *a++;
d = *a++;
dotp += (long)c * d;
c = *b++;
sqr += (long)c * c;
d = *a++;
dotp += (long)c * d;
*sum = dotp;
return sqr;
}
Can anybody suggest me any further optimization possible in the above
code?
Please help me.

Sumkari

解决方案

ku********@gmail.com wrote:

Can anybody help me...
I have following code which I have optimized using different
optimization techniques
like loop unrolling, use of pointers.

<snip>

>
Can anybody suggest me any further optimization possible in the above
code?

What does your profiler tell you? I assume you profiled the code before
you optimised it.

--
Ian Collins.


Ian Collins wrote:

ku********@gmail.com wrote:

>Can anybody help me...
I have following code which I have optimized using different
optimization techniques
like loop unrolling, use of pointers.

<snip>

>Can anybody suggest me any further optimization possible in the above
code?


What does your profiler tell you? I assume you profiled the code before
you optimised it.

Exactly. Remember Hoare''s Law/Knuth''s Law (attribution varies):
"Premature optimization is the root of all evil".


Hi Sukumari,

I have following code which I have optimized using different
optimization techniques
like loop unrolling, use of pointers.

use of pointers doesn''t mean optimizing the code.

you did not mention what your code is meant for. Sorry to say that it
has some bugs.

short c = *b++;

here pointer b is incremented not the value of b. even if you wanted to
increment the value, you cannot do that because it is a constant.

and all increments to a, b will lead to pointer increment in your code
and the ouput is undefined.

Specify briefly what mac function does.

-- Murali Krishna


这篇关于帮我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆