Skip to content

Commit 978c30e

Browse files
SARG-FBjayrm
authored andcommitted
gas64 : removal of duplicate code in _emitconvert by creating sub hEmitRoundFloat
(cherry picked from commit 4da0bc4)
1 parent 28bd1b5 commit 978c30e

File tree

1 file changed

+46
-42
lines changed

1 file changed

+46
-42
lines changed

src/compiler/ir-gas64.bas

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,6 +4133,48 @@ private sub _emituop(byval op as integer,byval v1 as IRVREG ptr,byval vr as IRVR
41334133
asm_info("Bop float reghandle reset so forced again to="+Str(vr->reg))
41344134
end if
41354135
end sub
4136+
private sub hEmitRoundFloat(byval dtype1 as FB_DATATYPE,byval dtype2 as FB_DATATYPE = FB_DATATYPE_INVALID)
4137+
dim as string lname1,lname2
4138+
'' Puts ctx.roundfloat to true for later adding of the code filling $sse41[rip]
4139+
ctx.roundfloat=true
4140+
asm_code("test DWORD PTR $sse41[rip], 0b10000000000000000000")
4141+
lname1 = *symbUniqueLabel( )
4142+
asm_code("je "+lname1)
4143+
4144+
if dtype1=FB_DATATYPE_DOUBLE then
4145+
asm_code("roundsd xmm0,xmm0,4")
4146+
if dtype2<>FB_DATATYPE_ULONGINT then
4147+
asm_code("cvttsd2si rax, xmm0")
4148+
end if
4149+
else
4150+
''single
4151+
asm_code("roundss xmm0,xmm0,4")
4152+
if dtype2<>FB_DATATYPE_ULONGINT then
4153+
asm_code("cvttss2si rax, xmm0")
4154+
end if
4155+
endif
4156+
4157+
lname2 = *symbUniqueLabel( )
4158+
asm_code("jmp "+lname2)
4159+
asm_code(lname1+":")
4160+
4161+
if dtype1=FB_DATATYPE_DOUBLE then
4162+
if dtype2<>FB_DATATYPE_ULONGINT then
4163+
no_roundsd(@"d")
4164+
else
4165+
asm_code("call nearbyint")
4166+
end if
4167+
else
4168+
''single
4169+
if dtype2<>FB_DATATYPE_ULONGINT then
4170+
no_roundsd(@"s")
4171+
else
4172+
asm_code("call nearbyintf")
4173+
end if
4174+
endif
4175+
4176+
asm_code(lname2+":")
4177+
end sub
41364178
private sub _emitconvert( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
41374179

41384180
dim as FB_DATATYPE v1dtype,v2dtype,v1old
@@ -4424,16 +4466,7 @@ private sub _emitconvert( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
44244466
asm_code("mov rax, "+op2)
44254467
asm_code("movq xmm0, rax")
44264468

4427-
ctx.roundfloat=true
4428-
asm_code("test DWORD PTR $sse41[rip], 0b10000000000000000000")
4429-
lname1 = *symbUniqueLabel( )
4430-
asm_code("je "+lname1)
4431-
asm_code("roundsd xmm0,xmm0,4") ''nearbyintf double
4432-
lname2 = *symbUniqueLabel( )
4433-
asm_code("jmp "+lname2)
4434-
asm_code(lname1+":")
4435-
asm_code("call nearbyint")
4436-
asm_code(lname2+":")
4469+
hEmitRoundFloat(FB_DATATYPE_DOUBLE,FB_DATATYPE_ULONGINT)
44374470

44384471
asm_code("ucomisd xmm0, xmm2")
44394472
lname1 = *symbUniqueLabel( )
@@ -4467,17 +4500,7 @@ private sub _emitconvert( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
44674500
asm_code("movsd xmm0, "+op2)
44684501
end if
44694502

4470-
ctx.roundfloat=true
4471-
asm_code("test DWORD PTR $sse41[rip], 0b10000000000000000000")
4472-
lname1 = *symbUniqueLabel( )
4473-
asm_code("je "+lname1)
4474-
asm_code("roundsd xmm0,xmm0,4") ''nearbyintf double
4475-
asm_code("cvttsd2si rax, xmm0")
4476-
lname2 = *symbUniqueLabel( )
4477-
asm_code("jmp "+lname2)
4478-
asm_code(lname1+":")
4479-
no_roundsd(@"d")
4480-
asm_code(lname2+":")
4503+
hEmitRoundFloat(FB_DATATYPE_DOUBLE)
44814504

44824505
if v1dtype=FB_DATATYPE_INTEGER Or v1dtype=FB_DATATYPE_LONGINT or v1dtype=FB_DATATYPE_ENUM then
44834506
asm_code("mov "+op1+", rax")
@@ -4505,16 +4528,7 @@ private sub _emitconvert( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
45054528
asm_code("mov eax, "+op2)
45064529
asm_code("movd xmm0, eax")
45074530

4508-
ctx.roundfloat=true
4509-
asm_code("test DWORD PTR $sse41[rip], 0b10000000000000000000")
4510-
lname1 = *symbUniqueLabel( )
4511-
asm_code("je "+lname1)
4512-
asm_code("roundss xmm0,xmm0,4")
4513-
lname2 = *symbUniqueLabel( )
4514-
asm_code("jmp "+lname2)
4515-
asm_code(lname1+":")
4516-
asm_code("call nearbyintf")
4517-
asm_code(lname2+":")
4531+
hEmitRoundFloat(FB_DATATYPE_SINGLE,FB_DATATYPE_ULONGINT)
45184532

45194533
asm_code("ucomiss xmm0, xmm2")
45204534
lname1 = *symbUniqueLabel( )
@@ -4548,17 +4562,7 @@ private sub _emitconvert( byval v1 as IRVREG ptr, byval v2 as IRVREG ptr )
45484562
asm_code("movss xmm0, "+op2)
45494563
end if
45504564

4551-
ctx.roundfloat=true
4552-
asm_code("test DWORD PTR $sse41[rip], 0b10000000000000000000")
4553-
lname1 = *symbUniqueLabel( )
4554-
asm_code("je "+lname1)
4555-
asm_code("roundss xmm0,xmm0,4") ''nearbyintf single
4556-
asm_code("cvttss2si rax, xmm0")
4557-
lname2 = *symbUniqueLabel( )
4558-
asm_code("jmp "+lname2)
4559-
asm_code(lname1+":")
4560-
no_roundsd(@"s")
4561-
asm_code(lname2+":")
4565+
hEmitRoundFloat(FB_DATATYPE_SINGLE)
45624566

45634567
if v1dtype=FB_DATATYPE_INTEGER Or v1dtype=FB_DATATYPE_LONGINT or v1dtype=FB_DATATYPE_ENUM then
45644568
asm_code("mov "+op1+", rax")

0 commit comments

Comments
 (0)