forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

VFPU: vf2in and vi2f

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Tue Sep 05, 2006 4:38 am    Post subject: VFPU: vf2in and vi2f Reply with quote

Does anyone know how the vf2in/vi2f functions work? Do they just convert a bunch of float values to int's/int's to float's, in the sense that after vf2in the VFPU regs now contain numbers coded like 32-bit signed int's instead of floats and I could then just store them back to memory and use as int's? Or in the case of vi2f I can just load int's into a VFPU register and that will convert them to floats?

If yes, that's SOOOOOOO great!!! :)
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Tue Sep 05, 2006 10:09 am    Post subject: Reply with quote

Yes.
There are also other vf2i versions for different rounding methods. Dunno exactly from the top of my head though.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Wed Sep 06, 2006 2:16 am    Post subject: Reply with quote

Thanks! :)

Now taking the opportunity, how do vmul/vdot/vdiv work? Do vmul and vdiv just multiply each part of the 2 vectors and put them at the respective place for the destination one? As for vdot, where does it put the result (since the dest reg is a vector)?

Also can the VFPU do Outer Products? If so, how?

Thanks in advance again :)
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Sep 06, 2006 5:10 am    Post subject: Reply with quote

Tinnus wrote:

Now taking the opportunity, how do vmul/vdot/vdiv work? Do vmul and vdiv just multiply each part of the 2 vectors and put them at the respective place for the destination one?

Yes.

Quote:
As for vdot, where does it put the result (since the dest reg is a vector)?

No, the destination register is a single register (s***).

Quote:
Also can the VFPU do Outer Products? If so, how?

I suppose you refer to the cross-product of two 3D-vectors:
vcrsp.t

Quote:
Thanks in advance again :)

No problem :)
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Wed Sep 06, 2006 5:25 am    Post subject: Reply with quote

Yes I mean the cross product. And thanks for clarifying the dot product destination register and all the rest :)
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Thu Sep 07, 2006 5:10 am    Post subject: Reply with quote

OK. Last question :)

I just found out you can put a scale value in vf2i and vi2f, but can't you use a negative scale? ie: like you were doing a shift to the right.

I tried but the assembler complained about "improper scale: some-big-number". I think he expects an unsigned value and got a big number since -12 in unsigned codification would turn out big.

Being able to scale down would be great for fixed-point...
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Thu Sep 07, 2006 7:14 am    Post subject: Reply with quote

Tinnus wrote:
OK. Last question :)

I just found out you can put a scale value in vf2i and vi2f, but can't you use a negative scale? ie: like you were doing a shift to the right.

I tried but the assembler complained about "improper scale: some-big-number". I think he expects an unsigned value and got a big number since -12 in unsigned codification would turn out big.

Being able to scale down would be great for fixed-point...


Yeah, only positive shifts. You can work around that though, by loading a immediate into a single register (vim.s s000, 1024) and just scaling your vector with vscl.q by the reciprocal (vrcp.s s000, s000). In that case it would be the same as a shift right by 10 (though somewhat slower).

PS: For what fixed-point when it's just a hassle to work with on vfpu? Why not use float?
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Thu Sep 07, 2006 8:53 am    Post subject: Reply with quote

Because I'm working on emulating something that stores stuff internally as fixed-point.

Namely, one of the SNES coprocessors.

But that's not that big of a problem, I'll just do the >>'s in C after converting.
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Tue Sep 12, 2006 8:31 am    Post subject: Reply with quote

Just one more :)

Are there any instructions to move data to/from the general and VFPU registers? Or must I move data to memory first? (ugh)
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Sep 13, 2006 4:29 am    Post subject: Reply with quote

mtv $rs, $rd // move to vector, $rs -> $rd, $rs = mips register, $rd = single vfpu register
mfv $rd, $rs // move from vector, $rs -> $rd, $rd =mips register, $rs = single vfpu register
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Wed Sep 13, 2006 6:00 am    Post subject: Reply with quote

Thanks again! :)

Now, do you know of any place I can get a *full* list of the VFPU ops? For example, none of the ones that I've seen until now have mfv/mtv/vcrsp/vim...
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
adrahil



Joined: 16 Mar 2006
Posts: 277

PostPosted: Wed Sep 13, 2006 6:22 am    Post subject: Reply with quote

You could dig them out from here: http://svn.ps2dev.org/filedetails.php?repname=psp&path=%2Ftrunk%2Fbinutils-psp%2Fopcodes%2Fmips-opc.c&rev=0&sc=0

Look under the "/* Sony Allegrex VFPU instructions. */" section.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Sep 13, 2006 9:57 am    Post subject: Reply with quote

adrahil wrote:
You could dig them out from here: http://svn.ps2dev.org/filedetails.php?repname=psp&path=%2Ftrunk%2Fbinutils-psp%2Fopcodes%2Fmips-opc.c&rev=0&sc=0

Look under the "/* Sony Allegrex VFPU instructions. */" section.


Code:

{"mtv",     "t,?d0z",      0x48e00000, 0xffe0ff80, LCD|WR_t|WR_C2,   0,      AL   },
{"mfv",     "t,?d0z",      0x48600000, 0xffe0ff80, COD|RD_t|WR_CC|RD_C2, 0,   AL   },
{"vrcp.q",  "?x3z,?s3y",   0xd0108080, 0xffff8080, RD_C2,      0,      AL   },
{"viim.s",  "?t0d,j",      0xdf000000, 0xff800000, RD_C2,      0,      AL   },


They're all there, you just need to find them ;) (ps, I misspelled the viim.s instruction in my privious post)
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Tinnus



Joined: 29 Jul 2006
Posts: 67

PostPosted: Wed Sep 13, 2006 10:14 am    Post subject: Reply with quote

Hmm, but how do I know what they do and what params they take?

Also any information on vcmp? I guess it does a comparison, but where is the result stored?
_________________
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Wed Sep 13, 2006 2:40 pm    Post subject: Reply with quote

Some educated guessing plus try&error. I already thought about writing up all my findings so far to document the VFPU ops. Might be a good idea, but time-consuming.

vcmp stores the result of the compare in the cc (conditional register), which in turn can be checked on and branched with bc*f? (branch conditional* on false = if (!cc)) or bc*t? (branch conditional* on true = if (cc)) [I'm not sure what the possible l at the ? might mean]. There are versions for * = 0-3 (ie there are 4 conditional registers) but I'm yet to find out when exactly which one is used (I had luck with c1 in my current project).
The arguments of vcmp.* are CMP, rs, rd where CMP can be something like EQ (equals), LT/GT (lower/greater then), LE/GE (lower/greater or equal). rs and rd are single or vector registers, depending on * being .s or something else.
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Sat Sep 30, 2006 8:53 pm    Post subject: Reply with quote

Raphael wrote:
adrahil wrote:
You could dig them out from here: http://svn.ps2dev.org/filedetails.php?repname=psp&path=%2Ftrunk%2Fbinutils-psp%2Fopcodes%2Fmips-opc.c&rev=0&sc=0

Look under the "/* Sony Allegrex VFPU instructions. */" section.


Code:

{"mtv",     "t,?d0z",      0x48e00000, 0xffe0ff80, LCD|WR_t|WR_C2,   0,      AL   },
{"mfv",     "t,?d0z",      0x48600000, 0xffe0ff80, COD|RD_t|WR_CC|RD_C2, 0,   AL   },
{"vrcp.q",  "?x3z,?s3y",   0xd0108080, 0xffff8080, RD_C2,      0,      AL   },
{"viim.s",  "?t0d,j",      0xdf000000, 0xff800000, RD_C2,      0,      AL   },


They're all there, you just need to find them ;) (ps, I misspelled the viim.s instruction in my privious post)


okay, let's try to make some synopsys :

viim.s S000, 10 <==> S000 = 10;
vfim.s S000, 0.5 <==> S000 = 0.5;
mtv v0, S000 <==> S000= *((float *)&v0); // XFER W/O CONVERSION
mfv v0, S000 <==> v0 = *((int *)&S000); // XFER W/O CONVERSION

Am I right ?

What do the following instructions :

vi2f.s S000.s,S001.s,1
vf2in.s S000.s,S001.s,1
vf2iz.s S000.s,S001.s,1
vf2iu.s S000.s,S001.s,1
vf2id.s S000.s,S001.s,1

Code:

{"vf2in.s", "?d0m,?s0s,?b",     0xd2000000, 0xffe08080, RD_C2,          0,              AL      },
{"vf2iz.s", "?d0m,?s0s,?b",     0xd2200000, 0xffe08080, RD_C2,          0,              AL      },
{"vf2iu.s", "?d0m,?s0s,?b",     0xd2400000, 0xffe08080, RD_C2,          0,              AL      },
{"vf2id.s", "?d0m,?s0s,?b",     0xd2600000, 0xffe08080, RD_C2,          0,              AL      },
{"vi2f.s",  "?d0d,?s0w,?b",     0xd2800000, 0xffe08080, RD_C2,          0,              AL      },

i'm pretty clueless with "?b"
Back to top
View user's profile Send private message
adrahil



Joined: 16 Mar 2006
Posts: 277

PostPosted: Sat Sep 30, 2006 11:34 pm    Post subject: Reply with quote

Quote:
vi2f.s S000.s,S001.s,1
vf2in.s S000.s,S001.s,1
vf2iz.s S000.s,S001.s,1
vf2iu.s S000.s,S001.s,1
vf2id.s S000.s,S001.s,1

check this out:
http://hitmen.c02.at/files/yapspd/psp_doc/chap4.html#sec4.9
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Sun Oct 01, 2006 1:37 am    Post subject: Reply with quote

adrahil wrote:
Quote:
vi2f.s S000.s,S001.s,1
vf2in.s S000.s,S001.s,1
vf2iz.s S000.s,S001.s,1
vf2iu.s S000.s,S001.s,1
vf2id.s S000.s,S001.s,1

check this out:
http://hitmen.c02.at/files/yapspd/psp_doc/chap4.html#sec4.9


oh well, you may be sure it would be the first right place where I go to find my answers but this link DOESN'T answer my questions. That is, what are the exact operations of thoses instructions ? If someone does know it, it would be interesting to make it public here, because I did try them but I have curious results which don't help me.

EDIT: ok, found some clues in vfpu_ops.h (libpspvgum)

Code:

/*
+----------------------+-------------+----+---------------+---+--------------+
|31                 21 | 20       16 | 15 | 14          8 | 7 | 6          0 |
+----------------------+-------------+----+---------------+---+--------------+
|  opcode 0xd2200000   |  scale[4-1] |    | vfpu_rs[6-0]  |   | vfpu_rd[6-0] |
+----------------------+-------------+----+---------------+---+--------------+

  Float to Int, Truncated

    vf2iz.s %vfpu_rd, %vfpu_rs, scale   ; Truncate and Convert Float to Integer (Single)
    vf2iz.p %vfpu_rd, %vfpu_rs, scale   ; Truncate and Convert Float to Integer (Pair)
    vf2iz.t %vfpu_rd, %vfpu_rs, scale   ; Truncate and Convert Float to Integer (Triple)
    vf2iz.q %vfpu_rd, %vfpu_rs, scale   ; Truncate and Convert Float to Integer (Quad)

        %vfpu_rs:   VFPU Vector Source Register ([s|p|t|q]reg 0..127)
        %vfpu_rd:   VFPU Vector Destination Register ([s|p|t|q]reg 0..127)
        scale:      Multiply by (2^scale) before converting to Float

    vfpu_regs[%vfpu_rd] <- (int) (2^scale * vfpu_regs[%vfpu_rs])
*/
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Sun Oct 01, 2006 2:04 am    Post subject: Reply with quote

hlide wrote:
vi2f.s S000.s,S001.s,1
vf2in.s S000.s,S001.s,1
vf2iz.s S000.s,S001.s,1
vf2iu.s S000.s,S001.s,1
vf2id.s S000.s,S001.s,1

vi2f.* converts 32bit integers to floats, the last argument is a shift (by right afaik)
the vf2iX.* are float to int functions with different rounding methods.
n is nearest (round), (the rest I'm not sure any more, but should be easy to check out) z is trunc, u ceil and d floor. There the last argument is a shift left (done after the conversion I think).
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Sun Oct 01, 2006 2:35 am    Post subject: Reply with quote

Thanx Raphael !

Should I need to convert a 3D vector of fix point (1, 27, 4) to a 3D vector of float for some calculations, do :
Code:

ulv.t   C000, 0(a0)
vi2f.t  C000, C000, 4
... do some calculation with vfpu


Should I need to convert a 3D vector of float to a 3D of fix point (1, 27, 4) f for storing purpose, do :
Code:

... do some calculation with vfpu
vf2iz.t C000, C000, 4
usv.t   C000, 0(a0)


I'm not wrong, Am I ?
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Mon Oct 02, 2006 3:50 am    Post subject: Reply with quote

If you insist to store your vertices as ints (or are forced to), then you'd need to convert them yes, but I wouldn't recommend it. Better store everything as floats and work with them. Also note, that short/char vectors need an extra conversion step with vi2(u)s, vi2(u)c and reverse. Again, avoid those at any cost, it's ugly to work with them (but those conversions could come handy if you convert your internal models to non-float GU vertices for faster rendering).
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Mon Oct 02, 2006 3:58 am    Post subject: Reply with quote

you're right, but as far as I know GTE (coprocessor 2 in PSX) use those kind of storage, so I was planning to use VFPU to emulate GTE.
Back to top
View user's profile Send private message
Raphael



Joined: 17 Jan 2006
Posts: 646
Location: Germany

PostPosted: Mon Oct 02, 2006 4:07 am    Post subject: Reply with quote

hlide wrote:
you're right, but as far as I know GTE (coprocessor 2 in PSX) use those kind of storage, so I was planning to use VFPU to emulate GTE.

Well, emulation is one of the cases were you are forced, so yes :)
_________________
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group