[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Syncing caches
From: |
Rob Landley |
Subject: |
Re: [Tinycc-devel] Syncing caches |
Date: |
Mon, 11 Nov 2002 22:07:24 +0000 |
User-agent: |
KMail/1.4.3 |
On Monday 11 November 2002 20:14, Jim Peters wrote:
> Thanks for the work on TinyCC -- it has moved on a long way since I
> last looked at it, now being able to output object files too.
>
> Inspired by this style of code generation, I'm thinking of using
> something similar to generate fast custom digital filters routines at
> run-time for a filter library I'm writing. I know I could use libtcc,
> but inspired by the code-generation of tcc, I think that my filter
> code is simple enough to be written straight out without going via C
> or libtcc.
>
> The only concern I have is about processor caches. I remember a long
> long time ago (Z80/6502/68000) when it was okay to write self-
> modifying code, but then caches came along and it was no longer okay,
> because the instruction cache could get out of sync. Does this still
> apply?
On x86 at least, yes it does. It's an erratum, meaning it'll bite you very
intermittently, differently on different processors, and you'll have a heck
of a time tracking it down (if you ever do).
> I looked through the code, and I couldn't find any OS call to
> synchronize caches or anything like that. Is it okay to just write
> code to memory and then call it?
Lots of people use interpreted bytecode. Python, Java, dot-nyet... It turns
out to be faster than you'd think because it's 8 bit code and a surprising
amount of it fits in cache (along with your entire interpreter most times),
which is your real bottleneck. (Stop and think: people are writing action
games in perl. Modern computers are FAST.)
A dirt simple way to fake up some bytecode is an array of function pointers
with a loop calling elements out of the array. Something vaguely like (ooh,
it's been years, I'm going to get the array of function pointer syntax
wrong):
*(int blah[])(args) = {func1, func2, func3...};
for (;;) blah[data[position++]](args);
Or have position be a pointer to save one level of indirection...
Rob
(That might be *(int blah)(args)[], try it and see...)
--
http://penguicon.sf.net - Terry Pratchett, Eric Raymond, Pete Abrams, Illiad,
CmdrTaco, liquid nitrogen ice cream, and caffienated jello. Well why not?