1. Questions about Euphoria and ASM/machine

Hello,

I've been playing around with the call() function and the mini-assembler stuff from the archive. I've had some great results and have been able to code some graphics functions with speeds way faster than I thought possible. I do however have a few questions that I was hoping someone might be able to help me out with. Forgive me for being overly curious hopefully I'm not too much of a bother. If someone can point me in the right direction I can do my own research, unfortunately I don't know which direction to look at the moment. I'll start with the question I'm pretty sure is the stupidest first:

1) When I call() some machine code that will take a long time lets say it tries to find all the prime numbers from 1 to 1e8 with some inefficient method -- will the processor be unable to do anything else until the code finishes? Or do the mysteries of the Windows OS and threads and the like keep the other tasks on the computer running without me doing anything special.

1a) Does multi-core vs single-core have an affect on this?

1b) If it does lock the processor up, what are the common options for resolving the issue? Having the code "ret" every now and then?

Forgive me for any ignorance or stupidity in the above questions, if those haven't put you off, I have a couple more.

2) Is there an easy-ish way for me to allocate memory from inside the machine code. I understand there are standard libraries that can give me malloc, but I was wondering if I couldn't use whatever euphoria is using. In machine.e the allocate() function calls machine_proc() with a value of 16. Is that something I could trigger from the machine code?

3) Speaking of triggering euphoria functions, could someone point me in the direction of the documentation that might help me unravel the representation of euphoria variable and procedures in memory. (Sorry that last sentence was a handful). This is open information now, right? So how do I go about being inducted into the mysteries?

Thank you for your help in satiating my curiosity, Damien

new topic     » topic index » view message » categorize

2. Re: Questions about Euphoria and ASM/machine

DamienBlack said...

1) When I call() some machine code that will take a long time lets say it tries to find all the prime numbers from 1 to 1e8 with some inefficient method -- will the processor be unable to do anything else until the code finishes? Or do the mysteries of the Windows OS and threads and the like keep the other tasks on the computer running without me doing anything special.

Your app won't be able to do anything, but Windows will still schedule other processes.

DamienBlack said...

1a) Does multi-core vs single-core have an affect on this?

On a multi-cored machine, even with a [single threaded] process that hogs all of one core, the machine should be more responsive in general, since other processes can be scheduled on another core.

DamienBlack said...

1b) If it does lock the processor up, what are the common options for resolving the issue? Having the code "ret" every now and then?

One of the recommended things to do when you have long running code in a GUI app, for instance, is to yield to the OS to process events. This gives the app a chance to process events, such as repainting, which prevents your app from looking like it's locked up. I think it would also give other processes a chance to get more time slices (especially important, perhaps, on a single core machine). Each library probably has a slightly different way of doing this, but in particular, I know that both Win32Lib and wxEuphoria both provide a way to do this.

You could call some thing like sleep to give other processes a chance to run. This should work even for console apps. Note that you can get the raw pointer to a function in a dll by using define_c_var() instead of define_c_func(), so that you could pass that to your machine code to work with.

DamienBlack said...

2) Is there an easy-ish way for me to allocate memory from inside the machine code. I understand there are standard libraries that can give me malloc, but I was wondering if I couldn't use whatever euphoria is using. In machine.e the allocate() function calls machine_proc() with a value of 16. Is that something I could trigger from the machine code?

Under windows, euphoria ultimately uses HeapAlloc, though it may semi-manage memory itself depending on the way euphoria is compiled. If you wanted to do this, you could give a callback to allocate(), and have your machine code call this like a regular C function.

DamienBlack said...

3) Speaking of triggering euphoria functions, could someone point me in the direction of the documentation that might help me unravel the representation of euphoria variable and procedures in memory. (Sorry that last sentence was a handful). This is open information now, right? So how do I go about being inducted into the mysteries?

The best place to look is probably execute.h in the source directory of euphoria. Euphoria integers are simply C-integers, though restricted to a smaller range than a normal 32-bit integer. In particular, here are the structure definitions of sequences and an atoms (that are represented as a double, since atoms can be euphoria integers or doubles) look like:

struct s1 {                        /* a sequence header block */ 
	object_ptr base;               /* pointer to (non-existent) 0th element */ 
	long length;                   /* number of elements */ 
	long ref;                      /* reference count */ 
	long postfill;                 /* number of post-fill objects */ 
}; /* total 16 bytes */ 
 
struct d {                         /* a double precision number */ 
	double dbl;                    /* double precision value */ 
	long ref;                      /* reference count */ 
}; /* total 12 bytes */ 
Note that euphoria shifts pointers to the structs and applies a mask to be able to differentiate an integer from a double from a sequence. See the SEQ_PTR(), DBL_PTR(), MAKE_DBL() and MAKE_SEQ() macros (also in execute.h).

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: Questions about Euphoria and ASM/machine

Thank you Matt, just what I needed :)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu