Total Format - Total Entertainment
 
 

Go Back   Total Format Forum > Computing Forums > Coding, Design & Graphics

Coding, Design & Graphics If you are programming a script, designing a web page, building your own graphics or anything related and need to discuss it, get help and tips or general advice, then you should post your thoughts to this section.

Reply
 
LinkBack Thread Tools Display Modes
Old 25-10-2009, 00:54   #1 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,206
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,781.01
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Cat converting p-code into machine code

oh, erm, yeah, so how do I do convert p-code into machine code ?

I generate the p-code which is generated from c# type source code. the actual language is TNBL (the next big language)

p-code is pseudo code, its like in between source code and machine code. consisting of the most basic operations which most closely reflect the source code.

the target for the machine code could be 386 or 8 bit micro controller - (which is seriously limited)

I'm thinking like, put into an object all the logic of what each opcode does, into a big list, in a way so it can be compared to a desired p-code operation. Some complex opcodes might consist of several p-code operations.

then cycle through all the opcodes until it can match all the p-code operations. but I'm thinking this might take some time to execute. the x86 has a ludicrous amount of possible variations of opcodes too.

of course register assignments and temporary variables complicates things even more.

tricky really,,,
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Toolsmeow is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 25-10-2009, 10:34   #2 (permalink)
Name, Title, Location Allanon
Meatbag

Malton
England
AvatarAllanon's Avatar
Mood
Posts961
Karma Allanon is an experienced TFer.
Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.Allanon is an experienced TFer.
Pu7,701.28
Default

I take it this is some sort of standardised pseudo code that you are generating?

But yes, indexing all the pseudo code statements and converting it into machine code using some sort of lookup table seems like a good approach.
Allanon's Sig:

When A man lies, he murders some part of the world. These are the pale deaths by which men miscall their lives. All this I cannot bear to witness any longer, cannot the kingdom of salvation, take me home?
ToolsAllanon is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 25-10-2009, 14:26   #3 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,206
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,781.01
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

cool thanks.

the pseudo code isn't really standardised, its just what ever comes out of the parser ATM.
there are a number of systems that use an intermediate code, but basically i don't think there can be a great deal of difference fundamentally. the code used by the .net CLI framework might be a good starting point. although rather complex. I think UNIX/gnu use a different system, and not to confuse Microsoft "p-code" which is just an object file format for relocatable code rather than pseudo code. lisp and others also have a distinct p-code format, with some using more than one software stack.

I read up a bit on doing this but it seems any approach to convert p-code to machine code from a specification of the CPU instructions has failed. but then again I also read the same about an LL(k) parser but I wrote one last month or so, although strictly its a decision tree based parser which is neither LL or LR.

the problem might be that although the p code references indexed variables and the CPU opcodes could be produced so that the registers they access etc are represented in p-code as indexes too, but to match these up in a lookup operation would require an almost infinite combination of possible alternatives for each opcode to appear in the table.

I'm thinking that if each individual source p-code statement is adjusted so that all the indexes it uses are consecutively numbered from zero it might be a good start, then just adjust them to point to the correct ones after.

ofc the source p-code indexes refer to variables in memory, rather than registers. the CPU opcodes refer to variables/memory either directly or though a total of 8 addressing modes for 386 which makes it difficult to match up instructions which would be most efficient. I was reading the early CPUs had 20 or more addressing modes, with a possible infinite number of combinations for architectures which had an indirection bit in the memory itself.

selecting variables to promote to registers is obviously a critical step.

one way might be to create by hand various conversions to machine code for as many types of typical statements as possible.
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Toolsmeow is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 25-10-2009, 16:49   #4 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,206
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,781.01
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

lets take as an example the very first mnemonic of 386 assembler is AAA - (surprised its not aardvark ?)

AAA -- ASCII Adjust after Addition
Opcode Instruction Clocks Description

37 AAA 4 ASCII adjust AL after addition

Operation
IF ((AL AND 0FH) > 9) OR (AF = 1)
THEN
AL := (AL + 6) AND 0FH;
AH := AH + 1;
AF := 1;
CF := 1;
ELSE
CF := 0;
AF := 0;
FI;
Description
Execute AAA only following an ADD instruction that leaves a byte result in the AL register. The lower nibbles of the operands of the ADD instruction should be in the range 0 through 9 (BCD digits). In this case, AAA adjusts AL to contain the correct decimal digit result. If the addition produced a decimal carry, the AH register is incremented, and the carry and auxiliary carry flags are set to 1. If there was no decimal carry, the carry and auxiliary flags are set to 0 and AH is unchanged. In either case, AL is left with its top nibble set to 0. To convert AL to an ASCII result, follow the AAA instruction with OR AL, 30H.
Flags Affected
AF and CF as described above; OF, SF, ZF, and PF are undefined


this is actually surprising to find this level of detail about its operation with pseudo code.
If you wanted to do this operation in a high level language such as c it would be a shame not to use this instruction without having to use inline assembler or native/embedded functions etc.

but it is unlikely to be a very close match to whatever one would write to achieve this.
some of the operations above would likely not fit at all but they would not actually matter.

I think the obvious problem is one of execution time to explore all the necessary permutations.

there are many more complications too, like doing 32 bit maths if you only have 16 bit CPU, (or 8 bit !) where you have to string together a whole load of operations, clearly this method cant be achieved with a simple lookup table.

maybe the best fitting CPU operation could be found which only does some of the bits and the remaining operations needed to calculate the remaining bits are reinterpreted into p-code and the process repeated.

most compilers call functions to do oversized arithmetic, but this can be quite inefficient, especially if not all the result is used, such as multiplying 2 x 16 bit numbers to give a 32 bit result but then just using the top 16 bits.

with a small micro controller its important to get the best optimisation as ram and code size is severely limited which means no high level languages seem to exist for them.

PS: this seems to sum up the problem, but unfortunately says little about how to do it.
http://en.wikipedia.org/wiki/Instruction_selection

PPS: seems what I idealy need is a "BURS" system,,,

Last edited by meow; 25-10-2009 at 17:46..
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Toolsmeow is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 29-10-2009, 13:07   #5 (permalink)
Name, Title, Location Ixpah
Full Member

Nottingham, UK
England
AvatarIxpah's Avatar
Mood
Posts335
Karma Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.
Pu8,097.30
Default

Are you actually looking for an optimal solution? e.g. an optimising compiler. Or will anything just do.

I'm guessing with all these multi-core/threaded processors around the obvious thing is to introduce parallelism into the process on a per function basis. I would seem to be a tricky task to get more than 1 thread to work on the same function though unless it could be pipelined in some way.
Ixpah's Sig:Check out my forums @ zints.co.uk or My Blog
ToolsIxpah is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 29-10-2009, 16:01   #6 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,206
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,781.01
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

well, it needs to be moderately good to start with, the idea is to improve it as and when ,,,

it would certainly need to be some sort of optimised result, if you have code generated from a CPU instruction set definition then this is unavoidable.

I'm currently thinking to wards a decision based tree approach, and in some ways it seems slightly easier than I first thought, rather than scan all the possible CPU instructions, it is only necessary to scan small subsets which can be selected depending on major type, eg add etc.

to simplify things further, the addressing modes of the x86 can be thought of as a separate fetch/store (virtual) instruction, which is looked up in the same way, but gets swallowed up if the opcode allows it or gets implemented by other instructions.

at the function level the chance to do any major optimisation like multi threading is rather limited, often all that can be done is things like loops rolled out and assigned different threads if possible.

I would particularly like to implement SSE instructions automatically, this is something which i heard was impracticable. as for shader code too ,,,


at the other end of the scale my 8 bit micro-controller has one register, and 256 bytes of ram, and a handful of instructions. it has no indirect addressing mode, so no instruction to make use of a pointer.

however it does have some complicated stuff to get round limitations, such as writing an address to a hardware register allows access to that ram address from another hardware register, so gets round the lack of pointers.
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Toolsmeow is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 30-10-2009, 12:02   #7 (permalink)
Name, Title, Location Ixpah
Full Member

Nottingham, UK
England
AvatarIxpah's Avatar
Mood
Posts335
Karma Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.Ixpah is a competent TFer.
Pu8,097.30
Default

When I said multi-threading I was referring to the compiler not the output it produces. If 16+ cores is the future then it would help if the compiler itself can actually utilise all these cores to compile the program.
Ixpah's Sig:Check out my forums @ zints.co.uk or My Blog
ToolsIxpah is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 30-10-2009, 12:20   #8 (permalink)
Name, Title, Location Detomah
Owner&Designer

Total Format HQ
United Kingdom
AvatarDetomah's Avatar
Mood
Posts22,900
Karma Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.
Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.Detomah is a superior being.
Pu129,886.77
Critters
Blog
Blog Entries: 2
Awards
TF Activity Award - Silver TF Activity Award - Bronze TF Gaming Award - Silver TF Top Poster Bronze TF Top Poster - Silver TF Top Poster - Gold 
Total Awards: 6
Sunderland AFC Dog 2 Pie Treasure Single Red Rose England
Default

Quote:
Originally Posted by Ixpah View Post
If 16+ cores is the future.
Don't want to hijack the thread, just wanted to say... OMG... 16 cores, hell until buying Win7, my quad core wasn't even utilised on WinXP, surely we are still a good few years away from utilisation of anything like that, right? Or am I thinking something different completely and being thick? This thread kind of wooshed with me a bit, I really need to keep away from threads with anything to do with C#, I know bugger all about it.
Detomah's Sig:
Donations - Help Total Format, by kindly donating your spare cash.
Site Map - See exactly what Total format has to offer during your stay.
TV Guide - check out what is on TV right here at Total Format.
Cartoons - Read the latest comics that Total Format has to offer.
Search | BBCodes | Smilies | FAQs | Forum Rules | Contact TF | Link To TF | Privacy Policy
Follow Total Format on Twitter HERE
ToolsDetomah is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 30-10-2009, 15:18   #9 (permalink)
Name, Title, Location meow
Kissed all the girls

The twighlight zone
Maldives
Avatarmeow's Avatar
Mood
Posts3,206
Karma meow is amazing.
meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.meow is amazing.
Pu6,781.01
Awards
TF Top Poster Bronze 
Total Awards: 1
Cat 3 Gift Box Medal Single Red Rose Flowers Cake French Fries litebeer Subway Apple Heart Love Hearts Cash Love Hearts Tissues

Default

I dont think its worth thinking about multithreading for compiling one file, the usual thing is to compile files on seperate processors, this would give the most utilisation. gfx cards already havve 256 cores, and nvidea are selling special gfx cards which you can use all 256 for general purpose supercomputing in your pc.
meow's Sig:"Some people see things as they are and ask `Why?'. I dream of things that never were and ask `Why not?'. "
"science without religion is lame, religion without science is blind"
Toolsmeow is offline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links

Reply

Tags
code, converting, machine, pcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sci-Fi TV and Movie Reference List Detomah Science Fiction Corner 2 14-10-2009 18:04
Dixons - Top Offers and discount code Detomah Shopping Offers 0 25-03-2009 14:54
Home and Garden Gifts Latest Discount Codes Detomah Shopping Offers 0 05-03-2009 21:06
Latest discount codes from Dixon's! Detomah Shopping Offers 0 14-02-2008 17:29
Honour For Cracking Colossus Code Cryptoghrapher Detomah Computer, Web & Tech News 0 29-01-2008 02:22

 
 
Archive - RSS Feeds - About Us - Privacy - Terms of Use - Site Map - Advertising - Link To TF - Contact Us - Top
Content Relevant URLs by vBSEO 3.2.0 RC5 Copyright ©2003 - 2000, Total Format. Forums powered by vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Limited.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385