Re: Questions about Euphoria and ASM/machine

new topic     » goto parent     » topic index » view thread      » older message » newer message
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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu