DCEmulation

dreamcast development • homebrew software • hardware hacking • indie games • emulators • and more!
Back to main site
It is currently Wed Dec 17, 2014 7:21 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat Dec 24, 2011 8:10 am 
Offline
DCEmu Freak
DCEmu Freak

Joined: Sun Apr 10, 2011 10:05 am
Posts: 65
I've been researching more and more about Processors and x86 Assembly.

I've had a hard time finding decent resources and general information on the SH4 (or SuperH) CPU however from what I can find it's optimized for vector and matrix calculations. Actually reserving instructions and registers. I believe AMD's 3DNow takes a similar approach.

So I'm wondering, to what extent to the KOS utilize this functionality?
And is this what's actually going on? Like registers and instructions being reserved or am I just completely deluded? :lol:

Also, if anyone knows a decent Sh4 assembler, or any good resources on this CPU then I'd very much appreciate it! :grin:


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 9:03 am 
Offline
Mental DCEmu
Mental DCEmu
User avatar

Joined: Wed Mar 30, 2011 10:13 am
Posts: 314
1.Marcus Site. http://mc.pp.se/dc/cpu.html
Look at this page you found there everything that you need (programming and hardware manual covers almost everything. after reading it you can even develop your own board on which you can set sh4 processor).

2. About registers and etc. KOS using libkallisti.a as a main source of raw machine code. So you can look through this file, or even push it to the disassembler\debugger, and run for the step tracing, to see, what is actually happens with registers, memory, and etc. The one problem that I didn't find one on the net (I mean debugger). One had nullDC but I didn't found it good. there's still gdb debugger, and IDA, but IDa sucks with dreamcast code, so...


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 9:08 am 
Offline
DCEmu Freak
DCEmu Freak

Joined: Sun Apr 10, 2011 10:05 am
Posts: 65
RyoDC wrote:
Marcus Site. http://mc.pp.se/dc/cpu.html
Look at this page you found there everything that you need (programming and hardware manual covers almost everything. after reading it you can even develop your own board on which you can set sh4 processor).

Thanks much! That one link is like an encyclopedia! :o


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 9:13 am 
Offline
Mental DCEmu
Mental DCEmu
User avatar

Joined: Wed Mar 30, 2011 10:13 am
Posts: 314
Np man. Always ready to help.

_________________
How do I try to build a Dreamcast toolchain:
Image


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 10:14 am 
Offline
DCEmu Freak
DCEmu Freak

Joined: Sun Apr 10, 2011 10:05 am
Posts: 65
I'm still stuck on an Assembler though, Hitachi's site seems long gone. I'm guessing you'd have to write your own -gulp- :(

So if anyone has any info on that, much appreciated again! :grin:

EDIT:
I just had a thought, the KOS development kit comes with GCC ready to compile straight out the box. Does this mean I've had an assembler all this time?


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 10:24 am 
Offline
Mental DCEmu
Mental DCEmu
User avatar

Joined: Wed Mar 30, 2011 10:13 am
Posts: 314
So you need an assembler?
Well, Hitachi site is not gone, but Hitachi, as a manufacturer of semiconductor devices, yes, it have. Now it's Renesas company. Anyway. Aboutt GCC.
Use this link.
http://www.delorie.com/djgpp/v2faq/faq8_20.html

_________________
How do I try to build a Dreamcast toolchain:
Image


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 10:40 am 
Offline
Insane DCEmu
Insane DCEmu

Joined: Thu Apr 03, 2008 5:01 am
Posts: 130
GCC (actually Binutils) provides an assembler. Just compile your .s file with kos-cc.


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 10:48 am 
Offline
DC Developer
DC Developer

Joined: Thu Aug 20, 2009 9:00 am
Posts: 324
Ayla wrote:
GCC (actually Binutils) provides an assembler. Just compile your .s file with kos-cc.


For those not familiar with gcc and assembly: A ".s" extension means the file gets passed directly to the assembler and must contain nothing but assembler friendly syntax. A ".S" extension (note that the s is capitalized) means the file is passed through the C preprocessor first before being sent to the assembler, so the file can have C friendly syntax for things like enum and define for stuff you'll use. So a .s file would have ".equ some_symbol, 1" while a .S file can have "#define some_symbol 1".


Top
 Profile  
 
PostPosted: Sat Dec 24, 2011 11:04 am 
Offline
DCEmu Freak
DCEmu Freak

Joined: Sun Apr 10, 2011 10:05 am
Posts: 65
Well awesome!
You've all been a *huge* help. I'll see what I can come up with! :grin:


Top
 Profile  
 
PostPosted: Wed Jan 04, 2012 3:22 pm 
Offline
DCEmu Freak
DCEmu Freak

Joined: Sun Apr 10, 2011 10:05 am
Posts: 65
Okay, after looking further into the links provided (thanks again!), The Sh4 CPU does indeed have opcodes/registers for optimizing vector calcualtions. Which is awesome, but before I start screwing around with this, I've got a few questions about the KOS's PVR API. Sorry if any of these are obvious/idiotic.

The actual PVR headers are located under kernel/arch/pvr?
Also, is there any assembly involved with the PVR API? If so, where are these files in the KOS repo?
And, one other question... Does the PVR API take advantage of this?
I know I already asked this question, but I probably shouldn't be attempting to implement functionality that already exists.

Thanks!


Top
 Profile  
 
PostPosted: Wed Jan 04, 2012 3:49 pm 
Offline
DC Developer
DC Developer

Joined: Thu Aug 20, 2009 9:00 am
Posts: 324
Just doing

Code:
#include <kos.h>


At the start of the file will take care of any pvr includes needed. Look at the examples in

kos/examples/dreamcast/pvr


Top
 Profile  
 
PostPosted: Wed Jan 04, 2012 3:55 pm 
Offline
The Crabby Overlord
The Crabby Overlord
User avatar

Joined: Mon May 27, 2002 9:31 am
Posts: 4349
The main include file for the PVR is kos/kernel/arch/dreamcast/include/dc/pvr.h (documentation). Note that this particular interface assumes that any 3D-related transformations you want done on the primitives are already done before feeding them in. It simply takes the data and feeds it directly to the hardware.

You may also be interested in kos/kernel/arch/dreamcast/include/dc/matrix.h (documentation) and kos/kernel/arch/dreamcast/include/dc/matrix3d.h (documentation), as they are the headers related to any matrix-type stuff that is in KOS proper. The 2ndmix example shows how to use some of that stuff, IIRC.


Top
 Profile  
 
PostPosted: Fri Jan 06, 2012 2:22 pm 
Offline
Mental DCEmu
Mental DCEmu
User avatar

Joined: Wed Mar 30, 2011 10:13 am
Posts: 314
Crab, one question. As far as i concerned, PowerVR chip doesn't support hardware lightning, I mean (besides of shading modes), light sources. So, that mean, that I can use my custom lightning algorithms for different types of surfaces, isn't it?

_________________
How do I try to build a Dreamcast toolchain:
Image


Top
 Profile  
 
PostPosted: Fri Jan 06, 2012 4:06 pm 
Offline
The Crabby Overlord
The Crabby Overlord
User avatar

Joined: Mon May 27, 2002 9:31 am
Posts: 4349
There is no hardware on the PVR to do lighting. You're responsible for calculating any lighting effects yourself and modifying what's sent to the PVR appropriately (mostly by changing the vertex colors to account for the light).


Top
 Profile  
 
PostPosted: Sat Jan 07, 2012 9:04 am 
Offline
Mental DCEmu
Mental DCEmu
User avatar

Joined: Wed Mar 30, 2011 10:13 am
Posts: 314
Crab, how do I use the bump mapping?

_________________
How do I try to build a Dreamcast toolchain:
Image


Top
 Profile  
 
PostPosted: Sat Jan 07, 2012 10:01 am 
Offline
The Crabby Overlord
The Crabby Overlord
User avatar

Joined: Mon May 27, 2002 9:31 am
Posts: 4349
Search is your friend. Here's a post with links to an example of how to do it: viewtopic.php?p=816595#p816595


Top
 Profile  
 
PostPosted: Sat Jan 21, 2012 1:27 pm 
Offline
DCEmu Freak
DCEmu Freak

Joined: Sun Apr 10, 2011 10:05 am
Posts: 65
Sorry for reviving such an old thread, I just really didn't want to make another considering it's a question related to the adventure started in this thread :lol:

I know the KOS has this stuff implemented already, I think it's in "kernel/arch/dreamcast/include/dc/math.h"?

Either way, for learning purposes I've been trying to utilize the SH4's vector functionality.

I took a look a the KOS's fmath.h header, which seems to inline assembly optimizations for shitton of stuff. For example, faster square roots, vector products, matrix multiplication etc.

Anywhoo, enough blabbering lol.
The KOS has this macro here:
Code:
#define __fipr(x, y, z, w, a, b, c, d) ({ \
   register float __x __asm__("fr0") = (x); \
   register float __y __asm__("fr1") = (y); \
   register float __z __asm__("fr2") = (z); \
   register float __w __asm__("fr3") = (w); \
   register float __a __asm__("fr4") = (a); \
   register float __b __asm__("fr5") = (b); \
   register float __c __asm__("fr6") = (c); \
   register float __d __asm__("fr7") = (d); \
   __asm__ __volatile__( \
      "fipr   fv4,fv0" \
      : "+f" (__w) \
      : "f" (__x), "f" (__y), "f" (__z), "f" (__w), \
        "f" (__a), "f" (__b), "f" (__c), "f" (__d) \
      ); \
      __w; })


Which clearly calculates the inner product of a 4D vector. But I'm very confused as to exactly how this works.

The constraints passed to GCC just say throw it into a floating point register, but they would need to be in a ordered fashion for the results to be accurate. Which leads me to believe that the values are being placed into the FR registers when they're declared like this:
Code:
register float __x __asm__("fr0") = (x); \


But looking into the "register" keyword, GCC can never promise they will actually be stored in a register.

Sorry if I've been too vague, I'm just quite confused. This is more of a question about GCC, but this seems quite different to any x86 inlined assembly I've seen.

EDIT: Just correct a few things...

Thanks!


Top
 Profile  
 
PostPosted: Sat Jan 21, 2012 1:53 pm 
Offline
Insane DCEmu
Insane DCEmu

Joined: Thu Apr 03, 2008 5:01 am
Posts: 130
The "register" keyword tells GCC that the associated variable should always be kept in a register and not on memory.

The following code simply associate the __x float variable with the fr0 register.
Code:
register float __x __asm__("fr0")


Now each time you do __x = 4 on your C/C++ code, the value 4 will be stored on the fr0 register, and not on memory or on any other register.


Top
 Profile  
 
PostPosted: Sat Jan 21, 2012 2:05 pm 
Offline
DCEmu User with No Life
DCEmu User with No Life

Joined: Sat Feb 16, 2002 12:55 pm
Posts: 3641
I think the way it works is that GCC guarantees the mapping when those variables are referenced by name as operands in an asm block. However, the mapping is not necessarily maintained beyond that (e.g. the variables might "really" live in memory and are just copied in/out of the specified registers by code generated around the asm block). AFAIK, the "register" keyword is not actually guaranteed to do anything in ANSI C generally, but sadly my copy of K&R is in my cube at the moment.

edit: it might be guaranteed to generate an error if the & operator is used on a register variable, but I don't know whether that's required or the compiler can implicitly convert it to a memory variable.

_________________
"You know, I have a great, wonderful, really original method of teaching antitrust law, and it kept 80 percent of the students awake. They learned things. It was fabulous." -- Justice Stephen Breyer


Last edited by Ex-Cyber on Sat Jan 21, 2012 2:20 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sat Jan 21, 2012 2:16 pm 
Offline
DCEmu Freak
DCEmu Freak

Joined: Sun Apr 10, 2011 10:05 am
Posts: 65
Ah, seems to make sense.

So really, even though it's not in that register, any inlined code can treat it as if it really is?

But then, why does the inline constraints have to directly specify the input operands? :?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group