operator overloading

H

hamze

hi,
I have added a special hardware to my cpu and now I want to overload *
for double type.
usually [ double operator*(double, double) ] does not work because
double is a predefined system type.
changing all of code manually is not a good way for me so I want to
find an automatic way.
first solution I tried was to define a class with one double variable
inside. then overload * for that class, but it is not good because it
has a lot of timing overhead , moreover I should carefully change all
of my code to replace double with new type.

is there any way to overload * operator for type of Double? can macros
help me ?
 
J

Jorgen Grahn

hi,
I have added a special hardware to my cpu and now I want to overload *
for double type.

It's not "overloading" if the operator already exists. "Replacement",
rather.

What is this special hardware, if it's not the normal floating-point
processor which your compiler can automatically make use of?
usually [ double operator*(double, double) ] does not work because
double is a predefined system type.
changing all of code manually is not a good way for me so I want to
find an automatic way.
first solution I tried was to define a class with one double variable
inside. then overload * for that class, but it is not good because it
has a lot of timing overhead ,

If "timing overhead" means it runs slower than whatever alternative
you have: are you sure this is the case, with a decent compiler with
optimization turned on? My assumption (I haven't investigated deeply)
is that you can easily get a struct Foo { double val; } to generate
code that's just as fast as a naked double.
moreover I should carefully change all
of my code to replace double with new type.

is there any way to overload * operator for type of Double? can macros
help me ?

/Jorgen
 
V

Victor Bazarov

I have added a special hardware to my cpu and now I want to overload *
for double type.

Tough luck.
usually [ double operator*(double, double) ] does not work because
double is a predefined system type.
Yes.

changing all of code manually is not a good way for me so I want to
find an automatic way.

I feel your pain. Writing programs manually is not a good way either.
If I could just find an automatic way to transmit my thoughts into the
computer...
first solution I tried was to define a class with one double variable
inside. then overload * for that class, but it is not good because it
has a lot of timing overhead ,

From what? How do you know there is the "timing overhead"?
moreover I should carefully change all
of my code to replace double with new type.

Yes, that's the price you [usually] have to pay to use special hardware.
is there any way to overload * operator for type of Double? can macros
help me ?

Not unless you write your own custom compiler.

V
 
H

hamze

It's not "overloading" if the operator already exists. "Replacement",
rather.

What is this special hardware, if it's not the normal floating-point
processor which your compiler can automatically make use of?

it does not matter but if you know it is a softprocessor on FPGA, it
does not have hardware for double precision (64bit )
so I add a custom hardware on bus of system, it gives me a lot of
speed compare to C++ library implementation of double precision
operations,
but if I dont find a good way to redirect using of my code ( which
works with that hardware) instead of C++ library code ,for double
operations , its timing overhead will compensate its speed!
difficulty of changing operations in all of my code to a new function
call is impossilbe because code is too big.

usually [ double operator*(double, double) ] does not work because
double is a predefined system type.
changing all of code manually is not a good way for me so I want to
find an automatic way.
first solution I tried was to define a class with one double variable
inside. then overload * for that class, but it is not good because it
has a lot of timing overhead ,

If "timing overhead" means it runs slower than whatever alternative
you have: are you sure this is the case, with a decent compiler with
optimization turned on?  My assumption (I haven't investigated deeply)
is that you can easily get a struct Foo { double val; } to generate
code that's just as fast as a naked double.
I am sure about my timing measurement, optimization is off to exact
measurement and a hardware timer is used to measure code runtime.....
"timing overhead" means time elapsed to use my hardware, for example
writing to that new hardware and reading result or waiting for
completion of computation,
I did what you say, but I used class instead of struct, ( i will try
struct ) but after deeply measurement, I saw referring to a double
type is faster than a class t Foo { double val; },

is there anyway to replace library of C++ with my code? I want to
replace c++ implementation of double*double with my code, then every
thin will solve!!
thanks
 
H

hamze

I have added a special hardware to my cpu and now I want to overload *
for double type.

Tough luck.
usually [ double operator*(double, double) ] does not work because
double is a predefined system type.
Yes.

changing all of code manually is not a good way for me so I want to
find an automatic way.

I feel your pain.  Writing programs manually is not a good way either.
If I could just find an automatic way to transmit my thoughts into the
computer...
first solution I tried was to define a class with one double variable
inside. then overload * for that class, but it is not good because it
has a lot of timing overhead ,

 From what?  How do you know there is the "timing overhead"?

 > moreover I should carefully change all
of my code to replace double with new type.

Yes, that's the price you [usually] have to pay to use special hardware.
is there any way to overload * operator for type of Double? can macros
help me ?

Not unless you write your own custom compiler.

V


NO!!! please answer!! please!!!
 
J

Jorgen Grahn

it does not matter but if you know it is a softprocessor on FPGA, it
does not have hardware for double precision (64bit )
so I add a custom hardware on bus of system, it gives me a lot of
speed compare to C++ library implementation of double precision
operations,
but if I dont find a good way to redirect using of my code ( which
works with that hardware) instead of C++ library code ,for double
operations , its timing overhead will compensate its speed!
difficulty of changing operations in all of my code to a new function
call is impossilbe because code is too big.

Ah, if the alternative is your compiler's non-FPU library functions,
then you might be able to provide your own implementation of the
floating-point routines, replacing the ones in the C library.
usually [ double operator*(double, double) ] does not work because
double is a predefined system type.
changing all of code manually is not a good way for me so I want to
find an automatic way.
first solution I tried was to define a class with one double variable
inside. then overload * for that class, but it is not good because it
has a lot of timing overhead ,

If "timing overhead" means it runs slower than whatever alternative
you have: are you sure this is the case, with a decent compiler with
optimization turned on?  My assumption (I haven't investigated deeply)
is that you can easily get a struct Foo { double val; } to generate
code that's just as fast as a naked double.
I am sure about my timing measurement, optimization is off to exact
measurement

Then it's not surprising that your code is slower! It's the optimizer
and nothing but the optimizer which removes the overhead (e.g. by
inlining function calls).
and a hardware timer is used to measure code runtime.....
"timing overhead" means time elapsed to use my hardware, for example
writing to that new hardware and reading result or waiting for
completion of computation,
I did what you say, but I used class instead of struct, ( i will try
struct )

Struct and class is the same thing, for these purposes.

but after deeply measurement, I saw referring to a double
type is faster than a class t Foo { double val; },

is there anyway to replace library of C++ with my code? I want to
replace c++ implementation of double*double with my code, then every
thin will solve!!

Impossible to say without knowing which compiler you use. I don't even
know how gcc implements soft-float ... I only know the ancient Lattice
C compiler for the Commodore-Amiga had library routines with funny
names for operating on floats and doubles. (You could even choose
between IEEE versions and some Commodore- or Motorola-specific
representation.)

/Jorgen
 
H

hamze

it does not matter but if you know it is a softprocessor on FPGA, it
does not have hardware for double precision (64bit )
so I add a custom hardware on bus of system, it gives me a lot of
speed compare to C++ library implementation of double precision
operations,
but if I dont find a good way to redirect using of my code ( which
works with that hardware) instead of C++ library code ,for double
operations , its timing overhead will compensate its speed!
difficulty of changing operations in all of my code to a new function
call is impossilbe because code is too big.

Ah, if the alternative is your compiler's non-FPU library functions,
then you might be able to provide your own implementation of the
floating-point routines, replacing the ones in the C library.








usually [ double operator*(double, double) ] does not work because
double is a predefined system type.
changing all of code manually is not a good way for me so I want to
find an automatic way.
first solution I tried was to define a class with one double variable
inside. then overload * for that class, but it is not good because it
has a lot of timing overhead ,
If "timing overhead" means it runs slower than whatever alternative
you have: are you sure this is the case, with a decent compiler with
optimization turned on?  My assumption (I haven't investigated deeply)
is that you can easily get a struct Foo { double val; } to generate
code that's just as fast as a naked double.
I am sure about my timing measurement, optimization is off to exact
measurement

Then it's not surprising that your code is slower! It's the optimizer
and nothing but the optimizer which removes the overhead (e.g. by
inlining function calls).
and a hardware timer is used to measure code runtime.....
"timing overhead" means time elapsed to use my hardware, for example
writing to that new hardware and reading result or waiting for
completion of computation,
I did what you say, but I used class instead of struct, ( i will try
struct )

Struct and class is the same thing, for these purposes.

but after deeply measurement, I saw referring to a double
type is faster than a class t Foo { double val; },
is there anyway to replace library of C++ with my code? I want to
replace c++ implementation of double*double with my code, then every
thin will solve!!

Impossible to say without knowing which compiler you use. I don't even
know how gcc implements soft-float ... I only know the ancient Lattice
C compiler for the Commodore-Amiga had library routines with funny
names for operating on floats and doubles. (You could even choose
between IEEE versions and some Commodore- or Motorola-specific
representation.)

/Jorgen



thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top