Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-10-23 20:12:15


From: Greg Colvin <gcolvin_at_[hidden]>
> > Many thanks for your work on this. Looks promising, but may
> > be worth also producing the plain const double/float/long double files
> > as well for the time being at least?
> >
> > Paul
>
> The plain const was actually less efficient for some platforms.
>
> The only problems I see with the template function approach is
> the extra typing:
>
> v = pi
>
> is certainly easier than
>
> v = constant<pi_tag,double>
>
> but it is not amenable to more precise implementations.
>
> How about a compromise:
>
> v = pi<double>()
>
> and so on for all the other constants? I think this can be
> made to work with even the most brain-dead compilers.

The following little test

    template<typename Type> inline Type pi() {
       return (Type)3.1415926535897932384626433832795028841972L;
    }
    extern int f(float&,double&,long double&);
    int pi_test() {
       float pi_float = pi<float>();
       double pi_double = pi<double>();
       long double pi_long_double = pi<long double>();
       return f(pi_float,pi_double,pi_long_double);
    }

produces the following Sparc code with Sun's latest compiler

    ___const_seg_900000101:
         .word 1078530011
         .align 8
         .word 1074340347,1413754136
         .word 1073779231,-1253817647,-2073458292,-9883
         .type ___const_seg_900000101,1
         .size ___const_seg_900000101,(.-___const_seg_9
         .align 4
         .global __1cHpi_test6F_i_
    __1cHpi_test6F_i_:
         save %sp,-128,%sp

    ! float pi_float = pi<float>();
    ! double pi_double = pi<double>();
    ! long double pi_long_double = pi<long double>();

         sethi %hi(___const_seg_900000101+16),%g1
         sethi %hi(___const_seg_900000101),%g2
         ld [%g1+%lo(___const_seg_900000101+16)],%g3
         add %g1,%lo(___const_seg_900000101+16),%g4
         sethi %hi(___const_seg_900000101+8),%g1
         ld [%g4+4],%o3

    ! return f(pi_float,pi_double,pi_long_double);

         add %fp,-4,%o0
         add %fp,-16,%o1
         ldd [%g1+%lo(___const_seg_900000101+8)],%f2
         add %fp,-32,%o2
         ld [%g4+8],%o4
         ld [%g2+%lo(___const_seg_900000101)],%f0
         st %g3,[%fp-32]
         st %o3,[%fp-28]
         std %f2,[%fp-16]
         ld [%g4+12],%o5
         st %f0,[%fp-4]
         st %o4,[%fp-24]
         call __1cBf6FrfrdrD_i_ ! params = %o0
         st %o5,[%fp-20]
         ret ! Result = %i0
         restore %g0,%o0,%o0
         .type __1cHpi_test6F_i_,2
         .size __1cHpi_test6F_i_,(.-__1cHpi_test6F_i_)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk