|
Boost : |
From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-10-23 11:43:53
For what it is worth, appendedis a very simple test program and
the 80x86 assembly language output from MSVC. I had to add the
call to f(double&,double&,double&,double&,double&) to prevent the
optimizer removing almost all the code. The operations for each
way of assigning pi to a local are a bit scrambled up, I assume
for optimal scheduling. When I unscamble them they look like:
; double pi_template = constant<pi_tag,double>();
mov DWORD PTR _pi_template$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_template$[esp+64], 1074340347 ; 400921fbH
; double pi_function = pi();
mov DWORD PTR _pi_function$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_function$[esp+64], 1074340347 ; 400921fbH
; double pi_constant = Pi;
mov eax, DWORD PTR _Pi$S188
mov DWORD PTR _pi_constant$[esp+40], eax
mov ecx, DWORD PTR _Pi$S188+4
mov DWORD PTR _pi_constant$[esp+52], ecx
; double pi_defined = PI;
mov DWORD PTR _pi_defined$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_defined$[esp+64], 1074340347 ; 400921fbH
; double pi_literal = 3.141592653589793238462643383279502884197;
mov DWORD PTR _pi_literal$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_literal$[esp+64], 1074340347 ; 400921fbH
; return f(pi_template,pi_function,pi_constant,pi_defined,pi_literal);
lea edx, DWORD PTR _pi_literal$[esp+40]
push edx
lea eax, DWORD PTR _pi_defined$[esp+44]
push eax
lea ecx, DWORD PTR _pi_constant$[esp+48]
push ecx
lea edx, DWORD PTR _pi_function$[esp+52]
push edx
lea eax, DWORD PTR _pi_template$[esp+56]
push eax
call ?f@@YAHAAN0000_at_Z ; f
Make of it all what you will.
//////////////////////////////////////////////////////////////////
// pi_test.cpp
template <typename Tag, typename Rep> struct constant {
constant() {}
operator Rep() const;
};
struct pi_tag {};
template<> inline constant<pi_tag, double>::operator double() const {
return 3.141592653589793238462643383279502884197;
}
inline double pi() {
return 3.141592653589793238462643383279502884197;
}
const double Pi = 3.141592653589793238462643383279502884197;
#define PI 3.141592653589793238462643383279502884197
extern int f(double&,double&,double&,double&,double&);
int pi_test() {
double pi_template = constant<pi_tag,double>();
double pi_function = pi();
double pi_constant = Pi;
double pi_defined = PI;
double pi_literal = 3.141592653589793238462643383279502884197;
return f(pi_template,pi_function,pi_constant,pi_defined,pi_literal);
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TITLE pi_test.cpp
.386P
include listing.inc
if @Version gt 510
.model FLAT
else
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
_DATA SEGMENT DWORD USE32 PUBLIC 'DATA'
_DATA ENDS
CONST SEGMENT DWORD USE32 PUBLIC 'CONST'
CONST ENDS
_BSS SEGMENT DWORD USE32 PUBLIC 'BSS'
_BSS ENDS
_TLS SEGMENT DWORD USE32 PUBLIC 'TLS'
_TLS ENDS
; COMDAT ??B?$constant_at_Upi_tag@@N@@QBENXZ
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT ?pi@@YANXZ
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
; COMDAT ??0?$constant_at_Upi_tag@@N@@QAE_at_XZ
_TEXT SEGMENT PARA USE32 PUBLIC 'CODE'
_TEXT ENDS
FLAT GROUP _DATA, CONST, _BSS
ASSUME CS: FLAT, DS: FLAT, SS: FLAT
endif
CONST SEGMENT
_Pi$S188 DQ 0400921fb54442d18r ; 3.14159
CONST ENDS
PUBLIC ?pi_test@@YAHXZ ; pi_test
EXTRN ?f@@YAHAAN0000_at_Z:NEAR ; f
EXTRN __fltused:NEAR
CONST SEGMENT
$T214 DQ 0400921fb54442d18r ; 3.14159
CONST ENDS
_TEXT SEGMENT
_pi_template$ = -8
_pi_function$ = -16
_pi_constant$ = -24
_pi_defined$ = -32
_pi_literal$ = -40
?pi_test@@YAHXZ PROC NEAR ; pi_test
; 25 : int pi_test() {
sub esp, 40 ; 00000028H
; 26 :
; 27 : double pi_template = constant<pi_tag,double>();
; 28 :
; 29 : double pi_function = pi();
; 30 :
; 31 : double pi_constant = Pi;
mov eax, DWORD PTR _Pi$S188
mov ecx, DWORD PTR _Pi$S188+4
mov DWORD PTR _pi_constant$[esp+40], eax
; 32 :
; 33 : double pi_defined = PI;
; 34 :
; 35 : double pi_literal = 3.141592653589793238462643383279502884197;
; 36 :
; 37 : return f(pi_template,pi_function,pi_constant,pi_defined,pi_literal);
lea edx, DWORD PTR _pi_literal$[esp+40]
mov DWORD PTR _pi_constant$[esp+44], ecx
lea eax, DWORD PTR _pi_defined$[esp+40]
push edx
lea ecx, DWORD PTR _pi_constant$[esp+44]
push eax
lea edx, DWORD PTR _pi_function$[esp+48]
push ecx
lea eax, DWORD PTR _pi_template$[esp+52]
push edx
push eax
mov DWORD PTR _pi_template$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_template$[esp+64], 1074340347 ; 400921fbH
mov DWORD PTR _pi_function$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_function$[esp+64], 1074340347 ; 400921fbH
mov DWORD PTR _pi_defined$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_defined$[esp+64], 1074340347 ; 400921fbH
mov DWORD PTR _pi_literal$[esp+60], 1413754136 ; 54442d18H
mov DWORD PTR _pi_literal$[esp+64], 1074340347 ; 400921fbH
call ?f@@YAHAAN0000_at_Z ; f
add esp, 20 ; 00000014H
; 38 : }
add esp, 40 ; 00000028H
ret 0
?pi_test@@YAHXZ ENDP ; pi_test
_TEXT ENDS
END
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk