Changes in src/ResolvExpr/Cost.h [b10c39a0:c378e5e]
- File:
-
- 1 edited
-
src/ResolvExpr/Cost.h (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Cost.h
rb10c39a0 rc378e5e 10 10 // Created On : Sun May 17 09:39:50 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Apr 29 18:33:44201913 // Update Count : 4912 // Last Modified On : Sun Apr 28 18:26:36 2019 13 // Update Count : 29 14 14 // 15 15 … … 18 18 #include <iostream> 19 19 #include <cassert> 20 #include <climits>21 20 22 21 namespace ResolvExpr { … … 217 216 << cost.referenceCost << " )"; 218 217 } 219 220 #else 218 #endif // 0 221 219 222 220 //*************************** NEW *************************** 223 224 // To maximize performance and space, the 7 resolution costs are packed into a single 64-bit word. However, the225 // specialization cost is a negative value so a correction is needed is a few places.226 221 227 222 class Cost { … … 239 234 unsigned char unsafeCost; ///< Unsafe (narrowing) conversions 240 235 #else 241 #error CostBIG_ENDIAN unsupported236 #error BIG_ENDIAN unsupported 242 237 #endif 243 238 } v; 244 239 uint64_t all; 245 240 }; 246 static const unsigned char correctb = 0xff; // byte correction for negative spec cost247 static const uint64_t correctw = 0x00'00'00'00'00'ff'00'00; //' word correction for negative spec cost248 241 public: 249 242 // Compiler adjusts constants for correct endian. 250 243 enum : uint64_t { 251 zero = 0x00'00'00'00'00'ff'00'00, 252 infinity = 0xff'ff'ff'ff'ff'00'ff'ff, 253 unsafe = 0x01'00'00'00'00'ff'00'00, 254 poly = 0x00'01'00'00'00'ff'00'00, 255 safe = 0x00'00'01'00'00'ff'00'00, 256 sign = 0x00'00'00'01'00'ff'00'00, 257 var = 0x00'00'00'00'01'ff'00'00, 258 spec = 0x00'00'00'00'00'fe'00'00, 259 reference = 0x00'00'00'00'00'ff'01'00, 260 }; //' 244 zero = 0x00'00'00'00'00'ff'00'00, 245 infinity = 0xff'ff'ff'ff'ff'00'ff'ff, 246 correction = 0x00'00'00'00'00'ff'00'00, // correct for negative spec cost 247 unsafe = 0x01'00'00'00'00'ff'00'00, 248 poly = 0x00'01'00'00'00'ff'00'00, 249 safe = 0x00'00'01'00'00'ff'00'00, 250 sign = 0x00'00'00'01'00'ff'00'00, 251 var = 0x00'00'00'00'01'ff'00'00, 252 spec = 0x00'00'00'00'00'fe'00'00, 253 reference = 0x00'00'00'00'00'ff'01'00, 254 }; // 261 255 262 256 Cost( uint64_t all ) { Cost::all = all; } … … 264 258 // Assume little-endian => first value is low priority and last is high priority. 265 259 v = { 266 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__267 260 (unsigned char)0, // padding 268 (unsigned char)referenceCost, // low priority269 (unsigned char)(specCost + correctb),// correct for signedness261 (unsigned char)referenceCost, 262 (unsigned char)(specCost + 0xff ), // correct for signedness 270 263 (unsigned char)varCost, 271 264 (unsigned char)signCost, 272 265 (unsigned char)safeCost, 273 266 (unsigned char)polyCost, 274 (unsigned char)unsafeCost, // high priority 275 #else 276 #error Cost BIG_ENDIAN unsupported 277 #endif 267 (unsigned char)unsafeCost, 278 268 }; 279 269 } … … 284 274 int get_signCost() const { return v.signCost; } 285 275 int get_varCost() const { return v.varCost; } 286 int get_specCost() const { return -( correctb- v.specCost); }276 int get_specCost() const { return -(0xff - v.specCost); } 287 277 int get_referenceCost() const { return v.referenceCost; } 288 278 … … 305 295 return *this; 306 296 } 307 all += rhs.all - correct w;// correct for negative spec cost297 all += rhs.all - correction; // correct for negative spec cost 308 298 return *this; 309 299 } 310 300 311 301 Cost incUnsafe( int inc = 1 ) { 312 if ( all != infinity ) { assert( v.unsafeCost + inc < = UCHAR_MAX); v.unsafeCost += inc; }302 if ( all != infinity ) { assert( v.unsafeCost + inc < 256 ); v.unsafeCost += inc; } 313 303 return *this; 314 304 } 315 305 316 306 Cost incPoly( int inc = 1 ) { 317 if ( all != infinity ) { assert( v.polyCost + inc < = UCHAR_MAX); v.polyCost += inc; }307 if ( all != infinity ) { assert( v.polyCost + inc < 256 ); v.polyCost += inc; } 318 308 return *this; 319 309 } 320 310 321 311 Cost incSafe( int inc = 1 ) { 322 if ( all != infinity ) { assert( v.safeCost + inc < = UCHAR_MAX); v.safeCost += inc; }312 if ( all != infinity ) { assert( v.safeCost + inc < 256 ); v.safeCost += inc; } 323 313 return *this; 324 314 } 325 315 326 316 Cost incSign( int inc = 1 ) { 327 if ( all != infinity ) { assert( v.signCost + inc < = UCHAR_MAX); v.signCost += inc; }317 if ( all != infinity ) { assert( v.signCost + inc < 256 ); v.signCost += inc; } 328 318 return *this; 329 319 } 330 320 331 321 Cost incVar( int inc = 1 ) { 332 if ( all != infinity ) { assert( v.varCost + inc < = UCHAR_MAX); v.varCost += inc; }322 if ( all != infinity ) { assert( v.varCost + inc < 256 ); v.varCost += inc; } 333 323 return *this; 334 324 } 335 325 336 326 Cost decSpec( int dec = 1 ) { 337 if ( all != infinity ) { assert( v.specCost - dec >= 0 );v.specCost -= dec; }327 if ( all != infinity ) { v.specCost -= dec; } 338 328 return *this; 339 329 } 340 330 341 331 Cost incReference( int inc = 1 ) { 342 if ( all != infinity ) { assert( v.referenceCost + inc < = UCHAR_MAX); v.referenceCost += inc; }332 if ( all != infinity ) { assert( v.referenceCost + inc < 256 ); v.referenceCost += inc; } 343 333 return *this; 344 334 } … … 363 353 inline Cost operator+( const Cost lhs, const Cost rhs ) { 364 354 if ( lhs.all == Cost::infinity || rhs.all == Cost::infinity ) return Cost{ Cost::infinity }; 365 return Cost{ lhs.all + rhs.all - Cost::correct w}; // correct for negative spec cost355 return Cost{ lhs.all + rhs.all - Cost::correction }; // correct for negative spec cost 366 356 } 367 357 … … 371 361 << ", " << cost.get_referenceCost() << " )"; 372 362 } 373 #endif // 0374 363 } // namespace ResolvExpr 375 364
Note:
See TracChangeset
for help on using the changeset viewer.