OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:03 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: And or double shift to select middle bits?
PostPosted: Tue Sep 05, 2017 8:38 am 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 360
Solar wrote:
you can use #ifdef to select the fastest operation depending on platform / option switch (if you must).
As I said, the OP most likely used C only as a metaphor in trying to investigate the hardware efficiency of this operation sequence, and I don't mean to insist on my opinion either, but this is not really possible in C. I mean - yes, you could technically benchmark, but the result depends on the surrounding source code, on the compiler version, on the generation of the core and CPU architecture. The OP will need to reevaluate after every source code change near such a macro expansion. There is no easy way to predict how the registers will be allocated and whether register operands will be used at all, how the instructions will be sequenced, and thus where exactly the code will be relative to the surrounding code. I doubt that even the compiler engineers can tell you that. Also, the effect will be different to each function, in every incarnation it has during the evolution of the project. So, the macrofication does not really abstract much but the syntax, especially for such short fragment.

Not that I am against rational sensible thinking about the code performance while writing in C, but evaluating the efficiency of less than entire function implementations or at least larger code fragments involving loops, and may be not even that in all cases, is going to provide very controversial results in the long run.

P.S. After thinking about it, I realized that for a different type of source alternative, such as a typedef, structure packing, or another bit hack, I would have considered the suggestion for conditional compilation favorably, actually. But the nature of extracting a byte from a word makes me suspect volatility here. Whatever the case - either the bit hack is performance critical enough that rewriting it in assembly (even if inline assembly), captured within macro if desirable, is justified, or the idea of reliable code efficiency is sacrificed I'd say.


Top
 Profile  
 
 Post subject: Re: And or double shift to select middle bits?
PostPosted: Tue Sep 05, 2017 9:18 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Basically I was trying to take the knife away from him before he hurts himself, if you get my meaning. ;-)

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: And or double shift to select middle bits?
PostPosted: Tue Sep 05, 2017 9:44 am 
Offline
Member
Member

Joined: Fri Aug 19, 2016 10:28 pm
Posts: 360
Solar wrote:
Basically I was trying to take the knife away from him before he hurts himself, if you get my meaning. ;-)
Ah, I see... Truth be told, I am witless at times.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group