Skip to content

Commit 7a00dfc

Browse files
committed
fbc : reviewing of hGetMagicStructNumber(),hGetReturnTypeGas64Linux() and struct_analyze() for better understanding
gas64 : use of hGetMagicStructNumber()
1 parent 59c9854 commit 7a00dfc

File tree

3 files changed

+55
-41
lines changed

3 files changed

+55
-41
lines changed

src/compiler/ir-gas64.bas

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ declare sub _emitscopebegin( byval s as FBSYMBOL ptr )
325325
declare sub _emitscopeend( byval s as FBSYMBOL ptr )
326326
declare sub _emitMacro( byval op as integer,byval v1 as IRVREG ptr, byval v2 as IRVREG ptr, byval vr as IRVREG ptr )
327327
declare sub save_call(byref func as string,byval vr as IRVREG ptr,byval vrreg as integer)
328-
declare sub struct_analyze(byval fld as FBSYMBOL ptr,byref class1 as integer,byref class2 as integer,byref limit as integer)
328+
declare function hGetMagicStructNumber( byval sym as FBSYMBOL ptr ) as integer
329329
''===================== globals ===========================================
330330
dim shared as EDBGCTX ctx_asm64
331331
dim shared as long reghandle(KREGUPPER+2)
@@ -2266,7 +2266,7 @@ private function param_analyze(byval dtype as FB_DATATYPE,byval struc as FBSYMBO
22662266
,byref cptarg as integer=0,byref cptint as integer=0,byref cptfloat as integer=0) as integer
22672267
''used in hdocall and also in procallocarg but here do not update cptarg/cptint/cptfloat.....
22682268
dim as FBSYMBOL ptr fld = any
2269-
dim as integer lgt,intcpt,floatcpt,class1,class2,limit
2269+
dim as integer lgt,intcpt,floatcpt
22702270

22712271
if ctx.target=FB_COMPTARGET_LINUX then
22722272
'' LNX =================================================================================
@@ -2293,41 +2293,35 @@ private function param_analyze(byval dtype as FB_DATATYPE,byval struc as FBSYMBO
22932293
lgt=struc->lgt
22942294
asm_info("subtype/lgt="+*symbGetMangledName(struc)+" "+str(lgt))
22952295
if lgt<=typeGetSize( FB_DATATYPE_LONGINT )*2 then
2296-
''by default floating point for first register
2297-
class1=2
2298-
class2=0
2299-
limit=7
2300-
struct_analyze(struc,class1,class2,limit)
2301-
asm_info("typeregister="+str(class1+class2))
2302-
select case as const class1+class2
2303-
case 1
2296+
select case as const hGetMagicStructNumber( struc )
2297+
case KSTRUCT_R
23042298
if cptint <6 then
23052299
cptint+=1
23062300
return KPARAMR1
23072301
end if
2308-
case 2
2302+
case KSTRUCT_X
23092303
if cptfloat <8 then
23102304
cptfloat+=1
23112305
return KPARAMX1
23122306
end if
2313-
case 5
2307+
case KSTRUCT_RR
23142308
if cptint <5 then
23152309
cptint+=2
23162310
return KPARAMRR
23172311
end if
2318-
case 9
2312+
case KSTRUCT_RX
23192313
if cptint <6 and cptfloat <8 then
23202314
cptint+=1
23212315
cptfloat+=1
23222316
return KPARAMRX
23232317
end if
2324-
case 6
2318+
case KSTRUCT_XR
23252319
if cptint <6 and cptfloat <8 then
23262320
cptfloat+=1
23272321
cptint+=1
23282322
return KPARAMXR
23292323
end if
2330-
case 10
2324+
case KSTRUCT_XX
23312325
if cptfloat <7 then
23322326
cptfloat+=2
23332327
return KPARAMXX

src/compiler/symb-struct.bas

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -639,49 +639,54 @@ sub symbInsertInnerUDT _
639639
end sub
640640

641641
''================================================
642-
'' for Linux structure parameters size<=16
642+
'' for Linux structure parameters size<=16 bytes
643643
''================================================
644-
645-
sub struct_analyze( byval fld as FBSYMBOL ptr, byref part1 as integer, byref part2 as integer, byref limit as integer )
644+
'' if the structure size is less or equal to 16 bytes it could be passed directly in registers according the datatype fields
645+
'' integers and floats could even be mixed using Rxx and Xmm
646+
'' analyzing the 8 low bytes then the 8 high bytes to know if each block contains integer or/and float
647+
'' if at least one integer field all the range is considered as integer
648+
'' if the size is greater than 8 and the result is only KPART1FLOAT or KPART1INTEGER then the structure is totally float or totally integer
649+
'' (the structure contains only an array of simple datatype) and the result is forced to KSTRUCT_XX or KSTRUCT_RR
650+
''================================================
651+
private sub struct_analyze( byval fld as FBSYMBOL ptr, byref part1 as integer, byref part2 as integer, byref range as integer )
646652

647653
dim as integer lgt=fld->lgt
648654
fld = symbUdtGetFirstField(fld)
649655
while fld
650-
if limit=7 and fld->ofs>7 then
651-
limit+=8
652-
part2=8
656+
if range=KLOW8BYTES and fld->ofs>7 then
657+
range = KHIGH8BYTES
658+
part2 = KPART2FLOAT ''default
653659
end if
654660

655661
if typegetclass(fld->typ)=FB_DATACLASS_UDT then
656-
struct_analyze(fld->subtype,part1,part2,limit)
662+
struct_analyze(fld->subtype,part1,part2,range)
657663
elseif typegetclass(fld->typ)=FB_DATACLASS_INTEGER then
658-
if limit=7 then
659-
part1=1
664+
if range=KLOW8BYTES then
665+
part1=KPART1INTEGER
660666
else
661-
part2=4
667+
part2=KPART2INTEGER
662668
end if
663669
end if
664670
fld=symbUdtGetNextField(fld)
665671
wend
666672

667673
if lgt>8 then
668674
''case array in type eg type udt / array(0 to 1) as integer /end type
669-
if part1+part2=1 then
670-
part1=5
671-
elseif part1+part2=2 then
672-
part1=10
675+
if part1+part2=KPART1INTEGER then
676+
part1=KSTRUCT_RR
677+
elseif part1+part2=KPART1FLOAT then
678+
part1=KSTRUCT_XX
673679
end if
674680
end if
675681

676682
end sub
677-
678-
private function hGetMagicStructNumber( byval sym as FBSYMBOL ptr ) as integer
683+
function hGetMagicStructNumber( byval sym as FBSYMBOL ptr ) as integer
679684
'' by default floating point for first register
680-
dim as integer part1 = 2
681-
dim as integer part2 = 0
682-
dim as integer limit = 7
685+
dim as integer part1 = KPART1FLOAT
686+
dim as integer part2 = KPARTNOTDEF
687+
dim as integer range = KLOW8BYTES
683688

684-
struct_analyze( sym, part1, part2, limit )
689+
struct_analyze( sym, part1, part2, range )
685690

686691
return part1 + part2
687692
end function
@@ -695,24 +700,24 @@ private function hGetReturnTypeGas64Linux( byval sym as FBSYMBOL ptr ) as intege
695700

696701
if( sym->lgt <= typeGetSize( FB_DATATYPE_LONGINT ) * 2 ) then
697702
select case as const hGetMagicStructNumber( sym )
698-
case 1 ''only integers in RAX
703+
case KSTRUCT_R ''only integers in RAX
699704
'' don't set retin2regs, it's handled by datatype only
700705
'' sym->udt.retin2regs = FB_STRUCT_R
701706
return FB_DATATYPE_LONGINT
702-
case 2 ''only floats in XMM0
707+
case KSTRUCT_X ''only floats in XMM0
703708
'' don't set retin2regs, it's handled by datatype only
704709
'' sym->udt.retin2regs = FB_STRUCT_X
705710
return FB_DATATYPE_DOUBLE
706-
case 5 ''only integers in RAX/RDX
711+
case KSTRUCT_RR ''only integers in RAX/RDX
707712
sym->udt.retin2regs = FB_STRUCT_RR
708713
return FB_DATATYPE_STRUCT
709-
case 9 ''first part in RAX then in XMMO
714+
case KSTRUCT_RX ''first part in RAX then in XMMO
710715
sym->udt.retin2regs = FB_STRUCT_RX
711716
return FB_DATATYPE_STRUCT
712-
case 6 ''first part in XMMO then in RAX
717+
case KSTRUCT_XR ''first part in XMMO then in RAX
713718
sym->udt.retin2regs = FB_STRUCT_XR
714719
return typeAddrOf( FB_DATATYPE_STRUCT )
715-
case 10 ''only floats in XMM0/XMM1
720+
case KSTRUCT_XX ''only floats in XMM0/XMM1
716721
sym->udt.retin2regs = FB_STRUCT_XX
717722
return FB_DATATYPE_STRUCT
718723
case else

src/compiler/symb.bi

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,21 @@ enum FB_STRUCT_INREG
275275
FB_STRUCT_XX ''XMM0/XMM1
276276
end enum
277277

278+
''for analyzing structures Linux only
279+
#define KPARTNOTDEF 0
280+
#define KPART1FLOAT 2
281+
#define KPART2FLOAT 8
282+
#define KPART1INTEGER 1
283+
#define KPART2INTEGER 4
284+
#define KLOW8BYTES 1
285+
#define KHIGH8BYTES 2
286+
#define KSTRUCT_R KPART1INTEGER
287+
#define KSTRUCT_X KPART1FLOAT
288+
#define KSTRUCT_RR KPART1INTEGER + KPART2INTEGER
289+
#define KSTRUCT_RX KPART1INTEGER + KPART2FLOAT
290+
#define KSTRUCT_XR KPART1FLOAT + KPART2INTEGER
291+
#define KSTRUCT_XX KPART1FLOAT + KPART2FLOAT
292+
278293
type FBSYMBOL_ as FBSYMBOL
279294

280295
#ifndef ASTNODE_

0 commit comments

Comments
 (0)