[Done] PB 6.00 Alpha 3 - Different type casting in C-backend during binary shift

All bugs related to new C backend
User avatar
STARGÅTE
Addict
Addict
Posts: 1619
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

[Done] PB 6.00 Alpha 3 - Different type casting in C-backend during binary shift

Post by STARGÅTE »

In the ASM-backend the binary shift operates regarding the destination variable size.
That is not the case in the C-backend. Here it operates regarding the source variable size?
It seems like, this bug happens only with Long and Quad and is propaly related to this topic: [Done] different results with long/integer and logical operators

Code: Select all

Define Long.l = $12345678
Define Quad.q = Long << 16

Debug Hex(Long)
Debug Hex(Quad)
C-backend:
12345678
56780000
ASM-backend:
12345678
123456780000
PB 5.73 ― Win 10, 20H2 ― Ryzen 9 3900X ― Radeon RX 5600 XT ITX ― Vivaldi 4.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
juergenkulow
User
User
Posts: 64
Joined: Wed Sep 25, 2019 10:18 am

Re: PB 6.00 Alpha 3 - Different type casting in C-backend during binary shift

Post by juergenkulow »

Code: Select all

; (long long) shift left
Define l.l=$47114712
Define q.q=l<<16
Define r.q
CompilerIf #PB_Backend_C=#PB_Compiler_Backend
  ! v_r=((long long)v_l<<16LL); 
CompilerElse
  r=l<<16
CompilerEndIf  
SetClipboardText(RSet(Hex(q),16,"0")+" "+RSet(Hex(r),16,"0"))

;              q                r 
; ASM Backend: 0000471147120000 0000471147120000
; C Backend:   0000000047120000 0000471147120000

; // Define q.q=l<<16
; v_q=(v_l<<16LL);
; 000000014000107D     | 8B05 7D320000            | mov eax,dword ptr ds:[140004300]     |
; 0000000140001083     | C1E0 10                  | shl eax,10                           |
; Shift 4 Byte of eax Register, not 8 Byte of rax register. 
; 0000000140001086     | 48:98                    | cdqe                                 |
; 0000000140001088     | 48:8905 69320000         | mov qword ptr ds:[1400042F8],rax     |
User avatar
mk-soft
Addict
Addict
Posts: 3191
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB 6.00 Alpha 3 - Different type casting in C-backend during binary shift

Post by mk-soft »

Perhaps use type casting from gcc

Code: Select all

Define Long.l = $12345678
Define Quad.q ; = Long << 16

; from v_quad=(v_long<<16LL) to type casting
!v_quad=((quad)v_long<<16LL);

Debug Hex(Long)
Debug Hex(Quad)
Although that is actually right and we no longer need such a thing.

Code: Select all

Define Long.l = $12345678
Define Quad.q = Long << 16 & $FFFFFFFF

Debug Hex(Long)
Debug Hex(Quad)
Maybe we should think about introducing a manual type casting in PB. :?: :!:
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace
Fred
Administrator
Administrator
Posts: 14413
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 6.00 Alpha 3 - Different type casting in C-backend during binary shift

Post by Fred »

Fixed.
Post Reply