Issue Details (XML | Word | Printable)

Key: STDCXX-335
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Mark Brown
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

std::min() suboptimal

Created: 07/Feb/07 09:04 PM   Updated: 02/Jun/08 06:20 PM
Return to search
Component/s: 25. Algorithms
Affects Version/s: 4.1.3
Fix Version/s: 4.3.0

Time Tracking:
Original Estimate: 4h
Original Estimate - 4h
Remaining Estimate: 4h
Remaining Estimate - 4h
Time Spent: Not Specified
Remaining Estimate - 4h

Environment: gcc 3.2.3, x86 Linux

Severity: Inefficiency


 Description  « Hide
I don't know if it's the compiler that's generating worse code for the stdcxx version of min or if the function is not implemented as efficiently as it could be but the disassembly for the two functions below shows that my_min() is one instruction shorter than test_min():

#include <algorithm>
int test_min (int x, int y) { return std::min (x, y); }
int my_min (int x, int y) { return x < y ? x : y; }

_Z8test_minii:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
cmpl %eax, 8(%ebp)
jg .L2
leal 8(%ebp), %eax <<< extra load?
.L4:
movl (%eax), %eax
leave
ret

_Z6my_minii:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
cmpl 8(%ebp), %eax
jle .L6
movl 8(%ebp), %eax
.L6:
leave
ret



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
No work has yet been logged on this issue.