Does the ZScript compiler do any optimizing?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Does the ZScript compiler do any optimizing?

Post by argv »

Does the ZScript compiler do any optimizing? Is there a run-down somewhere of what optimizations it does?

In particular, does it optimize arithmetic at all? Should I change “x / 2” to “x >> 1” or “x * .5” everywhere, or is the compiler doing that behind the scenes already?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Does the ZScript compiler do any optimizing?

Post by Graf Zahl »

It generally does not optimize anything, except in a few trivial cases. It can fold constant expressions but it does not alter any math operations. In your example case it won't change the operation but don't forget that optimizing such things make little sense because the VM code is already an entire magnitude slower than what you could gain.
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Re: Does the ZScript compiler do any optimizing?

Post by argv »

Does it fold constant subexpressions that are part of a non-constant expression, such as “x = y * (3. / 4.);” → “x = y * .75;”?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Does the ZScript compiler do any optimizing?

Post by Graf Zahl »

Yes.
argv
Posts: 184
Joined: Tue Aug 30, 2016 4:47 pm

Re: Does the ZScript compiler do any optimizing?

Post by argv »

Nice! That'll help with readability.

Is there any way to see a disassembly of the VM bytecode?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49252
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Does the ZScript compiler do any optimizing?

Post by Graf Zahl »

Yes, add "-dumpdisasm" to the command line and it writes out a disassembly of the entire compiled code.
Post Reply

Return to “Scripting”