News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

a shift (shl shr) on a 64 bits constants

Started by ToutEnMasm, June 11, 2009, 06:13:05 AM

Previous topic - Next topic

ToutEnMasm

Hello,
Is there a method (in masm 32 bits) to make this work ?
Quote
gros equ 1 SHL 38                     ; =0       only 32 bits

jj2007

Only with SSE2:

include \masm32\include\masm32rt.inc
.686
.xmm

.data
MyQword dq -1
MyCt dd 38

.code

start:
movq xmm2, MyQword
movd xmm3, MyCt
psllq xmm2, xmm3
movq MyQword, xmm2
exit

end start

ToutEnMasm


Using sse is a soluce.
I was thinking about a macro that place some result in a qword  with [qword] [qword+4]

Quote
; shift > 32         1ui64 = 1 in 64 bits
SPFEI_FLAGCHECK   equ   <( 1ui64 SHL SPEI_RESERVED1) OR( 1ui64 SHL SPEI_RESERVED2)>
SPFEI_ALL_TTS_EVENTS   equ   < 0000FFFEh OR SPFEI_FLAGCHECK>
SPFEI_ALL_SR_EVENTS   equ   < 0001FFFFC00000000h OR SPFEI_FLAGCHECK>
SPFEI_ALL_EVENTS   equ   < 0EFFFFFFFFFFFFFFFh>
   SPFEI MACRO SPEI_ord
      local Value
      Value equ <( 1ui64 SHL SPEI_ord ) OR SPFEI_FLAGCHECK>
      EXITM <Value>
      ENDM


sample:
qwordSPFEI MACRO SPEI_ord,Aqword
...
ENDM



jj2007

Here are two simple macros. Usage:

shl64 MyQw, 3
shr64 MyQw, 3

include \masm32\include\masm32rt.inc
.686
.xmm

shl64 MACRO arg, ct
  movq xmm0, arg
  push ct
  movd xmm1, dword ptr [esp]
  psllq xmm0, xmm1
  movq arg, xmm0
  add esp, 4
ENDM

shr64 MACRO arg, ct
  movq xmm0, arg
  push ct
  movd xmm1, dword ptr [esp]
  psrlq xmm0, xmm1
  movq arg, xmm0
  add esp, 4
ENDM

.data
MyQw dq 256

.code
start:
print "MyQw, original = ", 9
print uqword$(MyQw), 13, 10
shl64 MyQw, 3
print "MyQw, shl3 =    ", 9
print uqword$(MyQw), 13, 10
shr64 MyQw, 3
print "MyQw, shr3 =    ", 9
print uqword$(MyQw), 13, 10
getkey
exit
end start

Slugsnack

i guess if you are shifting left for example.  then you can just shift the first dword normally.  then the second dword test its most significant bit.  if it is 1 then add 1 to the first dword.  then shift that dword right as well.  this method can be applied similarly for shifting right

jj2007

Quote from: Slugsnack on June 11, 2009, 12:08:25 PM
i guess if you are shifting left for example.  then you can just shift the first dword normally.  then the second dword test its most significant bit.  if it is 1 then add 1 to the first dword.  then shift that dword right as well.  this method can be applied similarly for shifting right

Can you post an example? Just use the code above as a skeleton.

sinsi

How about:

shl64 macro arg,cnt
  if cnt lt 32
   mov eax,dword ptr [arg]
   shld dword ptr [arg+4],eax,cnt
   shl dword ptr [arg],cnt
  else
   sub eax,eax
   xchg eax,dword ptr [arg]
   shl eax,cnt-32
   mov dword ptr [arg+4],eax
  endif
endm

The only trouble is that you need a qword in memory. I think ToutEnMasm wants an equate.
Light travels faster than sound, that's why some people seem bright until you hear them.

raymond

QuoteThe only trouble is that you need a qword in memory. I think ToutEnMasm wants an equate.
I would have to guess that ToutEnMasm will have to abandon the idea of having it as an equate on a 32-bit box and settle to keep it as a qword variable in the .data section. :( :'(
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

Slugsnack

Quote from: jj2007 on June 11, 2009, 12:10:38 PM
Quote from: Slugsnack on June 11, 2009, 12:08:25 PM
i guess if you are shifting left for example.  then you can just shift the first dword normally.  then the second dword test its most significant bit.  if it is 1 then add 1 to the first dword.  then shift that dword right as well.  this method can be applied similarly for shifting right

Can you post an example? Just use the code above as a skeleton.

at college right now and the computers don't have masm32 installed but i imagine it might be something like this ?

mov eax, offset MyQword
mov ecx, dword ptr ds:[eax]
shl ecx, 1

mov dword ptr ds:[eax], ecx

mov ecx, dword ptr ds:[eax+4]
test ecx, 10000000h
jnz @f

mov byte ptr ds:[eax+3], 1

    @@:

shl ecx, 1
mov dword ptr ds:[eax+4], ecx


that would be for big endian + unsigned.  it has to be modified for little endian + 2's complement

i have a feeling i misunderstood what he wants..

gonna get back in about 20 mins and i'll recode it for little endian + 2's complement

Slugsnack

include \masm32\include\masm32rt.inc

ShiftLeft proto :DWORD

.data?

qwNum       qword       ?

.code
    Start:

xor ebx, ebx

    invoke AllocConsole
mov edi, input("Input your qword here : ")
mov eax, a2uq(edi)

mov ecx, offset qwNum
push [eax]
pop [ecx]
push [eax+4]
pop [ecx+4]

    invoke ShiftLeft, addr qwNum

            print uqword$(qwNum), 13, 10
            inkey
    invoke FreeConsole
    invoke ExitProcess, ebx

ShiftLeft proc lpqwNum:DWORD

mov eax, lpqwNum

mov ecx, [eax+4]
shl ecx, 1
mov [eax+4], ecx

mov ecx, [eax]
cmp ecx, 10000000h
jl @f

mov edx, [eax+4]
inc edx
mov [eax+4], edx

    @@:

shl ecx, 1
mov [eax], ecx

ret
ShiftLeft endp

    end Start


for unsigned qwords.  pretty easy to change to work for signed.  to make it shift more than 1 place, just call the function more times.  or add a new parameter for the count.

also.. yeah i know it's coded bad.  i coded it straight from how i would do it in my head for readability.

drizz

For constants:
HIDWORD = 0
LODWORD = 0


N = N AND 63
IF N LT 32
HIDWORD = VALUE SHR (32-N)
LODWORD = (VALUE SHL N) AND 0FFFFFFFFh
ELSE
HIDWORD = (VALUE SHL (N-32)) AND 0FFFFFFFFh
LODWORD = 0
ENDIF

myval label QWORD
DWORD LODWORD,HIDWORD
...but forget about full 64bit expression evaluation.
The truth cannot be learned ... it can only be recognized.

ToutEnMasm

Hello,
Thanks for answer.
What i want , is just a satisfying soluce to the problem to put in the sapi sample i have posted.
Making shift only in dword need to propagate the bigger bit in the other dword
Quote
shit left of 10000000h  need to pass 1 to the next dword
I have a look on the rol instruction to avoid the use of SSE but this one erase some bits.

sinsi

Are you wanting an equate (EQU) or a memory qword? What context are you using this in?

Quote from: ToutEnMasm on June 12, 2009, 06:30:46 AM
Quoteshit left of 10000000h need to pass 1 to the next dword
ah, merde  :lol
Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

Quote from: sinsi on June 12, 2009, 06:43:36 AM
Quote from: ToutEnMasm on June 12, 2009, 06:30:46 AM
Quoteshit left of 10000000h need to pass 1 to the next dword
ah, merde  :lol

Didn't know you speak French over there... ::)

Anyway, it can be done:

include \masm32\include\masm32rt.inc

.data
MyQw dq 0000FFFFFFFF0000h

.code
start:
print "Before: ", 9
mov eax, dword ptr MyQw
mov edx, dword ptr MyQw[4]
pushad
print xqword$(MyQw), 13, 10, "After:  ", 9
popad
mov ecx, 8
.Repeat
shl edx, 1
shl eax, 1
adc edx, 0 ; yep ;-)
dec ecx
.Until Zero?
mov dword ptr MyQw, eax
mov dword ptr MyQw[4], edx
print xqword$(MyQw), 13, 10

exit

end start


:bg

sinsi

Quote from: jj2007 on June 12, 2009, 06:54:31 AMDidn't know you speak French over there... ::)
Yep, we're real multicultural over here, we've got SBS.

P.S. Why the 'roll eyes'?
Light travels faster than sound, that's why some people seem bright until you hear them.