public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: how to make a long long
@ 2003-02-22 16:30 Sebastian Huber
  2003-02-22 21:37 ` LLeweLLyn Reese
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Huber @ 2003-02-22 16:30 UTC (permalink / raw)
  To: gcc-help

Adrian Sandor <aditsu@yahoo.com> schrieb am 22.02.03 16:44:50:
> 
> > what is wrong with
> > 
> > unsigned long long i = ((0x0ULL | uint32high) << 32)
> > | uint32low;
> > 
> > ?
> 
> this approach uses an OR between an unsigned long long
> and an unsigned int, a SHIFT-LEFT on an unsigned long
> long and another OR between 2 an unsigned long long
> and an unsigned int;
> I think these are too heavy calculations just for
> putting 2 unsigned ints next to each other
[...]

C is not an assembly language. It's up to the compiler to generate optimized code.

Bye
    Sebastian
______________________________________________________________________________
Die SMS direkt auf's Handy. - Die Blitz-SMS bei WEB.DE FreeMail
http://freemail.web.de/features/?mc=021165

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-22 16:30 how to make a long long Sebastian Huber
@ 2003-02-22 21:37 ` LLeweLLyn Reese
  2003-02-22 22:13   ` Sebastian Huber
  0 siblings, 1 reply; 11+ messages in thread
From: LLeweLLyn Reese @ 2003-02-22 21:37 UTC (permalink / raw)
  To: Sebastian Huber; +Cc: gcc-help

Sebastian Huber <sebastian-huber@web.de> writes:

> Adrian Sandor <aditsu@yahoo.com> schrieb am 22.02.03 16:44:50:
> > 
> > > what is wrong with
> > > 
> > > unsigned long long i = ((0x0ULL | uint32high) << 32)
> > > | uint32low;
> > > 
> > > ?
> > 
> > this approach uses an OR between an unsigned long long

OR often has the lowest latency and highest paralellism a cpu can
    offer. It is much simpler than, for example, add or increment.

> > and an unsigned int, a SHIFT-LEFT on an unsigned long
> > long and another OR between 2 an unsigned long long
> > and an unsigned int;
> > I think these are too heavy calculations just for
> > putting 2 unsigned ints next to each other

I doubt it. There have been a few microcontrollers for whom SHIFT-LEFT
    was/is expensive, but they are a minority.

> C is not an assembly language. It's up to the compiler to generate optimized code.

If you actually need optimized code, the programmer has to write it,
    regardless of the language. The compiler merely allows one to
    concentrate on the code that needs optimization most.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-22 21:37 ` LLeweLLyn Reese
@ 2003-02-22 22:13   ` Sebastian Huber
  2003-02-24  5:51     ` LLeweLLyn Reese
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Huber @ 2003-02-22 22:13 UTC (permalink / raw)
  To: gcc-help

On Saturday 22 February 2003 22:34, you wrote:
> Sebastian Huber <sebastian-huber@web.de> writes:
> > Adrian Sandor <aditsu@yahoo.com> schrieb am 22.02.03 16:44:50:
> > > > what is wrong with
> > > >
> > > > unsigned long long i = ((0x0ULL | uint32high) << 32)
> > > >
> > > > | uint32low;
> > > >
> > > > ?
> > >
> > > this approach uses an OR between an unsigned long long
>
> OR often has the lowest latency and highest paralellism a cpu can
>     offer. It is much simpler than, for example, add or increment.
>
> > > and an unsigned int, a SHIFT-LEFT on an unsigned long
> > > long and another OR between 2 an unsigned long long
> > > and an unsigned int;
> > > I think these are too heavy calculations just for
> > > putting 2 unsigned ints next to each other
>
> I doubt it. There have been a few microcontrollers for whom SHIFT-LEFT
>     was/is expensive, but they are a minority.
>
> > C is not an assembly language. It's up to the compiler to generate
> > optimized code.
>
> If you actually need optimized code, the programmer has to write it,
>     regardless of the language. The compiler merely allows one to
>     concentrate on the code that needs optimization most.

You should interpret my statement in view of this special problem. If you want 
to play with bits in plain C your tools are limited.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-22 22:13   ` Sebastian Huber
@ 2003-02-24  5:51     ` LLeweLLyn Reese
  0 siblings, 0 replies; 11+ messages in thread
From: LLeweLLyn Reese @ 2003-02-24  5:51 UTC (permalink / raw)
  To: Sebastian Huber; +Cc: gcc-help

Sebastian Huber <sebastian-huber@web.de> writes:

> On Saturday 22 February 2003 22:34, you wrote:
> > Sebastian Huber <sebastian-huber@web.de> writes:
> > > Adrian Sandor <aditsu@yahoo.com> schrieb am 22.02.03 16:44:50:
> > > > > what is wrong with
> > > > >
> > > > > unsigned long long i = ((0x0ULL | uint32high) << 32)
> > > > >
> > > > > | uint32low;
> > > > >
> > > > > ?
> > > >
> > > > this approach uses an OR between an unsigned long long
> >
> > OR often has the lowest latency and highest paralellism a cpu can
> >     offer. It is much simpler than, for example, add or increment.
> >
> > > > and an unsigned int, a SHIFT-LEFT on an unsigned long
> > > > long and another OR between 2 an unsigned long long
> > > > and an unsigned int;
> > > > I think these are too heavy calculations just for
> > > > putting 2 unsigned ints next to each other
> >
> > I doubt it. There have been a few microcontrollers for whom SHIFT-LEFT
> >     was/is expensive, but they are a minority.
> >
> > > C is not an assembly language. It's up to the compiler to generate
> > > optimized code.
> >
> > If you actually need optimized code, the programmer has to write it,
> >     regardless of the language. The compiler merely allows one to
> >     concentrate on the code that needs optimization most.
> 
> You should interpret my statement in view of this special problem.

I'm sorry, I've no idea what you mean by that. Which statement? What
    special problem?

> If you want 
> to play with bits in plain C your tools are limited.

This is true, but they are often adequate. (and frankly better than
    most non-assembler languages.) If you need assembler, use it, but
    know how to seperate such platform specific code from non-platform
    specific code.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
       [not found] <1045823803.20501.ezmlm@gcc.gnu.org>
@ 2003-02-22 15:44 ` Adrian Sandor
  0 siblings, 0 replies; 11+ messages in thread
From: Adrian Sandor @ 2003-02-22 15:44 UTC (permalink / raw)
  To: gcc-help

> what is wrong with
> 
> unsigned long long i = ((0x0ULL | uint32high) << 32)
> | uint32low;
> 
> ?

this approach uses an OR between an unsigned long long
and an unsigned int, a SHIFT-LEFT on an unsigned long
long and another OR between 2 an unsigned long long
and an unsigned int;
I think these are too heavy calculations just for
putting 2 unsigned ints next to each other

Adrian

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-20 11:02 ` Sebastian Huber
@ 2003-02-20 11:40   ` Mihnea Balta
  0 siblings, 0 replies; 11+ messages in thread
From: Mihnea Balta @ 2003-02-20 11:40 UTC (permalink / raw)
  To: Sebastian Huber, gcc-help

On Thursday 20 February 2003 12:58, Sebastian Huber wrote:
> On Thursday 20 February 2003 09:56, Adrian Sandor wrote:
> > Wich is the proper way to make an unsigned long long
> > from two unsigned ints (high and low dwords) without
> > too many conversions and calculations?
> > [...]
>
> Hi,
> what is wrong with
>
> unsigned long long i = ((0x0ULL | uint32high) << 32) | uint32low;
Erm... nothing.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-20  8:56 Adrian Sandor
  2003-02-20  9:05 ` Mihnea Balta
@ 2003-02-20 11:02 ` Sebastian Huber
  2003-02-20 11:40   ` Mihnea Balta
  1 sibling, 1 reply; 11+ messages in thread
From: Sebastian Huber @ 2003-02-20 11:02 UTC (permalink / raw)
  To: gcc-help

On Thursday 20 February 2003 09:56, Adrian Sandor wrote:
> Wich is the proper way to make an unsigned long long
> from two unsigned ints (high and low dwords) without
> too many conversions and calculations?
> [...]

Hi,
what is wrong with

unsigned long long i = ((0x0ULL | uint32high) << 32) | uint32low;

?

Ciao

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-20  9:58   ` Adrian Sandor
@ 2003-02-20 10:24     ` Mihnea Balta
  0 siblings, 0 replies; 11+ messages in thread
From: Mihnea Balta @ 2003-02-20 10:24 UTC (permalink / raw)
  To: Adrian Sandor, gcc-help

The memset() thing was just a reference value, to test if the above two ways 
work. I wasn't suggesting you use it :)

Sorry about the bit union, I started the example one way and finished in 
another. It's a leftover, you can safely use a struct made of 2 ints.

On Thursday 20 February 2003 11:57, Adrian Sandor wrote:
> --- Mihnea Balta <dark_lkml@mymail.ro> wrote:
> >     union{
> >         struct{
> >             unsigned long long a:32;
> >             unsigned long long b:32;
> >         } gigi;
> >         unsigned long long l;
> >     } toto;
> >     toto.gigi.a = 0xFFFFFFFF;
> >     toto.gigi.b = 0xFFFFFFFF;
>
> this might be the best way
> but why use unsigned long bit fields and not just
> unsigned ints? (or unsigned longs)
> e.g. struct{unsigned int a,b;}gigi;
>
> >     unsigned long long l;
> >     l = 0xFFFFFFFF;
> >     l <<= 32;
> >     l += 0xFFFFFFFF;
>
> this involves some calculations.. I doubt that the
> compiler can optimize them
>
> >     unsigned long long referenceval;
> >     memset(&referenceval, 0xFF,
> > sizeof(referenceval));
>
> this works if the bytes are identical.. but usually
> they are not
>
> thanks for the reply
>
> Adrian
>
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - forms, calculators, tips, more
> http://taxes.yahoo.com/
>
> ------------------------------------------------------------------------
> P.S. Stiai ca s-a lansat www.FreeSMS.ro ?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-20  9:05 ` Mihnea Balta
@ 2003-02-20  9:58   ` Adrian Sandor
  2003-02-20 10:24     ` Mihnea Balta
  0 siblings, 1 reply; 11+ messages in thread
From: Adrian Sandor @ 2003-02-20  9:58 UTC (permalink / raw)
  To: Mihnea Balta, gcc-help


--- Mihnea Balta <dark_lkml@mymail.ro> wrote:
>     union{
>         struct{
>             unsigned long long a:32;
>             unsigned long long b:32;
>         } gigi;
>         unsigned long long l;
>     } toto;
>     toto.gigi.a = 0xFFFFFFFF;
>     toto.gigi.b = 0xFFFFFFFF;

this might be the best way
but why use unsigned long bit fields and not just
unsigned ints? (or unsigned longs)
e.g. struct{unsigned int a,b;}gigi;

>     unsigned long long l;
>     l = 0xFFFFFFFF;
>     l <<= 32;
>     l += 0xFFFFFFFF;

this involves some calculations.. I doubt that the
compiler can optimize them

>     unsigned long long referenceval;
>     memset(&referenceval, 0xFF,
> sizeof(referenceval));

this works if the bytes are identical.. but usually
they are not

thanks for the reply

Adrian


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to make a long long
  2003-02-20  8:56 Adrian Sandor
@ 2003-02-20  9:05 ` Mihnea Balta
  2003-02-20  9:58   ` Adrian Sandor
  2003-02-20 11:02 ` Sebastian Huber
  1 sibling, 1 reply; 11+ messages in thread
From: Mihnea Balta @ 2003-02-20  9:05 UTC (permalink / raw)
  To: Adrian Sandor, gcc-help

On Thursday 20 February 2003 10:56, Adrian Sandor wrote:
> Wich is the proper way to make an unsigned long long
> from two unsigned ints (high and low dwords) without
> too many conversions and calculations?

Choose whatever you like:

int main(){
    union{
        struct{
            unsigned long long a:32;
            unsigned long long b:32;
        } gigi;
        unsigned long long l;
    } toto;
    unsigned long long l;
    unsigned long long referenceval;

    toto.gigi.a = 0xFFFFFFFF;
    toto.gigi.b = 0xFFFFFFFF;
    l = 0xFFFFFFFF;
    l <<= 32;
    l += 0xFFFFFFFF;
    memset(&referenceval, 0xFF, sizeof(referenceval));
    printf("%llu\n%llu\n%llu\n", toto.l, l, referenceval);
    return 0;
}

>
> thanks
>
> Adrian
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Tax Center - forms, calculators, tips, more
> http://taxes.yahoo.com/
>
> ------------------------------------------------------------------------
> P.S. Stiai ca s-a lansat www.FreeSMS.ro ?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* how to make a long long
@ 2003-02-20  8:56 Adrian Sandor
  2003-02-20  9:05 ` Mihnea Balta
  2003-02-20 11:02 ` Sebastian Huber
  0 siblings, 2 replies; 11+ messages in thread
From: Adrian Sandor @ 2003-02-20  8:56 UTC (permalink / raw)
  To: gcc-help


Wich is the proper way to make an unsigned long long
from two unsigned ints (high and low dwords) without
too many conversions and calculations?

thanks

Adrian

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-02-24  5:51 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-22 16:30 how to make a long long Sebastian Huber
2003-02-22 21:37 ` LLeweLLyn Reese
2003-02-22 22:13   ` Sebastian Huber
2003-02-24  5:51     ` LLeweLLyn Reese
     [not found] <1045823803.20501.ezmlm@gcc.gnu.org>
2003-02-22 15:44 ` Adrian Sandor
  -- strict thread matches above, loose matches on Subject: below --
2003-02-20  8:56 Adrian Sandor
2003-02-20  9:05 ` Mihnea Balta
2003-02-20  9:58   ` Adrian Sandor
2003-02-20 10:24     ` Mihnea Balta
2003-02-20 11:02 ` Sebastian Huber
2003-02-20 11:40   ` Mihnea Balta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).