Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Packer vs Code VM vs Code Generator
2016-08-13 16:38
oziphantom

Registered: Oct 2014
Posts: 478
Packer vs Code VM vs Code Generator

Has anybody experimented with/know of code VMs or Generators.
Just thinking to get code size down they might perform better than exomiser et al.

I know of Sweet16 by Woz any others?
 
... 80 posts hidden. Click here to view all posts....
 
2016-08-17 18:31
TNT
Account closed

Registered: Oct 2004
Posts: 189
@Krill: did you try separate streams for immediate/low byte operands and high bytes? I found out that high bytes compress better when separated from the low byte.

@soci: no need to add special cases for RTI/RTS - just make preprocessor warn if the following byte (fake operand) is non-zero. Additionally the preprocessor can replace the zero with any other value if that improves compression. JSR needs to be handled separately of course.
2016-08-18 04:53
Krill

Registered: Apr 2002
Posts: 2845
TNT: I don't remember trying that. Also the RTS/RTI padding is a good idea. Certainly something to play around with for the next 4K of mine! :D
2016-08-18 05:00
Krill

Registered: Apr 2002
Posts: 2845
Quoting Oswald
you could just set some flag to tell the irq to stop scheduling the loader in, insead of that supper scifi method? :)
Why is the obvious solution of simply splitting the stack (TSX/TXS exists) the "super sci-fi" method and painstakingly copying it back and forth not? :)
2016-08-18 05:38
JackAsser

Registered: Jun 2002
Posts: 1989
Quote: Quoting Oswald
you could just set some flag to tell the irq to stop scheduling the loader in, insead of that supper scifi method? :)
Why is the obvious solution of simply splitting the stack (TSX/TXS exists) the "super sci-fi" method and painstakingly copying it back and forth not? :)


He was referring to implementing yield vs pause/resume thread
2016-08-18 06:02
Krill

Registered: Apr 2002
Posts: 2845
Ah, thanks. I should not morning-post before the third coffee. :D
2016-08-18 20:23
lft

Registered: Jul 2007
Posts: 369
Quoting soci
From the processor's viewpoint the least significant 5 bits of opcode fully determines the length of the addressing mode.

Still it seems that BRK/JSR/RTI/RTS are exceptions. But that's only because the modification of PC is covering up that they're actually 2 bytes long.

I think if you reduce the table size the result will be shorter even with the special handling added in for these opcodes.


Also remember that this doesn't need to be 100% accurate. It's just a heuristic, and things will work as long as the encoder and the decoder make exactly the same errors. So treating jsr as having a one-byte operand (or brk/rti/rts/ldy#/cpy#/cpx# as having two-byte operands) will throw things out of sync for a while, but the compression ratio might not increase very much, and may even accidentally decrease for some input data. Meanwhile the decoder would be greatly simplified.
2016-08-19 06:20
Krill

Registered: Apr 2002
Posts: 2845
Yes, but i'd try to get things back in sync again as quickly as possible. In an environment where every byte counts, "tainting" the streams by switching their data may (or may not) result in some losses.

And the question would be how often do the streams get in and out of alignment? Surely you want to keep that number low, otherwise the entire exercise is moot.

Now, i really like the idea of padding in zeros for simplified decoding, which may avoid unaligned streams altogether and have no drawbacks in comparison.

But i guess the goal would be to make the op-code lengths as regular as possible, possibly even getting rid of the table altogether in favour of a simple expression, while keeping the streams as well-aligned as possible by padding and/or allowing transient alignment errors only on rare operations (prefer brk/rti/rts/jsr over lda#/cmp#/etc.) with a quick recovery (also via some sort of padding?).
2016-08-19 06:43
Krill

Registered: Apr 2002
Posts: 2845
Oh, and of course, most illegals and also quite a few regular operations aren't used much (or can be replaced), especially in size-constrained productions. This may also have a significant influence on the "regularity" of the instruction lengths.
2016-08-23 06:55
TBH

Registered: Mar 2010
Posts: 20
I've played around with what might be considered code VM systems for the C64, with varying results:

1) Event Management System
The use of Events allows code to be deferred ("fire and forget") within an imperative program design. It's basically a set of tables, pointers and indices tied together with a few routines.

The basic features of such a system are:
* Subscribe To An Event - Add a subroutine address to an Event's list of Handlers.
* Unsubscribe From An Event - Remove a subscription.
* Raise An Event - Notify the Event system that an Event of a certain type occurred.
* Event Manager - (called from main loop) Executes the subscribed Handlers for each raised event in its buffer. Events can be queued and prioritised, eg animation Events handled once every 8 frames.

2) Reactive (Event-Driven) Extended Finite State machine
A state machine compatible with OMG's UML2 specification. Relatively slow, but can handle complex sets of transitions. However, it's probably overkill for most purposes.

3) Decision Table
Similar to a lookup table, but with more features and a routine that (optionally) compiles the data and executes the logic expressed by the data and structure.

A table consists of a set of Rules. Each Rule has a set of Actions that are executed if a set of Conditions are met.

The benefits:
a) Rules are expressed explicity when tabularised, instead of (often) implicitly when in code.
b) No IF-THEN code is required.

Many different tables can exist, but only routine used to execute them. This minimises code and the payoff can be big in a program that needs to evaluate a lot of conditions. Alternatively, a code generator can generate a code representation of the table.

4) Inline Function Parameters
This is simple but useful in that it remains slightly more readable than using a data table outside the code. Implementation can vary, but involve manipulating stack return values. The result is code like this:

; PrintAt routine params: Column, Row, Colour, @-terminated string

JSR PrintAt
.byt 10, 2, LtBlue
.asc "The quick brown fox@"
JSR PrintAt
.byt 10, 3, White
.asc "jumps over the lazy dog.@"
2016-08-23 07:09
lft

Registered: Jul 2007
Posts: 369
I've implemented the Z-machine for C64+REU. Zeugma 1.2
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
tlr
Mason/Unicess
Didi/Laxity
Mike
Bieno/Commodore Plus
void256
Volcano/EXON
MCM/ONSLAUGHT
marty/RADWAR
jmin
Sentinel/Excess/TREX
TheRyk/MYD!
iAN CooG/HVSC
Slaxx/Q/HF/MYD!
Frostbyte/Artline De..
iceout/Avatar/HF
Almighty God/Level 6..
Guests online: 163
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Diskmag Editors
1 Jazzcat  (9.4)
2 Magic  (9.4)
3 hedning  (9.2)
4 Elwix  (9.1)
5 A Life in Hell  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.047 sec.