Something used roughly like this: unsigned foo __attribute__(( min(5), // value will never be below this max(0x007fff04), // value will never be above this set(0x00000004), // these bits will always be set clear(0xff800002), // these bits will never be set likely_min(100), // the value is rarely below this likely_max(12345), // the value is rarely above this likely_set(0x00000604), // these bits are usually set likely_clear(0xfffff032) // these bits are usually clear )) = 100;
The idea is that I tell gcc that my variable (or type) is certain or likely to have various values. This lets me avoid marking up lots and lots of code with __builtin_expect. I can just mark the variable or type. A bit of error checking can be done too. It would be invalid to pass a value that never exceeds 1 to a function whose argument is marked as always having bit 4 set. The compiler could catch this and halt with an error. -- Summary: value expectation attribute Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: acahalan at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26369