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?
Does the ZScript compiler do any optimizing?
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!)
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!)
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Does the ZScript compiler do any optimizing?
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.
Re: Does the ZScript compiler do any optimizing?
Does it fold constant subexpressions that are part of a non-constant expression, such as “x = y * (3. / 4.);” → “x = y * .75;”?
Re: Does the ZScript compiler do any optimizing?
Nice! That'll help with readability.
Is there any way to see a disassembly of the VM bytecode?
Is there any way to see a disassembly of the VM bytecode?
- Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Does the ZScript compiler do any optimizing?
Yes, add "-dumpdisasm" to the command line and it writes out a disassembly of the entire compiled code.