Unsigned dword/qword

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

Before I went to sleep, I replaced all the.. !xor rax,rax with rax_rax and updated the Macro names with it;

Code: Select all

CompilerIf #PB_Compiler_Processor = #PB_Processor_x86  
  Macro rax_rax
    !xor eax,eax
  EndMacro
CompilerElse
  Macro rax_rax
    !xor rax,rax
  EndMacro  
  Macro edx : rdx : EndMacro 
CompilerEndIf
... this the only way I figured it'd work under x86. However if all I needed to-do was remove ! in-front of xor rax,rax .... :evil:
Last edited by Thunder93 on Fri Mar 25, 2016 12:30 am, edited 1 time in total.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

Latest code tested.

PBx64 Debug Output:

Code: Select all

-2
-1
OK
2147483647
4294967294
2147483647
4294967294
4294967292
4294967294
-2
-1
PBx86 Debug Output:

Code: Select all

-2
-1
OK
2147483647
0
0
0
-2
0
0
0
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Unsigned dword/qword

Post by Keya »

Thunder which OS and PB are you using?

here's my latest output:

Code: Select all

;5.42 Win x64
-2
-1
OK
2147483647
4294967294
2147483647
4294967294
4294967292
4294967294
-2
-1

;5.42 Win x86
-2
-1
OK
2147483647
-2147340288
1073813504
-2147340288
-2147340290
-2147340288
-2147340288
-1073670144
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

PB 5.42 (x86, x64) under Windows x64.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Unsigned dword/qword

Post by idle »

got it working on x86

expected results are in hex
-2
-1
OK
7FFFFFFF 2147483647
FFFFFFFE 4294967294
7FFFFFFF 2147483647
FFFFFFFE 4294967294
FFFFFFFC 4294967292
FFFFFFFE 4294967294
FFFFFFFF -1
FFFFFFFE -2
x86 it will only handle longs and integers. Quads are done via function calls
x64 it should handle longs, integers and quads

please note this is a dirty hack and may yield unexpected results
and only for windows and linux

Code: Select all

CompilerIf SizeOf(integer) = 4
  
  
Macro EnableUnsigned() 
  
  !macro IDIV var
  !{ 
     !mov edx,0 
     !div var
  !}
  
  !macro IMUL reg,var
  !{
    !mov eax,reg 
    !mul var
    !mov reg,eax 
  !}  
  
  !macro SAR reg,var 
  !{
    !shr reg,var 
  !} 
  
  !macro SAL reg,var 
  !{ 
   !shl reg,var 
  !}
    
  !macro CDQ {} 
EndMacro

Macro DisableUnsigned() 
  !purge IDIV
  !purge IMUL
  !purge SAR
  !purge SAL 
  !purge CDQ 
  UndefineMacro EnableUnsigned 
EndMacro 

Procedure Unsigned(arg1.i,op1.l,arg2.i) 
  EnableASM 
  
  Select op1 
    Case '<'
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setb al 
      ProcedureReturn 
    Case '<='   
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setbe al 
      ProcedureReturn 
    Case '>'  
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !seta al 
      ProcedureReturn
    Case '>='  
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setae al 
      ProcedureReturn 
     Case '=' 
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !sete al 
      ProcedureReturn
    Case '<>' 
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setne al 
      ProcedureReturn
  EndSelect     
EndProcedure     

CompilerElse 
  
   
  Macro EnableUnsigned() 
  
  !macro IDIV var
  !{ 
     !mov rdx,0 
     !div var
  !}
  
  !macro IMUL reg,var
  !{
  !match =qword x , var 
  !\{ mov rax, reg 
     !mov r15, var 
   !\} 
    !mul reg
    !mov reg,rax 
  !}  
  
  !macro SAR reg,var 
  !{
    !shr reg,var 
  !} 
  
  !macro SAL reg,var 
  !{ 
   !shl reg,var 
  !}
    
  !macro MOVSXD reg,var  
  !{ 
    !match =dword x , var 
    !\{ mov eax, var 
       !mov reg,rax \} 
    !} 
  !macro CQO {}
  !macro CDO {}
  !macro CWD {} 
  !macro CBW {}
  !macro CWDE{}
  !macro CDQE {} 
  !macro CDQ {} 
  
  
  
EndMacro 

Macro DisableUnsigned() 
  !purge IDIV
  !purge IMUL
  !purge SAR
  !purge SAL 
  !purge MOVSXD
  !purge CQO 
  !purge CDO
  !purge CWD 
  !purge CBW
  !purge CWDE 
  !purge CDQE 
  !purge CDQ 
  UndefineMacro EnableUnsigned 
EndMacro   

Procedure Unsigned(arg1.i,op1.l,arg2.i) 
  EnableASM 
  
  Select op1 
    Case '<'
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setb al 
      ProcedureReturn 
    Case '<='   
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setbe al 
      ProcedureReturn 
    Case '>'  
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !seta al 
      ProcedureReturn
    Case '>='  
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setae al 
      ProcedureReturn 
     Case '=' 
      !xor rax,rax 
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !sete al 
      ProcedureReturn
    Case '<>' 
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setne al 
      ProcedureReturn
  EndSelect     
EndProcedure     

CompilerEndIf   

Global x.l,y.l 
x=2
y=$FFFFFFFE
Debug y 
y / 2
Debug y  

EnableUnsigned()

y=$FFFFFFFE

If Unsigned(x,'<=',y) ; unsigned comparison.
  Debug "OK"
  y / 2
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;7FFFFFFF
  y * x
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;FFFFFFFE 
  y >> 1 
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;7FFFFFFF 
  y << 1 
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;FFFFFFFE  
  y - x 
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;FFFFFFFC
  y + x 
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;FFFFFFFE
  DisableUnsigned()
  y / 2 
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;FFFFFFFF 
  y * x
  Debug  Hex(y,#PB_Long) + " " + Str(y)  ;FFFFFFFE -
EndIf
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

PBx64

Code: Select all

-2
-1
OK
7FFFFFFF 2147483647
FFFFFFFE 4294967294
7FFFFFFF 2147483647
FFFFFFFE 4294967294
FFFFFFFC 4294967292
FFFFFFFE 4294967294
FFFFFFFF -1
FFFFFFFE -2

PBx86 under Win-x64

Code: Select all

-2
-1
OK
7FFFFFFF -2147483649
FFFFFFFE -2
7FFFFFFF -2147483649
FFFFFFFE -2
FFFFFFFC -4
FFFFFFFE -2
FFFFFFFF -1
FFFFFFFE -2
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

Skipping Compiler Debugger, directly testing without it. :wink:

PBx64

Code: Select all

OK
 raw-y = 2147483647
7FFFFFFF 2147483647
 raw-y * x = 4294967294
FFFFFFFF 4294967295
7FFFFFFF 2147483647
FFFFFFFE 4294967294
FFFFFFFC 4294967292
FFFFFFFE 4294967294
FFFFFFFF -1
FFFFFFFE -2
PBx86 under Win-x64

Code: Select all

OK
 raw-y = 113816633343
7FFFFFFF 311385128959
 raw-y * x = 545460846590
FFFFFFFF 743029342207
7FFFFFFF 938450354175
FFFFFFFE 1138166333438
FFFFFFFC 1344324763644
FFFFFFFE 1550483193854
FFFFFFFF -1
FFFFFFFE -2
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Unsigned dword/qword

Post by idle »

last one I hope, please try to break it. (probably won't have to try to hard)
you can turn the patch on and off with enableunsigned disableunsigned

The patch macros are only for windows and linux
for x64 it should handle unsigned arithmetic for longs, integers and quads
for x86 it should handle unsigned arithmetic for longs, integers (quads aren't possible)

Code: Select all


CompilerIf SizeOf(integer) = 4
  
  
Macro EnableUnsigned() 
  
  !macro IDIV var
  !{ 
     !mov edx,0 
     !div var
  !}
  
  !macro IMUL reg,var
  !{
    !mov eax,reg 
    !mul var
    !mov reg,eax 
  !}  
  
  !macro SAR reg,var 
  !{
    !shr reg,var 
  !} 
  
  !macro SAL reg,var 
  !{ 
   !shl reg,var 
  !}
    
  !macro CDQ {} 
EndMacro

Macro DisableUnsigned() 
  !purge IDIV
  !purge IMUL
  !purge SAR
  !purge SAL 
  !purge CDQ 
  
EndMacro 

Procedure Unsigned(arg1.i,op1.l,arg2.i) 
  EnableASM 
  
  Select op1 
    Case '<'
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setb al 
      ProcedureReturn 
    Case '<='   
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setbe al 
      ProcedureReturn 
    Case '>'  
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !seta al 
      ProcedureReturn
    Case '>='  
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setae al 
      ProcedureReturn 
     Case '=' 
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !sete al 
      ProcedureReturn
    Case '<>' 
      !xor eax , eax
      !mov edx, [p.v_arg1]
      !cmp edx, [p.v_arg2] 
      !setne al 
      ProcedureReturn
  EndSelect     
EndProcedure     

CompilerElse 
  
   
  Macro EnableUnsigned() 
  
  !macro IDIV var
  !{ 
     !mov rdx,0 
     !div var
  !}
  
  !macro IMUL reg,var
  !{
  !match =qword x , var 
  !\{ mov rax, reg 
     !mov r15, var 
   !\} 
    !mul reg
    !mov reg,rax 
  !}  
  
  !macro SAR reg,var 
  !{
    !shr reg,var 
  !} 
  
  !macro SAL reg,var 
  !{ 
   !shl reg,var 
  !}
    
  !macro MOVSXD reg,var  
  !{ 
    !match =dword x , var 
    !\{ mov eax, var 
       !mov reg,rax \} 
    !} 
  !macro CQO {}
  !macro CDO {}
  !macro CWD {} 
  !macro CBW {}
  !macro CWDE{}
  !macro CDQE {} 
  !macro CDQ {} 
  
  
  
EndMacro 

Macro DisableUnsigned() 
  !purge IDIV
  !purge IMUL
  !purge SAR
  !purge SAL 
  !purge MOVSXD
  !purge CQO 
  !purge CDO
  !purge CWD 
  !purge CBW
  !purge CWDE 
  !purge CDQE 
  !purge CDQ 
  
EndMacro   

Procedure Unsigned(arg1.i,op1.l,arg2.i) 
  EnableASM 
  
  Select op1 
    Case '<'
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setb al 
      ProcedureReturn 
    Case '<='   
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setbe al 
      ProcedureReturn 
    Case '>'  
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !seta al 
      ProcedureReturn
    Case '>='  
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setae al 
      ProcedureReturn 
     Case '=' 
      !xor rax,rax 
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !sete al 
      ProcedureReturn
    Case '<>' 
      !xor rax,rax
      !mov rdx, [p.v_arg1]
      !cmp rdx, [p.v_arg2] 
      !setne al 
      ProcedureReturn
  EndSelect     
EndProcedure     

CompilerEndIf   

Global x.l,y.l 
x=2
y=$FFFFFFFE
Debug y 
y / 2
Debug y  
 
EnableUnsigned()

y=$FFFFFFFE

If Unsigned(x,'<=',y) ; unsigned comparison.
  Debug "OK"
  y / 2
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;7FFFFFFF
  y * x
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE 
  y >> 1 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;7FFFFFFF 
  y << 1 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE  
  y - x 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFC
  y + x 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE
  DisableUnsigned()
  y / 2 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  + " should be 7FFFFFFF if unsigned was used "  
  y * x
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE -
EndIf


CompilerIf SizeOf(Integer) = 8; 
; 
Global xx.q,yy.q 
xx=2
yy=$FFFFFFFFFFFFFFFE
Debug yy 
yy / 2
Debug yy  


EnableUnsigned()
xx=2
y=$FFFFFFFFFFFFFFFE

If Unsigned(xx,'<=',yy) ; unsigned comparison.
  Debug "OK"
  yy / 2
  Debug Hex(yy,#PB_Quad) + " " + StrU(yy)  ;7FFFFFFFFFFFFFFF
  yy * xx
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFE 
  yy >> 1 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;7FFFFFFFFFFFFFFF 
  yy << 1 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFE  
  yy - xx 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFC
  yy + xx 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFE
  DisableUnsigned()
  yy / 2 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy) + " should be 7FFFFFFFFFFFFFFF if unsigned was used " 
  yy * xx
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFE -
EndIf

CompilerEndIf 
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Unsigned dword/qword

Post by Keya »

Here's my output from Win32 Win64 Linux64! :) not sure i can test Linux32 at the moment but still checking (only just got to the keyboard!).
I havent tried breaking it yet, but initial results look SUCCESS!!! ? :) :) :)
ooh btw, just need to change a couple like "Case '>=' " to "Case '=>', '>='" :D

Code: Select all

;5.42 Win x86 on x86:
; -2
; -1
; OK
; 7FFFFFFF 18446744071562067967
; FFFFFFFE 18446744073709551614
; 7FFFFFFF 18446744071562067967
; FFFFFFFE 18446744073709551614
; FFFFFFFC 18446744073709551612
; FFFFFFFE 18446744073709551614
; FFFFFFFF 18446744073709551615 should be 7FFFFFFF If unsigned was used 
; FFFFFFFE 18446744073709551614

;5.42 Win x64 on x64:
; -2
; -1
; OK
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; FFFFFFFC 4294967292
; FFFFFFFE 4294967294
; FFFFFFFF 18446744073709551615 should be 7FFFFFFF If unsigned was used 
; FFFFFFFE 18446744073709551614
; -2
; -1
; OK
; 7FFFFFFFFFFFFFFF 9223372036854775807
; FFFFFFFFFFFFFFFE 18446744073709551614
; 7FFFFFFFFFFFFFFF 9223372036854775807
; FFFFFFFFFFFFFFFE 18446744073709551614
; FFFFFFFFFFFFFFFC 18446744073709551612
; FFFFFFFFFFFFFFFE 18446744073709551614
; FFFFFFFFFFFFFFFF 18446744073709551615 should be 7FFFFFFFFFFFFFFF If unsigned was used 
; FFFFFFFFFFFFFFFE 18446744073709551614

;5.41 Linux x64 on x64
; -2
; -1
; OK
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; FFFFFFFC 4294967292
; FFFFFFFE 4294967294
; FFFFFFFF 18446744073709551615 should be 7FFFFFFF If unsigned was used 
; FFFFFFFE 18446744073709551614
; -2
; -1
; OK
; 7FFFFFFFFFFFFFFF 9223372036854775807
; FFFFFFFFFFFFFFFE 18446744073709551614
; 7FFFFFFFFFFFFFFF 9223372036854775807
; FFFFFFFFFFFFFFFE 18446744073709551614
; FFFFFFFFFFFFFFFC 18446744073709551612
; FFFFFFFFFFFFFFFE 18446744073709551614
; FFFFFFFFFFFFFFFF 18446744073709551615 should be 7FFFFFFFFFFFFFFF If unsigned was used 
; FFFFFFFFFFFFFFFE 18446744073709551614
Last edited by Keya on Fri Mar 25, 2016 3:44 am, edited 1 time in total.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

Code: Select all

PBx86 under Win-x64
-2
-1
OK
7FFFFFFF 18446744071562067967
FFFFFFFE 18446744073709551614
7FFFFFFF 18446744071562067967
FFFFFFFE 18446744073709551614
FFFFFFFC 18446744073709551612
FFFFFFFE 18446744073709551614
FFFFFFFF 18446744073709551615 should be 7FFFFFFF if unsigned was used 
FFFFFFFE 18446744073709551614

PBx64
-2
-1
OK
7FFFFFFF 2147483647
FFFFFFFE 4294967294
7FFFFFFF 2147483647
FFFFFFFE 4294967294
FFFFFFFC 4294967292
FFFFFFFE 4294967294
FFFFFFFF 18446744073709551615 should be 7FFFFFFF if unsigned was used 
FFFFFFFE 18446744073709551614
-2
-1
OK
7FFFFFFFFFFFFFFF 9223372036854775807
FFFFFFFFFFFFFFFE 18446744073709551614
7FFFFFFFFFFFFFFF 9223372036854775807
FFFFFFFFFFFFFFFE 18446744073709551614
FFFFFFFFFFFFFFFC 18446744073709551612
FFFFFFFFFFFFFFFE 18446744073709551614
FFFFFFFFFFFFFFFF 18446744073709551615 should be 7FFFFFFFFFFFFFFF if unsigned was used 
FFFFFFFFFFFFFFFE 18446744073709551614
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

Compile without Debugger..

Code: Select all

PBx86 under Win-x64

OK
7FFFFFFF 130996502527
FFFFFFFE 330712481790
7FFFFFFF 526133493759
FFFFFFFE 725849473022
FFFFFFFC 923417968636
FFFFFFFE 1120986464254
FFFFFFFF 18446744073709551615 should be 7FFFFFFF if unsigned was used 
FFFFFFFE 18446744073709551614

PBx64

OK
7FFFFFFF 2147483647
FFFFFFFE 4294967294
7FFFFFFF 2147483647
FFFFFFFE 4294967294
FFFFFFFC 4294967292
FFFFFFFE 4294967294
FFFFFFFF 18446744073709551615 should be 7FFFFFFF if unsigned was used 
FFFFFFFE 18446744073709551614


OK
7FFFFFFFFFFFFFFF 9223372036854775807
FFFFFFFFFFFFFFFE 18446744073709551614
7FFFFFFFFFFFFFFF 9223372036854775807
FFFFFFFFFFFFFFFE 18446744073709551614
FFFFFFFFFFFFFFFC 18446744073709551612
FFFFFFFFFFFFFFFE 18446744073709551614
FFFFFFFFFFFFFFFF 18446744073709551615 should be 7FFFFFFFFFFFFFFF if unsigned was used 
FFFFFFFFFFFFFFFE 18446744073709551614
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Unsigned dword/qword

Post by idle »

The results look right!

I've just removed the unsigned procedure as it's not really required when we can patch the jmp conditions
haven't tested on x86 with this version

Code: Select all

;unsigned Long Integer Quads for windows and linux x64 / x86 (Long Integer only) 
;PB 5.24 LTS final  
;Scope unsigned arithmatic and ifs in EnableUnsigned() DisableUnsigned() blocks 

CompilerIf SizeOf(integer) = 4
  
  
Macro EnableUnsigned() 
  
  !macro IDIV var
  !{ 
     !mov edx,0 
     !div var
  !}
  
  !macro IMUL reg,var
  !{
    !mov eax,reg 
    !mul var
    !mov reg,eax 
  !}  
  
  !macro SAR reg,var 
  !{
    !shr reg,var 
  !} 
  
  !macro SAL reg,var 
  !{ 
   !shl reg,var 
  !}
    
  !macro CDQ {} 
  
  !macro JG arg
  !{ 
  !JA arg 
  !}
  !macro JGE arg 
  !{ 
     !JAE arg 
  !}
  !macro JL arg 
  !{
     !JB arg 
  !}
  !macro JLE arg 
  !{ 
     !JBE arg 
  !}
EndMacro

Macro DisableUnsigned() 
  !purge IDIV
  !purge IMUL
  !purge SAR
  !purge SAL 
  !purge CDQ 
  !purge JG
  !purge JGE
  !purge JL
  !purge JLE
EndMacro 

CompilerElse 
   
  Macro EnableUnsigned() 
  
  !macro IDIV var
  !{ 
     !mov rdx,0 
     !div var
  !}
  
  !macro IMUL reg,var
  !{
  !match =qword x , var 
  !\{ mov rax, reg 
     !mov r15, var 
   !\} 
    !mul reg
    !mov reg,rax 
  !}  
  
  !macro SAR reg,var 
  !{
    !shr reg,var 
  !} 
  
  !macro SAL reg,var 
  !{ 
   !shl reg,var 
  !}
    
  !macro MOVSXD reg,var  
  !{ 
    !match =dword x , var 
    !\{ mov eax, var 
       !mov reg,rax \} 
    !} 
  !macro CQO {}
  !macro CDO {}
  !macro CWD {} 
  !macro CBW {}
  !macro CWDE{}
  !macro CDQE {} 
  !macro CDQ {} 
  
  !macro JG arg
  !{ 
  !JA arg 
  !}
  !macro JGE arg 
  !{ 
     !JAE arg 
  !}
  !macro JL arg 
  !{
     !JB arg 
  !}
  !macro JLE arg 
  !{ 
     !JBE arg 
  !}
     
EndMacro 

Macro DisableUnsigned() 
  !purge IDIV
  !purge IMUL
  !purge SAR
  !purge SAL 
  !purge MOVSXD
  !purge CQO 
  !purge CDO
  !purge CWD 
  !purge CBW
  !purge CWDE 
  !purge CDQE 
  !purge CDQ 
  !purge JG
  !purge JGE
  !purge JL
  !purge JLE
EndMacro   

CompilerEndIf   

Global x.l,y.l 
x=2
y=$FFFFFFFC
If x > y 
  Debug "Result not unsigned, activating EnableUnsigned()"
  EnableUnsigned()
EndIf   

If y >= x 
  Debug "OK Unsigned Enabled "
EndIf 

y=$FFFFFFFE
x=2
If x < y ;Unsigned(x,'<=',y) ; unsigned comparison.
  Debug "OK x <= y"
  y / 2
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;7FFFFFFF
  y * x
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE 
  y >> 1 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;7FFFFFFF 
  y << 1 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE  
  y - x 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFC
  y + x 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE
  DisableUnsigned()
  y / 2 
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  + " should be 7FFFFFFF if unsigned was used "  
  y * x
  Debug  Hex(y,#PB_Long) + " " + StrU(y)  ;FFFFFFFE -
EndIf


CompilerIf SizeOf(Integer) = 8; 
; 
Global xx.q,yy.q 
xx=2
yy=$FFFFFFFFFFFFFFFC
Debug yy 

If xx > yy 
  Debug "Result not unsigned, activating EnableUnsigned()"
  EnableUnsigned()
EndIf   

If yy >= xx 
  Debug "OK Unsigned Enabled "
EndIf 

If xx <= yy 
  Debug "OK xx <= yy"
  yy / 2
  Debug Hex(yy,#PB_Quad) + " " + StrU(yy)  ;7FFFFFFFFFFFFFFF
  yy * xx
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFE 
  yy >> 1 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;7FFFFFFFFFFFFFFF 
  yy << 1 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFE  
  yy - xx 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFC
  yy + xx 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFFFFFFFFFE
  DisableUnsigned()
  yy / 2 
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy) + " should be 7FFFFFFFFFFFFFFF if unsigned was used " 
  yy * xx
  Debug  Hex(yy,#PB_Quad) + " " + StrU(yy)  ;FFFFFFFE -
EndIf

CompilerEndIf 
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Unsigned dword/qword

Post by Keya »

latest :)

Code: Select all

5.42 Win x86 on x86 
; Result not unsigned, activating EnableUnsigned()
; OK Unsigned Enabled 
; OK x <= y
; 7FFFFFFF 18446744071562067967
; FFFFFFFE 18446744073709551614
; 7FFFFFFF 18446744071562067967
; FFFFFFFE 18446744073709551614
; FFFFFFFC 18446744073709551612
; FFFFFFFE 18446744073709551614
; FFFFFFFF 18446744073709551615 should be 7FFFFFFF if unsigned was used 
; FFFFFFFE 18446744073709551614


5.42 Win x64 on x64
; Result Not unsigned, activating EnableUnsigned()
; OK Unsigned Enabled 
; OK x <= y
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; FFFFFFFC 4294967292
; FFFFFFFE 4294967294
; FFFFFFFF 18446744073709551615 should be 7FFFFFFF If unsigned was used 
; FFFFFFFE 18446744073709551614
; -4
; Result Not unsigned, activating EnableUnsigned()
; OK Unsigned Enabled 
; OK xx <= yy
; 7FFFFFFFFFFFFFFE 9223372036854775806
; FFFFFFFFFFFFFFFC 18446744073709551612
; 7FFFFFFFFFFFFFFE 9223372036854775806
; FFFFFFFFFFFFFFFC 18446744073709551612
; FFFFFFFFFFFFFFFA 18446744073709551610
; FFFFFFFFFFFFFFFC 18446744073709551612
; FFFFFFFFFFFFFFFE 18446744073709551614 should be 7FFFFFFFFFFFFFFF If unsigned was used 
; FFFFFFFFFFFFFFFC 18446744073709551612 


5.41 Linux x64 on x64
; Result Not unsigned, activating EnableUnsigned()
; OK Unsigned Enabled 
; OK x <= y
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; 7FFFFFFF 2147483647
; FFFFFFFE 4294967294
; FFFFFFFC 4294967292
; FFFFFFFE 4294967294
; FFFFFFFF 18446744073709551615 should be 7FFFFFFF If unsigned was used 
; FFFFFFFE 18446744073709551614
; -4
; Result Not unsigned, activating EnableUnsigned()
; OK Unsigned Enabled 
; OK xx <= yy
; 7FFFFFFFFFFFFFFE 9223372036854775806
; FFFFFFFFFFFFFFFC 18446744073709551612
; 7FFFFFFFFFFFFFFE 9223372036854775806
; FFFFFFFFFFFFFFFC 18446744073709551612
; FFFFFFFFFFFFFFFA 18446744073709551610
; FFFFFFFFFFFFFFFC 18446744073709551612
; FFFFFFFFFFFFFFFE 18446744073709551614 should be 7FFFFFFFFFFFFFFF If unsigned was used 
; FFFFFFFFFFFFFFFC 18446744073709551612
Last edited by Keya on Fri Mar 25, 2016 4:55 am, edited 3 times in total.
User avatar
Thunder93
Addict
Addict
Posts: 1788
Joined: Tue Mar 21, 2006 12:31 am
Location: Canada

Re: Unsigned dword/qword

Post by Thunder93 »

PB_x64

Code: Select all

Result not unsigned, activating EnableUnsigned()
OK Unsigned Enabled 
OK x <= y
7FFFFFFF 2147483647
FFFFFFFE 4294967294
7FFFFFFF 2147483647
FFFFFFFE 4294967294
FFFFFFFC 4294967292
FFFFFFFE 4294967294
FFFFFFFF 18446744073709551615 should be 7FFFFFFF if unsigned was used 
FFFFFFFE 18446744073709551614
-4
Result not unsigned, activating EnableUnsigned()
OK Unsigned Enabled 
OK xx <= yy
7FFFFFFFFFFFFFFE 9223372036854775806
FFFFFFFFFFFFFFFC 18446744073709551612
7FFFFFFFFFFFFFFE 9223372036854775806
FFFFFFFFFFFFFFFC 18446744073709551612
FFFFFFFFFFFFFFFA 18446744073709551610
FFFFFFFFFFFFFFFC 18446744073709551612
FFFFFFFFFFFFFFFE 18446744073709551614 should be 7FFFFFFFFFFFFFFF if unsigned was used 
FFFFFFFFFFFFFFFC 18446744073709551612

PB_x86 under Win-x64

Code: Select all

Result not unsigned, activating EnableUnsigned()
OK Unsigned Enabled 
OK x <= y
7FFFFFFF 18446744071562067967
FFFFFFFE 18446744073709551614
7FFFFFFF 18446744071562067967
FFFFFFFE 18446744073709551614
FFFFFFFC 18446744073709551612
FFFFFFFE 18446744073709551614
FFFFFFFF 18446744073709551615 should be 7FFFFFFF if unsigned was used 
FFFFFFFE 18446744073709551614
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Unsigned dword/qword

Post by idle »

Windows 11, Manjaro, Raspberry Pi OS
Image
Post Reply