AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Does the AMXX compiler inline variables at compile time? (https://forums.alliedmods.net/showthread.php?t=340475)

kww 11-21-2022 07:11

Does the AMXX compiler inline variables at compile time?
 
Possibly stupid question...
Does the compiler inline variables at compile time?
Like:
PHP Code:

public Ham_Item_Deploy_Pre(iEnt)
{
    new 
id pev(iEnt pev_owner); // it will be referenced only once
    
console_print(0"%n deployed a flashbang!"id);


turns to this:
PHP Code:

public Ham_Item_Deploy_Pre(iEnt)
{
    
console_print(0"%n deployed a flashbang!"pev(iEnt pev_owner));


Or not?

If not, should I worry about it and make id static?

MrPickles 11-21-2022 19:47

Re: Does the AMXX compiler inline variables at compile time?
 
Quote:

Originally Posted by kww (Post 2793319)
Possibly stupid question...
Does the compiler inline variables at compile time?
Like:
PHP Code:

public Ham_Item_Deploy_Pre(iEnt)
{
    new 
id pev(iEnt pev_owner); // it will be referenced only once
    
console_print(0"%n deployed a flashbang!"id);


turns to this:
PHP Code:

public Ham_Item_Deploy_Pre(iEnt)
{
    
console_print(0"%n deployed a flashbang!"pev(iEnt pev_owner));


Or not?

If not, should I worry about it and make id static?

if u use it one time, its not neccesary to make a variable, if not, make a static var

kww 11-21-2022 21:10

Re: Does the AMXX compiler inline variables at compile time?
 
Quote:

Originally Posted by MrPickles (Post 2793372)
if u use it one time, its not neccesary to make a variable

The question was: is it skips variable creation if it can use that value directly?

Quote:

Originally Posted by MrPickles (Post 2793372)
if not, make a static var

ok

MrPickles 11-21-2022 21:18

Re: Does the AMXX compiler inline variables at compile time?
 
Quote:

Originally Posted by kww (Post 2793381)
The question was: is it skips variable creation if it can use that value directly?

yes, u can use it directly, but like i said, if u use it many times( > 1 ) in the function, u should make a static var

fysiks 11-21-2022 21:42

Re: Does the AMXX compiler inline variables at compile time?
 
While it's theoretically possible, I'm quite sure that the compiler won't optimize that out of the code. As long as it's not called really often or isn't really large, it really won't matter which option you choose. For the cases where it's large or called often, you would use static.

In your case, using it directly without variable creation is probably the best way to go about it.

kww 11-22-2022 08:46

Re: Does the AMXX compiler inline variables at compile time?
 
Quote:

Originally Posted by MrPickles (Post 2793382)
but like i said, if u use it many times( > 1 ) in the function, u should make a static var

I think this makes sence only if used very often, e.g. inside client_...think or some Ham_* hooks

Quote:

Originally Posted by fysiks (Post 2793385)
While it's theoretically possible, I'm quite sure that the compiler won't optimize that out of the code. As long as it's not called really often or isn't really large, it really won't matter which option you choose. For the cases where it's large or called often, you would use static.

In your case, using it directly without variable creation is probably the best way to go about it.

This is the reply I waited for. I also tried to use amxxdump and I think it says you're right.
Code:

0x210                      PROC              ; public Ham_Item_Deploy_Pre(iEnt)
0x214                    BREAK
0x218                    BREAK
                                            ; new id
0x21C                    STACK  0xFFFFFFFC  ; allocate 1 cells
0x224                    PUSH.C  0x12
0x22C                    PUSH.S  0xC        ; iEnt
0x234                    PUSH.C  0x8
0x23C                  SYSREQ.C  0x7        ; pev
0x244                    STACK  0xC        ; free 3 cells
0x24C                STOR.S.pri  0xFFFFFFFC  ; id
0x254                    BREAK
0x258                  PUSH.ADR  0xFFFFFFFC  ; id
0x260                    PUSH.C  0xF4
0x268                    PUSH.C  0x0
0x270                    PUSH.C  0xC
0x278                  SYSREQ.C  0x8        ; console_print
0x280                    STACK  0x10        ; free 4 cells
0x288                    STACK  0x4        ; free 1 cells
0x290                  ZERO.pri
0x294                      RETN

Code:

0x298                      PROC              ; public Ham_Item_Deploy_Pre2(iEnt)
0x29C                    BREAK
0x2A0                    BREAK
0x2A4                    PUSH.C  0x12
0x2AC                    PUSH.S  0xC        ; iEnt
0x2B4                    PUSH.C  0x8
0x2BC                  SYSREQ.C  0x7        ; pev
0x2C4                    STACK  0xC        ; free 3 cells
0x2CC                      HEAP  0x4
0x2D4                    STOR.I
0x2D8                  PUSH.alt
0x2DC                    PUSH.C  0x158
0x2E4                    PUSH.C  0x0
0x2EC                    PUSH.C  0xC
0x2F4                  SYSREQ.C  0x8        ; console_print
0x2FC                    STACK  0x10        ; free 4 cells
0x304                      HEAP  0xFFFFFFFC
0x30C                  ZERO.pri
0x310                      RETN



All times are GMT -4. The time now is 15:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.