I was disappointed when I disassembled the code using the KiROUND() inline function
solution to see that it was not pre-computing constants when used in static initializers. So we have two use cases, and need two solutions to be optimal, since the compiler is too stupid to do the right thing. I think we need something else for compile time computable constants, to be optimal in both use cases. There is quite a bit of code savings by using a macro for that situation from my testing. To fully capitalize on this, we need to go back and make Mm2mils() and what not macros also, or have MACRO versions of them too.
This commit is contained in:
parent
a2f1482192
commit
e3b6385cd3
2
TODO.txt
2
TODO.txt
|
@ -63,7 +63,7 @@ Dick's Peronal TODO Items (Last Update: 24-April-2012)
|
||||||
viewport within the virtual IU space and also a change in size of the virtual
|
viewport within the virtual IU space and also a change in size of the virtual
|
||||||
IU space. Once this happens, you can end up thinking there are problems in
|
IU space. Once this happens, you can end up thinking there are problems in
|
||||||
functions like EDA_DRAW_PANE::DrawCrossHair(), but this may be an artifact
|
functions like EDA_DRAW_PANE::DrawCrossHair(), but this may be an artifact
|
||||||
of having travelled outside a limited virtual IU space.
|
of having traveled outside a limited virtual IU space.
|
||||||
|
|
||||||
|
|
||||||
2) Check that the new load visibility BOARD settings is properly setting the toolbar
|
2) Check that the new load visibility BOARD settings is properly setting the toolbar
|
||||||
|
|
|
@ -127,11 +127,24 @@ enum pseudokeys {
|
||||||
* In Debug build an assert fires if will not fit into an int.
|
* In Debug build an assert fires if will not fit into an int.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined( DEBUG )
|
#if !defined( DEBUG )
|
||||||
|
|
||||||
// DEBUG: a macro to capture line and file, then calls this inline
|
/// KiROUND: a function so v is not evaluated twice. Unfortunately, compiler
|
||||||
|
/// is unable to pre-compute constants using this.
|
||||||
|
static inline int KiROUND( double v )
|
||||||
|
{
|
||||||
|
return int( v < 0 ? v - 0.5 : v + 0.5 );
|
||||||
|
}
|
||||||
|
|
||||||
static inline int KiRound( double v, int line, const char* filename )
|
/// KIROUND: a macro so compiler can pre-compute constants. Use this with compile
|
||||||
|
/// time constants rather than the inline function above.
|
||||||
|
#define KIROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// DEBUG: KiROUND() is a macro to capture line and file, then calls this inline
|
||||||
|
|
||||||
|
static inline int kiRound_( double v, int line, const char* filename )
|
||||||
{
|
{
|
||||||
v = v < 0 ? v - 0.5 : v + 0.5;
|
v = v < 0 ? v - 0.5 : v + 0.5;
|
||||||
if( v > INT_MAX + 0.5 )
|
if( v > INT_MAX + 0.5 )
|
||||||
|
@ -145,13 +158,10 @@ static inline int KiRound( double v, int line, const char* filename )
|
||||||
return int( v );
|
return int( v );
|
||||||
}
|
}
|
||||||
|
|
||||||
#define KiROUND( v ) KiRound( v, __LINE__, __FILE__ )
|
#define KiROUND( v ) kiRound_( v, __LINE__, __FILE__ )
|
||||||
|
|
||||||
#else
|
// in Debug build, use the overflow catcher since code size is immaterial
|
||||||
|
#define KIROUND( v ) KiROUND( v )
|
||||||
// RELEASE: a macro so compile can pre-compute constants.
|
|
||||||
|
|
||||||
#define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 )
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue