Author Topic: HACC  (Read 23763 times)

0 Members and 2 Guests are viewing this topic.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
HACC
« Reply #60 on: August 01, 2007, 01:58:00 am »
He seems on vacation, I hardly see him on anymore x.x

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
HACC
« Reply #61 on: August 01, 2007, 12:28:00 pm »
I've thought about this subject a bit and I don't think a C compiler for Z80 would really be practical. The Z80 architecture is badly suited for C (or any other compiled language, really) for several reasons:
  • in C, the normal way to pass arguments to a function is on the stack. On most modern processors, you have a stack-relative addressing mode, so this is fine. Z80 has no easy way to access elements of the stack below the topmost, so the only sensible way to pass things into a function is through registers. But the question of which registers are best to use is dependent on the function itself, and to some extent its callers. C requires standardized calling conventions in order to be able to have separate compilation of multiple source files; a compiler can't generate the code to call an external function if it doesn't know how that function expects its arguments passed.
  • Register allocation on the Z80 is a very complicated problem. On most processors, registers have few if any differences between them - if it works on "R0", it works on "R7". On the Z80, every register has its own special purposes, so deciding what to put where becomes more complicated.
  • When C programmers want an integer, they usually just type "int". This poses a problem for the Z80, since "int" has to be at least 16 bits long. On today's processors, 8-bit, 16-bit, and 32-bit operations are all the same speed, but on the Z80 anything bigger than 8-bit takes up more time and space.
  • Also, in C integer types are signed unless you explicitly say "unsigned". More often than not, it doesn't matter whether a variable is signed or unsigned so programmers just use signed integers to save typing. Unsigned comparisons can be done easily on the Z80 (just use the carry flag), but signed comparisons require that the sign flag and parity/overflow flag be XORed together. Modern processors have conditional jump instructions that do just that; the Z80 doesn't.
I strongly doubt that a C compiler could ever produce Z80 code anywhere near as well as a person writing assembly could. As a result, C games would require a lot more memory, which is in short supply on the Z8-based calculators.
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
HACC
« Reply #62 on: August 01, 2007, 12:29:00 pm »
I see, this means we are stuck with BASIC and ASM then, right?

Offline Goplat

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 289
  • Rating: +82/-0
    • View Profile
HACC
« Reply #63 on: August 01, 2007, 12:54:00 pm »
If you don't want programs that take up more space than they have to, that's probably a good idea.
Numquam te deseram; numquam te deficiam; numquam circa curram et te desolabo
Numquam te plorare faciam; numquam valedicam; numquam mendacium dicam et te vulnerabo

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
HACC
« Reply #64 on: August 01, 2007, 01:03:00 pm »
Well, BASIC is huge, and slow, but if it's gonna take more space with C its better to stay with BASIC or asm. And BASIC is pretty nice for creating RPGs and if you're good other types of games as well. Then if you want speed and even smaller size assembly solve the issue, altough it's much harder to startup with

Offline Halifax

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1334
  • Rating: +2/-1
    • View Profile
    • TI-Freakware
HACC
« Reply #65 on: August 01, 2007, 04:31:00 pm »
Goplat: Believe I have been working on this for some time now and  I have already thought about everything you just said right there.

Let me address some things.

1. z8-GCC has still been in effect and is still being worked on, but it is not z8-GCC anymore because we are not using GCC.

2. C will most obviously not be as efficient as hand-written assembly, but it will provide smaller size than BASIC and much faster speed than BASIC

3. Let me answer you questions up there

Well first off I should address this by saying my development team and I are making a C compiler from the ground up which will support 68K and z80 as the first targets. It will be target-expandable meaning that the compiler will produce programs for any processor that you want to target it to through writing a backend.

Now let me talk about the problems that you have posed above.

1st problem: Calling conventions: There are numerous ways to pass arguments on the z80. Registers, stack, memory. These can be user defined or they can be chosen by the compiler. Secondly I don't think you know this but the z80 in effect actually has  14 8bit registers or 8 16bit registers.

8bit: a,b,c,d,e,h,l,a',b',c',d',e',h',l'
16bit: bc,de,hl,bc',de',hl',ix,iy

Now also another thing which you may or may not know is that ix, and iy can be used in almost every place that hl can be used which gives you 4 general purpose 16bit registers. So that is more than enough to pass parameters to functions as long as you do it smartly.

2nd problem: Register allocation: Basically what you just said is that is going to be more work for me. Well I don't care because I have been turning this over in my head and have came up with some very good algorithms.

3rd problem: Types: int defaults to short. Can you have a long int? Of course. Can you have a long long int? Of course. No need to worry there. It may take more time, but I see assembly programmers using them all the time. Remember it doesn't take that much more time. Maybe 2-4 cycles which isn't that much. You have 6 million cycles in a second on the z80 and 15 million possible on a z80 in the silver edition.

4th problem: Types: I still see no problem. What you are saying is all possible so I really don't see the point in that statement?

Now let me just say. Of course it will be more work to write a z80 target for our C compiler, but it will NOT make over-bloated or even close to unneeded bloating code. It will be aware that register to register loads are faster than constant or memory loads and that will make an effect. SSA trees will be used for other various optimizations internally in our compiler. Final pass peephole optimizations will also be made like the call-ret optimization.

Also remember that programmers will be allow to write there own assembly functions for their programs too.

Trust me Goplat. Anything you can throw at me has already been thought of. I would not continue with this project if it was not possible.

Oh and about that using more memory than it should?? That will not be a problem as programmers will have the option to use bcall()'s over the hand-written z80 assembly C functions provided in the Standard libraries if they truly need it.

One thing I can guarantee you is that the C games will not be as big as their BASIC counterparts and will most be much faster.
There are 10 types of people in this world-- those that can read binary, and those that can't.

Offline Halifax

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1334
  • Rating: +2/-1
    • View Profile
    • TI-Freakware
HACC
« Reply #66 on: August 31, 2007, 01:26:00 pm »
Alright well I kind of have 2 updates. One doesn't matter and another is a major advancement.

First announcement: The name of the compiler is now HACC(Halfiax's C Compiler). Haha I am so original ;)wink.gif . The name isn't final though exactly.

Second announcement: The major advancement that is one of the key driving forces behind parsing C code, and the technology behind all the internal data types in HACC is nearing the end of the development process. Generic Trees are finally shaping up. Some key things of what it can do now.

* Build a full tree containing any number of nodes that can be contained in memory
* Inserting triplets right into a leaf node
* Deleting triplets right from a branch node
* Obtaining triplets from any place in the tree
* Resolving triplets through a callback built by the programmer

Things to implement:

* Any number of child members to one parent
* Resolving variable child members
* Recursive resolving of the tree from custom resolution callback list

After the things to implement are implemented, then we can begin to build the trees needed on top of that.

Just for fun I recorded a quick little debug session of a small small tree :Ptongue.gif

c1-->
CODE
ec1
Tree created successfully
 
There are 10 types of people in this world-- those that can read binary, and those that can't.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
HACC
« Reply #67 on: August 31, 2007, 01:40:00 pm »
THis is awesome to see this revived, I noticed the new name as well in the title. I can't wait to make a game using this :Dbiggrin.gif, will they require a shell like mirage or ion to run? And what are "node"s?

Offline Ranman

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1354
  • Rating: +83/-0
    • View Profile
HACC
« Reply #68 on: August 31, 2007, 02:01:00 pm »
If you define some rules and/or limitations (something like Small C), then your C compiler implementation complexity will decrease substantially. ;)wink.gif

Now... what are those darned rules/limitations? :gah:fou.gif
Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator. Download available at Ticalc.

Offline Halifax

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1334
  • Rating: +2/-1
    • View Profile
    • TI-Freakware
HACC
« Reply #69 on: August 31, 2007, 02:32:00 pm »
Nah I don't think I am going to take out anything really from the C language, except maybe from the preprocessor. I mean with three developers working on this, things are starting to go smoothly at least. :)smile.gif

And also this project was never really dead. We have been working on it all along.

Also DJ_Omnimaga a node is a piece of a tree. It is just technical jargon that is used to describe trees.
There are 10 types of people in this world-- those that can read binary, and those that can't.

Offline Ranman

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1354
  • Rating: +83/-0
    • View Profile
HACC
« Reply #70 on: August 31, 2007, 02:46:00 pm »
QuoteBegin-Halifax+31 Aug, 2007, 20:32-->
QUOTE (Halifax @ 31 Aug, 2007, 20:32)
Nah I don't think I am going to take out anything really from the C language, except maybe from the preprocessor.

Actually, I was thinking about limiting things for the Z80 implementation such as:

- floats & double floats
- variable number of arguments (ex. printf() )
- possibly consider leaving out 32 bit integers
Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator. Download available at Ticalc.

Offline Halifax

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1334
  • Rating: +2/-1
    • View Profile
    • TI-Freakware
HACC
« Reply #71 on: August 31, 2007, 02:51:00 pm »
Hmm you know I was considering leaving out 32 bit integer, but I thought it would be so fun to see what people come up with even though they are slow. Sigma made a whole slew of 32 bit manipulation routines so I was going to just throw them in there.

Oh, but yes, that is one thing I was tossing around. I think I am just going to leave floats out for now, personally because I doubt people would use them and they are just too much to manage.

Oh yeah and variable arguments are allowed up until 16 arguments which is only 64 bytes at most on the stack. I really have never seen anything over 16, but it will report an error when a variable argument recieves anything above 16 arguments.
There are 10 types of people in this world-- those that can read binary, and those that can't.

Offline Ranman

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1354
  • Rating: +83/-0
    • View Profile
HACC
« Reply #72 on: August 31, 2007, 03:07:00 pm »
You could also leave out the following C commands:

- do/while (redundant with 'for' loops)
- switch/case (redundant with 'if/else')
- goto (bad programming practice)


The following C types are not absolutely necessary either:

- register (you probably don't have enough registers to spare)
- auto (I have never even seen this used)
- union
- const
- and bitfields (redundant with shifting & masking)
Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator. Download available at Ticalc.

Offline Halifax

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1334
  • Rating: +2/-1
    • View Profile
    • TI-Freakware
HACC
« Reply #73 on: August 31, 2007, 03:16:00 pm »
Woah woah, now you are talking about killing the face of C, and breaking a bunch of source trees. I agree with getting rid of auto. I agree with taking away bitfields. I don't agree with taking away do/while switch/case or goto. Goto can give you serious optimizations.

E.G.

case 1:
... do something ...
store to huge struct
case 2:
... do something else ...
store to huge struct

can be optimized to

case 1:
... do something ...
goto store
case 2:
... do something ...
store:

That saves a bunch of memory, because I guarantee you that HACC won't be looking to optimize that, nor does GCC I think.

Also I am keeping register because it can make a difference if the register is taken, which will be kept track of.

And 'const' does affect what happens. 'char' is stored in RAM while a 'const' is stored in the program since it is always constant.

Yeah I think I am going to take unions out. I agree with that.
There are 10 types of people in this world-- those that can read binary, and those that can't.

Offline Ranman

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1354
  • Rating: +83/-0
    • View Profile
HACC
« Reply #74 on: August 31, 2007, 03:31:00 pm »
QuoteBegin-Halifax+31 Aug, 2007, 21:16-->
QUOTE (Halifax @ 31 Aug, 2007, 21:16)
Woah woah, now you are talking about killing the face of C, and breaking a bunch of source trees.

Okay... I agree with you on 'const'. :Ptongue.gif But, a compiler could be designed to treat program constants as "implied" constants.

I agree with your point on 'goto' as well, but then you will have to implement labels -- which is something else that could be left out. :Ptongue.gif

But I'm not killing the face of C... because I prefaced my statements by saying you could implement a "Small C" -- suggesting a subset of C. Removing everything I stated will still compile with a standard C compiler -- while reducing complexity of the compiler. ;)wink.gif


These are just suggestions... take them for what they are worth. :)smile.gif


I always thought it would be cool to have a complete programming language as minimal as possible. C is pretty close to that, but it still has a few redundant and unnecessary things. :)smile.gif
Ranman
Bringing Randy Glover's Jumpman to the TI-89 calculator. Download available at Ticalc.