[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
| Title: | Languages | 
| Notice: | Speaking In Tongues | 
| Moderator: | TLE::TOKLAS::FELDMAN | 
|  | 
| Created: | Sat Jan 25 1986 | 
| Last Modified: | Wed May 21 1997 | 
| Last Successful Update: | Fri Jun 06 1997 | 
| Number of topics: | 394 | 
| Total number of notes: | 2683 | 
387.0. "3way branch optimization" by RANGER::BRADLEY (Chuck Bradley) Wed Feb 15 1995 17:42
in a binary search, or while searching a binary tree, one needs to make
a 3 way comparison, <, =, or >.
decades ago, fortran provided this capability.
nowadays in c we write
	...
	if (p->key < soughtvalue)
		mumble
	else if (p->key > soughtvalue)
		whatever
	else
		somethingelse
	...
does your compiler do the comparison only once?
this is about any language, any implementaion, and any operating system.
that is, does it generate code something like
	indexed load of key to Rn
	compare Rn,soughtvalue
	BH	mumblelabel
	BL	whateverlabel
somethingelselabel:
or does it do something like this
	indexed load of key to Rn
	compare Rn,soughtvalue
	BH	mumblelabel
	indexed load of key to Rn
	compare Rn,soughtvalue
	BL	whateverlabel
somethingelselabel:
| T.R | Title | User | Personal Name
 | Date | Lines | 
|---|
| 387.1 |  | AUSSIE::GARSON | achtentachtig kacheltjes | Thu Feb 16 1995 01:08 | 11 | 
|  |     None of the following (on VAX) make the optimisation.
    
    DEC C V4.0-000
    VAX C V3.2-044
    PASCAL V4.3-76
    
    For numeric comparisons a "sign" function comes in handy. However
    string comparisons are where this optimisation is more helpful and in
    that case C's strcmp() at least allows the programmer to do the
    optimisation. [The compiler itself can't because it doesn't know what
    strcmp() is, at least traditionally.]
 |