Function to set high and low Dword of a QWord

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Function to set high and low Dword of a QWord

Luiz Americo Pereira Camara
Hi,

  I'm looking to a function that will take two DWord as arguments and
and returns a Qword where the low 4 bytes are the first DWord and the
High 4 bytes the second DWord.

Something like MakeLong of win unit.

BTW

  TQWordRec = record
    D1: Dword;
    D2: DWord;
  end;

TQWordRec will have the same memory representation of  the result of
such function?

Thanks in advance.


Luiz
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Function to set high and low Dword of a QWord

Jonas Maebe-2

On 28 feb 2007, at 17:51, Luiz Americo Pereira Camara wrote:

>  I'm looking to a function that will take two DWord as arguments  
> and and returns a Qword where the low 4 bytes are the first DWord  
> and the High 4 bytes the second DWord.

function makeqword(d1, d2: dword): qword;
begin
   result:=(qword(d2) shl 32) or d1;
end;

>  TQWordRec = record
>    D1: Dword;
>    D2: DWord;
>  end;
>
> TQWordRec will have the same memory representation of  the result  
> of such function?

Only on little endian, on big endian it's the other way round.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Function to set high and low Dword of a QWord

Luiz Americo Pereira Camara-2
Jonas Maebe wrote:

>
> On 28 feb 2007, at 17:51, Luiz Americo Pereira Camara wrote:
>
>>  I'm looking to a function that will take two DWord as arguments and
>> and returns a Qword where the low 4 bytes are the first DWord and the
>> High 4 bytes the second DWord.
>
> function makeqword(d1, d2: dword): qword;
> begin
>   result:=(qword(d2) shl 32) or d1;
> end;
>
>>  TQWordRec = record
>>    D1: Dword;
>>    D2: DWord;
>>  end;
>>
>> TQWordRec will have the same memory representation of  the result of
>> such function?
>
> Only on little endian, on big endian it's the other way round.
>
Thanks

Luiz

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Function to set high and low Dword of a QWord

Florian Klämpfl
In reply to this post by Jonas Maebe-2
Jonas Maebe schrieb:

>
> On 28 feb 2007, at 17:51, Luiz Americo Pereira Camara wrote:
>
>>  I'm looking to a function that will take two DWord as arguments and
>> and returns a Qword where the low 4 bytes are the first DWord and the
>> High 4 bytes the second DWord.
>
> function makeqword(d1, d2: dword): qword;
> begin
>   result:=(qword(d2) shl 32) or d1;
> end;

Cleaner imo:

lo(result):=d1;
hi(result):=d2;

>
>>  TQWordRec = record
>>    D1: Dword;
>>    D2: DWord;
>>  end;
>>
>> TQWordRec will have the same memory representation of  the result of
>> such function?
>
> Only on little endian, on big endian it's the other way round.
>
>
> Jonas
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Function to set high and low Dword of a QWord

Jonas Maebe-2

On 28 feb 2007, at 18:06, Florian Klaempfl wrote:

> Jonas Maebe schrieb:
>>
>> function makeqword(d1, d2: dword): qword;
>> begin
>>   result:=(qword(d2) shl 32) or d1;
>> end;
>
> Cleaner imo:
>
> lo(result):=d1;
> hi(result):=d2;

I think this is a lot less clean (if only because lo/hi have  
different meanings in FPC and Delphi, making it less clear what the  
code does). Besides, lo()/hi() do not produce lvalues, so it doesn't  
even compile :)


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Function to set high and low Dword of a QWord

Florian Klämpfl
Jonas Maebe schrieb:

>
> On 28 feb 2007, at 18:06, Florian Klaempfl wrote:
>
>> Jonas Maebe schrieb:
>>>
>>> function makeqword(d1, d2: dword): qword;
>>> begin
>>>   result:=(qword(d2) shl 32) or d1;
>>> end;
>>
>> Cleaner imo:
>>
>> lo(result):=d1;
>> hi(result):=d2;
>
> I think this is a lot less clean (if only because lo/hi have different
> meanings in FPC and Delphi, making it less clear what the code does).

Well, it should generate better code ;)

> Besides, lo()/hi() do not produce lvalues, so it doesn't even compile :)

Ops, I thought this worked :)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal