Raised This Month: $32 Target: $400
 8% 

Solved Does the AMXX compiler inline variables at compile time?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-21-2022 , 07:11   Does the AMXX compiler inline variables at compile time?
Reply With Quote #1

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?
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 11-22-2022 at 08:52.
kww is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-21-2022 , 19:47   Re: Does the AMXX compiler inline variables at compile time?
Reply With Quote #2

Quote:
Originally Posted by kww View Post
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
MrPickles is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-21-2022 , 21:10   Re: Does the AMXX compiler inline variables at compile time?
Reply With Quote #3

Quote:
Originally Posted by MrPickles View Post
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 View Post
if not, make a static var
ok
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951
kww is offline
MrPickles
Senior Member
Join Date: Aug 2022
Location: Colombia
Old 11-21-2022 , 21:18   Re: Does the AMXX compiler inline variables at compile time?
Reply With Quote #4

Quote:
Originally Posted by kww View Post
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

Last edited by MrPickles; 11-21-2022 at 21:18.
MrPickles is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-21-2022 , 21:42   Re: Does the AMXX compiler inline variables at compile time?
Reply With Quote #5

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.
__________________

Last edited by fysiks; 11-21-2022 at 21:45.
fysiks is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 11-22-2022 , 08:46   Re: Does the AMXX compiler inline variables at compile time?
Reply With Quote #6

Quote:
Originally Posted by MrPickles View Post
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 View Post
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
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 11-22-2022 at 08:51.
kww is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:28.


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