[bug?] xmm optimizations

General FreeBASIC programming questions.
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

[bug?] xmm optimizations

Postby Gonzo » Jan 16, 2012 1:21

Code: Select all

   print .flrad; .flspd  ' 0.0    0.5
   .flrad += .flspd
   print .flrad; .flspd  ' 0.0    0.5


i managed to replicate it using -fpu SSE -fpmode FAST -vec 2 =)

here is the bugged version:
http://fbcraft.fwsnet.net/testing.rar

comparison:

Code: Select all

// without optimization
   mov ebx, dword ptr [ebp-8]
   mov eax, dword ptr [ebp-8]
   fld dword ptr [eax+128]
   fadd dword ptr [ebx+124]
   mov ebx, dword ptr [ebp-8]
   fstp dword ptr [ebx+124]
   push 0

// with optimization
   mov ebx, dword ptr [ebp-8]
   movss xmm6, dword ptr [ebx+124]
   mov ebx, dword ptr [ebp-8]
   movss dword ptr [ebx+124], xmm6
   push 0

Last edited by Gonzo on Jan 16, 2012 14:07, edited 3 times in total.
counting_pine
Site Admin
Posts: 6176
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: float won't increase!

Postby counting_pine » Jan 16, 2012 1:34

Can you post a complete program that illustrates your problem? I tried filling in the blanks and it worked as expected:

Code: Select all

type f32_t as single

type actor
   'flying/floating
   float as f32_t 'float factor
   flrad as f32_t 'float rotation 0 - PI2
   flspd as f32_t 'float increment
end type

dim a as actor
with a
    .flrad = 0.0: .flspd = 0.5
    print .flrad; .flspd  ' 0 0.5
    .flrad += .flspd
    print .flrad; .flspd  ' 0.5 0.5
end with
And where are you using const? It's not obvious to me.
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Re: float won't increase!

Postby Gonzo » Jan 16, 2012 11:02

i will try figure out what the cause is...

but the offending code is simply:
.flrad += .flspd

if i replace it with
.flrad += constant

it starts working...

so far ive tried:
reshuffling structs
renaming variables
changing type
i looked at the preprocess, and its correct
using constant.. which is the only one that worked so far

i started a new project and tested with all the same structs... it works there

here is the ASM:

Code: Select all

   print .flrad; .flspd  ' 0.0    0.5
   .flrad += .flspd
   print .flrad; .flspd  ' 0.0    0.5

   call _fb_PrintSingle@12
   push 1
   mov ebx, dword ptr [ebp-8]
   push dword ptr [ebx+128]
   push 0
   call _fb_PrintSingle@12
   mov ebx, dword ptr [ebp-8]
   mov eax, dword ptr [ebp-8]
   fld dword ptr [eax+128]
   fadd dword ptr [ebx+124]
   mov ebx, dword ptr [ebp-8]
   fstp dword ptr [ebx+124]
   push 0
   mov ebx, dword ptr [ebp-8]
   push dword ptr [ebx+124]
   push 0
   call _fb_PrintSingle@12
   push 1
   mov ebx, dword ptr [ebp-8]
   push dword ptr [ebx+128]
   push 0
   call _fb_PrintSingle@12



i made a second project and run the same code, there it works
the asm output is the same:

Code: Select all

mov ebx, dword ptr [ebp-8]
mov eax, dword ptr [ebp-8]
fld dword ptr [eax+128]
fadd dword ptr [ebx+124]
mov ebx, dword ptr [ebp-8]
fstp dword ptr [ebx+124]
Richard
Posts: 2984
Joined: Jan 15, 2007 20:44
Location: Australia

Re: float won't increase!

Postby Richard » Jan 16, 2012 13:22

float is ambiguous, .float is not changed by .flrad += .flspd
This code seems to work as expected...

Code: Select all

Type f32_t As Single    ' alias

Type actor
    float As f32_t 'float factor
    flrad As f32_t 'float rotation 0 - PI2
    flspd As f32_t 'float increment
End Type

Dim As actor x

x.float = .1
x.flrad = .2
x.flspd = .3

print "  i", "float", "flrad", "flspd"
For i As Integer = 1 To 10
    With x
        Print i, .float, .flrad, .flspd
        .flrad += .flspd
    End With
Next i

Sleep

Please post code that runs without modification and that demonstrates the fault. Once we can demonstrate a fault we can examine the generated assembly code and test the different versions of FB.
.
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Re: float won't increase!

Postby Gonzo » Jan 16, 2012 13:44

yes but thats the problem here... ive tried with all kinds of different variable names, struct organizations..
the assembler output is EXACTLY the same on my test (which works) and my project (where it doesnt work)

the only things that does work on my project:
1. changing single to short
2. changing flrad to a const single

ive never had this happen before so im kind of stumped...
3 lines of code to make an object float up and down is starting to drain time

here is my testing project:
http://fbcraft.fwsnet.net/testing.rar

.float is uncommented in my code, its used elsewhere (where its also uncommented atm)
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Re: float won't increase!

Postby Gonzo » Jan 16, 2012 13:53

i managed to replicate it using -fpu SSE -fpmode FAST -vec 2 =)

here is the bugged version:
http://fbcraft.fwsnet.net/testing.rar

comparison:

Code: Select all

// without optimization
   mov ebx, dword ptr [ebp-8]
   mov eax, dword ptr [ebp-8]
   fld dword ptr [eax+128]
   fadd dword ptr [ebx+124]
   mov ebx, dword ptr [ebp-8]
   fstp dword ptr [ebx+124]
   push 0

// with optimization
   mov ebx, dword ptr [ebp-8]
   movss xmm6, dword ptr [ebx+124]
   mov ebx, dword ptr [ebp-8]
   movss dword ptr [ebx+124], xmm6
   push 0

counting_pine
Site Admin
Posts: 6176
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: [bug?] xmm optimizations

Postby counting_pine » Jan 16, 2012 18:02

Editing your first post has made this a bit confusing to follow!

Anyway, this code seems to show the bug:

Code: Select all

'' compile with -fpu sse -vec 2
dim as single f1, f2
f1 = 0: f2 = 1
print f1, f2 '' 0, 1
f1 += .f2
print f1, f2 '' 1, 1


type udt
   f1 as single
   f2 as single
end type

dim u as udt

u.f1 = 0: u.f2 = 1
print u.f1, u.f2 '' 0, 1
u.f1 += u.f2
print u.f1, u.f2 '' 0, 1!
Gonzo
Posts: 722
Joined: Dec 11, 2005 22:46

Re: [bug?] xmm optimizations

Postby Gonzo » Jan 16, 2012 18:29

can confirm it doesnt happen with -vec 1
counting_pine
Site Admin
Posts: 6176
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: [bug?] xmm optimizations

Postby counting_pine » Jan 16, 2012 18:49

I've filed a report at http://www.sf.net/support/tracker.php?aid=3474511. Thanks for letting us know.

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests