将我的想法添加到C ++编译器 [英] Add My Idea to the C++ Compiler

查看:62
本文介绍了将我的想法添加到C ++编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能会注意到开关(...)比功能快得多,因为它只使用JMP指令,因此它可以获得很大的改进性能

功能是需要使用CALL,PUSH和POP指令,这些指令可能比较慢。

我在一个数组中创建了三个函数。数组被称为

pArray_Func [xx]()。 pArray_Func [xx]()包含三个函数。 " XX"可以用

用于指出每个功能。

比方说,我有超过1000个功能。我会把内联每个

函数。每个函数可能包含超过50行
行并不重要。 C / C ++编译器告诉内联是真的很大。用于

短只需3-5行。我决定通过强制

内联来告诉C / C ++编译器。因为我不在乎我的代码是越来越大。

我允许将50行复制到每个函数中。 CALL,PUSH和POP

指令总是可以通过C / C ++编译器自动删除

,然后总是可以为每个函数放置JMP指令。

根据我的设计我非常整洁。如果我想保留

小代码而不是大代码,内联不应该使用。

现在,有一个大问题。我不能放置内联进入

pArray_Func [xx]()。我明白为什么。 JMP可以显示JMP [EAX + EDX * 4],这将是
工作正常。 C / C ++编译器只能将CALL [EAX + EDX * 4]放入

pArrayFunc [xx]()。它不是为了取代CALL [EAX + EDX * 4]而设计的。

" JMP [EAX + EDX * 4] ifinline在那儿。 C / C ++编译器将始终忽略

内联。

另一种选择是在switch(...)中放置1,000个函数。看看

如下所示。


开关(xx)

{

案例1:

Func1();

案例2:

Func2();

案例3:

Func3();

}


C / C ++编译器在它可以放置内联之前可以看到上面的代码。

每个函数在switch(...)内。这让我非常讨厌,因为我通过向上/向下滚动来逐行读取开关(...)。对我来说,这是非常好的b $ b。找到BUG并不是很难(我的观点)。

我希望只看到3或4行,而不是超过20,000行

包含开关(。 ..)。 pArrayFunc()可能非常有用。我们应该告诉C / C ++作者添加像__USE_JMP_INLINE这样的关键字而不是

__inline,_inline或inline。

最新版本的C像英特尔编译器这样的/ C ++编译器可以接受

__USE_JMP_INLINE。 " __ USE_JMP_INLINE"将被添加到pArrayFunc [xx](),但是

inline 1,000个功能总是相同的。在编译了

C ++源代码之后,它将识别出__ USE_JMP_INLINE,它将从

CALL [EAX + EDX * 4]重命名。到JMP [EAX + EDX * 4]所以每个函数''PUSH和POP

指令都将被删除。它看起来就像真正的JMP表格里面

pArrayFunc [xx]()。这对于轻松阅读来说是完美的。

请说明您对我修改C / C ++

编译器源代码的想法的看法。 ***不要告诉所有C / C ++编译器都没有__USE_JMP_INLINE。请让作者添加__USE_JMP_INLINE关键字。

这将是完美而简洁的C ++编码。***


我已经把pArrayFunc [xx]()在下面的C ++类示例中。它会给你一个想法,然后__ USE_JMP_INLINE。不存在,但应该添加

将来。


#include< stdio.h>


class Test


{


public:


inline void Get_a(){printf (A:%d \ n,_a); }


inline void Get_b(){printf(" B:%d \ n",_ b); }


inline void Get_c(){printf(" C:%d \ n",_ c); }


inline void Set_a(unsigned int a){_ a = a; }


inline void Set_b(unsigned int b){_ b = b; }


inline void Set_c(unsigned int c){_ c = c; }


typedef void(Test :: * Action)();


静态const动作菜单[3];


inline void调用();


private:


unsigned int _a;


unsigned int _b;


unsigned int _c;


};


const Test :: Action Test :: Menu [3] =


{


& Test :: Get_a,


& Test :: Get_b,


& Test :: Get_c


};


inline void Test :: Call()


{


for(int a = 0; a < = 2; a ++)


(this-> *菜单[a])();


}


无效主(无效)


{


测试;


test.Set_a(1);


test.Set_b(2);


test.Set_c(3);


test.Call();


返回;


}

-

Bryan Parkoff

解方案
"布赖恩Parkoff" <峰; br ****************** @ nospam.com>写道...

您可能会注意到开关(...)比可以获得大幅提升性能的功能快得多,因为它只使用JMP指令
但功能需要使用速度较慢的CALL,PUSH和POP指令。


可以这里是关键。

我在一个数组中创建了三个函数。数组叫做pArray_Func [xx]()。 pArray_Func [xx]()包含三个函数。 " XX"可以用
来指出每个功能。
比方说,我有超过1000个功能。我会把内联到每个
功能。每个函数可能包含超过50行并不重要。 C / C ++编译器告诉内联是真的很大。用于
短仅3-5行。我决定通过
强制内联来告诉C / C ++编译器。那里因为我不在乎我的代码是否越来越大,
更大。


编译器可以简单地告诉你亲自去亲自完全

忽略您的''内联''关键字。你不知道它不是强制性的吗?

我允许将50行复制到每个函数中。 C / C ++编译器总是可以自动删除CALL,PUSH和POP
指令,然后总是可以为每个函数放置JMP指令。
根据我的设计我非常整洁通缉。如果我关心
保留小代码而不是大代码,内联不应该使用。
现在,有一个大问题。我不能放置内联进入
pArray_Func [xx]()。我明白为什么。 JMP可以显示JMP [EAX + EDX * 4],
将正常工作。 C / C ++编译器只能将CALL [EAX + EDX * 4]放入pArrayFunc [xx]()中。它不是为了取代CALL [EAX + EDX * 4]而设计的。
toJMP [EAX + EDX * 4] ifinline在那儿。 C / C ++编译器将始终忽略
inline。


再次,''inline''只是对编译器的建议。编译器

不必遵循它。

另一种选择是在switch(...)中放置1,000个函数。看下面的


开关(xx)
{
案例1:
Func1();
案例2:
Func2();
案例3:
Func3();
}
C / C ++编译器在它可以放置内联之前可以看到上面的代码。
开关内的每个功能(...)。这让我非常讨厌,因为我通过向上/向下滚动来逐行读取开关(...)。这对我来说非常漫长。找到BUG并不难(我的观点)。


嗯,这完全取决于你不要这样做。你可以将你的''xx''

值分组并设计另一层功能,你可以在其中使用另一层次的间接:

if(xx <100)

callOneOfLessThan100Funcs(xx);

else if(xx< 200)

callOneOfLessThan200Funcs (xx);

...

我希望只看到3或4行,而不是超过20,000
行包含开关(... )。 pArrayFunc()可能非常有用。我们应该告诉C / C ++作者添加像__USE_JMP_INLINE这样的关键字而不是
__ inline,_inline或inline。


请不要将_us_混入您的计划中。 _You_需要这个,_you_

似乎已经考虑过了,所以_you_应该去comp.std.c ++

并建议在语言中添加一些东西。 _They_会听取并且

回答。

最新版本的C / C ++编译器如Intel Compiler可以接受
__USE_JMP_INLINE。 " __ USE_JMP_INLINE"将被添加到pArrayFunc [xx](),
但是inline 1,000个功能总是相同的。编译完C ++源代码后,它将识别__ USE_JMP_INLINE,它将从
CALL [EAX + EDX * 4]重命名。到JMP [EAX + EDX * 4]所以每个功能的'PUSH和POP
指令都将被删除。它看起来像pArrayFunc [xx]()里面真正的JMP表。它非常适合轻松阅读。


轻松阅读?

请说明您对我修改C / C ++
编译器来源的想法的看法码。 ***不要告诉所有C / C ++编译器都没有__USE_JMP_INLINE
。请让作者添加__USE_JMP_INLINE
关键字。这将是完美和整洁的C ++编码。***


请转到comp.std.c ++并自己动手。

我已经把pArrayFunc [ xx]()里面的C ++类示例。然而,它为你提供了一个想法__ USE_JMP_INLINE不存在,但应该在未来附近添加

#include< stdio.h>

上课测试

{

公开:

内联空格Get_a(){printf(" A:%d \ n",_ a);内联void Get_b(){printf(" B:%d \ n",_ b);内联空格Get_c(){printf(" C:%d \ n",_ c);内联void Set_a(unsigned int a){_ a = a;内联void Set_b(unsigned int b){_ b = b;内联void Set_c(unsigned int c){_ c = c; }

typedef void(Test :: * Action)();

静态const动作菜单[3];

内联void Call() ;

私有:

unsigned int _a;

unsigned int _b;

unsigned int _c;

};

const测试::动作测试::菜单[3] =

{

&测试:: Get_a,

& Test :: Get_b,

& Test :: Get_c

};

内联void Test :: Call()


对于(int a = 0; a< = 2; a ++)

(这 - > *菜单[a])();

}

主要(无效)


您最好学习使用


int main()

否则comp.std.c ++中的人可能甚至不会认真对待你。
{

测试;

test.Set_a(1);

测试.Set_b(2);

test.Set_c(3);

test.Call();

返回;

}




编译器可以忽略内联指令。这是因为制作一个函数

inline实际上可以减慢代码速度。我不知道所有的细节,但是由于额外的内存需求(缓存大小等等),有一个大型编译程序的
会降低速度。相关的,

不仅仅是系统内存总量。)

-

John Carson

1.回复发送电子邮件至地址,删除donald

2.不要回复电子邮件地址(在此处发帖)


Victor,


我已将我的文章的副本发布到comp.std.c ++。请原谅我

,我知道大多数C / C ++编译器IGNORE内联除非我可以强迫他们支持我的愿望。

编译器可以简单地告诉你亲自去亲自完全
忽略你的''inline''关键词。难道你不知道它不是强制性的吗?

再次,''inline''只是对编译器的建议。编译器
不必遵循它。



我使用的是英特尔C / C ++编译器7.1。实际上,英特尔C / C ++编译器不会忽略内联。除非我告诉英特尔C / C ++编译器遵循我的愿望,不像其他通用的C / C ++编译器,如Microsoft,GCC,G ++或其他Unix

编译器。 />
你可能会惊讶于英特尔C / C ++编译器可以给我一个选择,如果

我想使用inline或不。它有像保持内联的开关。或者

忽略内联然而,大多数通用的C / C ++编译器没有开关所以

他们总是忽略内联。

我希望你理解我的观点。


Bryan Parkoff


You may notice that switch (...) is much faster than function that can
gain a big improved performance because it only use JMP instruction however
function is required to use CALL, PUSH, and POP instruction that can be
slower.
I created three functions in an array. Array is called
pArray_Func[xx](). pArray_Func[xx]() contains three functions. "xx" can be
used to point each function.
Let say, I have over 1,000 functions. I would put "inline" to each
functions. It does not matter that each function may contain more than 50
lines. It is really BIG that C/C++ compiler tells "inline" is used for
short like 3-5 lines ONLY. I have decided to tell C/C++ compiler by forcing
"inline" there because I don''t care if my code is getting bigger and bigger.
I allow 50 lines to be copied to each functions. CALL, PUSH, and POP
instructions can always be removed automatically by the C/C++ compiler
before JMP instruction can always be placed each function.
It is very neat according to my design that I wanted. If I care to keep
small code rather than big code, "inline" should not be used.
Right now, there is a big problem. I can''t place "inline" into
pArray_Func[xx](). I can see why. JMP can show "JMP [EAX+EDX*4] that will
work fine. C/C++ compiler can only place "CALL [EAX+EDX*4] into
pArrayFunc[xx](). It is not designed to replace from "CALL [EAX+EDX*4]" to
"JMP [EAX+EDX*4] if "inline" is there. C/C++ compiler will always ignore
"inline".
Another option is to place 1,000 functions inside switch (...). Look
like below.

switch (xx)
{
case 1:
Func1();
case 2:
Func2();
case 3:
Func3();
}

C/C++ compiler can see this code above before it can place "inline" to
each functions inside switch (...). It is very annoying me because I have
to read switch (...) from line to line by scrolling up/down. It is very
long for me to read. It is not HARD to FIND BUG (off my point).
I would want to see only 3 or 4 lines there instead of over 20,000 lines
that contains switch (...). pArrayFunc() may be very useful. We should
tell the C/C++ authors to add keyword like __USE_JMP_INLINE instead of
__inline, _inline, or inline.
Newest version of C/C++ compiler like Intel Compiler can accept
__USE_JMP_INLINE. "__USE_JMP_INLINE" will be added to pArrayFunc[xx](), but
"inline" will always be same for 1,000 functions. After you compile your
C++ source code, it will recognize "__USE_JMP_INLINE", it will rename from
"CALL [EAX+EDX*4]" to "JMP [EAX+EDX*4]" so each functions'' PUSH and POP
instructions will be removed. It will look like real JMP Table inside
pArrayFunc[xx](). It would be perfect for easy reading.
Please state your opinion what you think about my idea to modify C/C++
compiler''s source code. ***Do not tell that there is no __USE_JMP_INLINE to
all C/C++ compiler. Please ask the authors to add __USE_JMP_INLINE keyword.
It would be perfect and neat C++ coding.***

I have put pArrayFunc[xx]() inside C++ class example below. It gives
you an idea however "__USE_JMP_INLINE" does not EXIST, but should be added
near the future.

#include <stdio.h>

class Test

{

public:

inline void Get_a() { printf("A: %d\n", _a); }

inline void Get_b() { printf("B: %d\n", _b); }

inline void Get_c() { printf("C: %d\n", _c); }

inline void Set_a(unsigned int a) { _a = a; }

inline void Set_b(unsigned int b) { _b = b; }

inline void Set_c(unsigned int c) { _c = c; }

typedef void (Test::*Action)();

static const Action Menu[3];

inline void Call();

private:

unsigned int _a;

unsigned int _b;

unsigned int _c;

};

const Test::Action Test::Menu[3] =

{

&Test::Get_a,

&Test::Get_b,

&Test::Get_c

};

inline void Test::Call()

{

for (int a = 0; a <= 2; a++)

(this->*Menu[a])();

}

void main(void)

{

Test test;

test.Set_a(1);

test.Set_b(2);

test.Set_c(3);

test.Call();

return;

}

--
Bryan Parkoff

解决方案

"Bryan Parkoff" <br******************@nospam.com> wrote...

You may notice that switch (...) is much faster than function that can
gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP instruction that can be
slower.
"Can be" is key here.
I created three functions in an array. Array is called
pArray_Func[xx](). pArray_Func[xx]() contains three functions. "xx" can be used to point each function.
Let say, I have over 1,000 functions. I would put "inline" to each
functions. It does not matter that each function may contain more than 50
lines. It is really BIG that C/C++ compiler tells "inline" is used for
short like 3-5 lines ONLY. I have decided to tell C/C++ compiler by forcing "inline" there because I don''t care if my code is getting bigger and bigger.

And compiler can simply tell you to go kiss yourself and completely
ignore your ''inline'' keywords. Didn''t you know that it''s not mandatory?
I allow 50 lines to be copied to each functions. CALL, PUSH, and POP
instructions can always be removed automatically by the C/C++ compiler
before JMP instruction can always be placed each function.
It is very neat according to my design that I wanted. If I care to keep small code rather than big code, "inline" should not be used.
Right now, there is a big problem. I can''t place "inline" into
pArray_Func[xx](). I can see why. JMP can show "JMP [EAX+EDX*4] that will work fine. C/C++ compiler can only place "CALL [EAX+EDX*4] into
pArrayFunc[xx](). It is not designed to replace from "CALL [EAX+EDX*4]" to "JMP [EAX+EDX*4] if "inline" is there. C/C++ compiler will always ignore
"inline".
Again, ''inline'' is but a suggestion to the compiler. The compiler
does NOT have to follow it.
Another option is to place 1,000 functions inside switch (...). Look
like below.

switch (xx)
{
case 1:
Func1();
case 2:
Func2();
case 3:
Func3();
}

C/C++ compiler can see this code above before it can place "inline" to
each functions inside switch (...). It is very annoying me because I have
to read switch (...) from line to line by scrolling up/down. It is very
long for me to read. It is not HARD to FIND BUG (off my point).
Well, it''s totally up to you not to do that. You can group your ''xx''
values and design another layer of functions, within which you would
have another level of indirection:

if (xx < 100)
callOneOfLessThan100Funcs(xx);
else if (xx < 200)
callOneOfLessThan200Funcs(xx);
...
I would want to see only 3 or 4 lines there instead of over 20,000 lines that contains switch (...). pArrayFunc() may be very useful. We should
tell the C/C++ authors to add keyword like __USE_JMP_INLINE instead of
__inline, _inline, or inline.
Please do not mix _us_ up into your scheme. _You_ need this, _you_
seem to have thought this through, so _you_ should go to comp.std.c++
and suggest adding something to the language. _They_ will listen and
answer.
Newest version of C/C++ compiler like Intel Compiler can accept
__USE_JMP_INLINE. "__USE_JMP_INLINE" will be added to pArrayFunc[xx](), but "inline" will always be same for 1,000 functions. After you compile your
C++ source code, it will recognize "__USE_JMP_INLINE", it will rename from
"CALL [EAX+EDX*4]" to "JMP [EAX+EDX*4]" so each functions'' PUSH and POP
instructions will be removed. It will look like real JMP Table inside
pArrayFunc[xx](). It would be perfect for easy reading.
"Easy reading"?
Please state your opinion what you think about my idea to modify C/C++
compiler''s source code. ***Do not tell that there is no __USE_JMP_INLINE to all C/C++ compiler. Please ask the authors to add __USE_JMP_INLINE keyword. It would be perfect and neat C++ coding.***
Please go to comp.std.c++ and do it yourself.
I have put pArrayFunc[xx]() inside C++ class example below. It gives
you an idea however "__USE_JMP_INLINE" does not EXIST, but should be added
near the future.

#include <stdio.h>

class Test

{

public:

inline void Get_a() { printf("A: %d\n", _a); }

inline void Get_b() { printf("B: %d\n", _b); }

inline void Get_c() { printf("C: %d\n", _c); }

inline void Set_a(unsigned int a) { _a = a; }

inline void Set_b(unsigned int b) { _b = b; }

inline void Set_c(unsigned int c) { _c = c; }

typedef void (Test::*Action)();

static const Action Menu[3];

inline void Call();

private:

unsigned int _a;

unsigned int _b;

unsigned int _c;

};

const Test::Action Test::Menu[3] =

{

&Test::Get_a,

&Test::Get_b,

&Test::Get_c

};

inline void Test::Call()

{

for (int a = 0; a <= 2; a++)

(this->*Menu[a])();

}

void main(void)
You better learn to use

int main()

otherwise people in comp.std.c++ may not even take you seriously.

{

Test test;

test.Set_a(1);

test.Set_b(2);

test.Set_c(3);

test.Call();

return;

}




Compilers can ignore inline instructions. This is because making a function
inline can actually slow down the code. I don''t know all of the details, but
having a large compiled program can slow things down because of the
additional memory requirements (cache sizes and the like are relevant here,
not just total system memory).
--
John Carson
1. To reply to email address, remove donald
2. Don''t reply to email address (post here instead)


Victor,

I have posted a copy of my article to comp.std.c++. Please forgive me
that I DO KNOW that most C/C++ Compiler IGNORE "inline" unless I CAN FORCE
them to OBEY my desire.

And compiler can simply tell you to go kiss yourself and completely
ignore your ''inline'' keywords. Didn''t you know that it''s not mandatory?

Again, ''inline'' is but a suggestion to the compiler. The compiler
does NOT have to follow it.


I use Intel C/C++ Compiler 7.1. In fact, Intel C/C++ Compiler DOES NOT
ignore "inline" unless I tell Intel C/C++ Compiler to obey my desire unlike
other generic C/C++ Compiler such as Microsoft, GCC, G++, or other Unix
compilers.
You may be surprised that Intel C/C++ Compiler can give me the choice if
I want to use "inline" or not. It has switches like "keep inline" or
"ignore inline" however most generic C/C++ Compilers don''t have switches so
they always ignore "inline".
I hope that you understand my point.

Bryan Parkoff


这篇关于将我的想法添加到C ++编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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