Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QuakeC: if chains?

#1
So writing some code i have been reading up on how to not make it perform badly by default and came across this site http://ouns.nexuizninjaz.com/dev_quakec.html#if-chains that says:

Quote:With default compile options (i.e. if the option -flo is not passed to the compiler), boolean expressions are evaluated fully.

They also mention fteqcc so i am wondering if this is something i have to worry about using gmqcc beyond that expressions that can have sideeffects (containing functions or assignments) will have them regardless of order (which i guess cant be changed as some code might rely on the sideeffects). Where i am getting is: Can i write something like if( somevar && someother && yetanother ) assuming the compiler will chose the best possible bytecode (say no possible sideeffects -> if chain - assuming that actually is the most efficient bytecode) or will it be auto performance loss for not writing if( somevar ) if( someother ) if( yetanother ) because the compiler is not clever enough or for some weird technical reason cant optimize it? The gmqcc "documentation" sadly wasnt exactly helpful so i thought it might not hurt to ask.

Somewhat related: Is there a reason to avoid switch? I have seen looooong if-else-if constructs. Is this just a preference of the authors or maybe some historical thing or is there more to it? Switch being closely related to if kinda got me curious.

Also somewhat related: Is this something i should worry about at all? I guess instantly doubting the compilers abilities to optimize stuff is kind of a bad c habit.
Reply

#2
Your reference is not up to date, here's the relevant page in the Xonotic wiki: http://dev.xonotic.org/projects/xonotic/..._to_QuakeC

It's still based on FTEQCC though. Someone should fix that.

Anyway, gmqcc's manpage (or at least a months-old version of it) mentions
Quote: -fshort-logic
Perform early out in logical AND and OR expressions. The final result will be either a 0 or a 1, see the next flag for more possibilities.
which is what you mean.

Looking at the source code, it seems that SHORT_LOGIC is enabled for -std=gmqcc, which Xonotic uses. Looks like the docs aren't up to date on this.
[Image:http://i.imgur.com/4XODR.png]640K ought to be enough for anybody.
     ― Linux Torvalds
Reply

#3
Ouch, how could i miss that? You are right, its just above -fperl-logic which ironically i read at least 3 times thinking "no this really isnt what i am looking for". I guess i owe the gmqcc documentation an apology now. Thanks a lot for clarifying. This would have cost me time on pretty much every single if statement trying to decide if i am going to build this ugly if-if-if construct just to be sure or if i will take the risk of doing it the normal way.
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  New QuakeC virtual machine Lyberta 8 2,721 07-14-2017, 04:01 PM
Last Post: poVoq
  Moving away from QuakeC Lyberta 6 2,198 04-07-2017, 03:35 AM
Last Post: Mario
Brick A script engine written in QuakeC Melanosuchus 9 7,042 10-14-2014, 02:01 AM
Last Post: Melanosuchus
  QuakeC: Variadic macros? WannabeUser 2 1,988 03-10-2014, 05:16 PM
Last Post: WannabeUser
  Learning QuakeC? phim 13 12,607 12-24-2013, 03:07 AM
Last Post: aa
  A question of getting started with Quakec timetopat 5 5,162 07-02-2012, 07:55 AM
Last Post: timetopat

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-