1. Embedding machine code
- Posted by Derek Parnell <ddparnell at bigpond.com> Feb 26, 2004
- 610 views
I wanted to use Juergen's 'bit.e' library for doing 32-bit manipulations because he uses machine code to achieve get over Euphoria's lack of 32-bit integers. However, the code doesn't work because it has lines like this ... SHIFT_LEFT = define_c_func("", SHL_SPACE, {C_INT, C_INT}, C_INT) but that gives the error message ... c:\euphoria\include\dll.e:50 in function define_c_func() type_check failure, lib is {} Any ideas about how I should actually call these machine code routines? What I really need is when I have an atom that exceeds a 32-bit format I want to chop off the excess bits and only keep the low 32 bits. -- Derek
2. Re: Embedding machine code
- Posted by akusaya at gmx.net Feb 26, 2004
- 574 views
If I remember correctly you need to use eu 2.4 to use that... D> I wanted to use Juergen's 'bit.e' library for doing 32-bit manipulations D> because he uses machine code to achieve get over Euphoria's lack of D> 32-bit integers. D> However, the code doesn't work because it has lines like this ... D> SHIFT_LEFT = define_c_func("", SHL_SPACE, {C_INT, C_INT}, C_INT) D> but that gives the error message ... D> c:\euphoria\include\dll.e:50 in function define_c_func() D> type_check failure, lib is {} D> Any ideas about how I should actually call these machine code routines? D> What I really need is when I have an atom that exceeds a 32-bit format I D> want to chop off the excess bits and only keep the low 32 bits.
3. Re: Embedding machine code
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Feb 26, 2004
- 593 views
On Thu, 26 Feb 2004 08:31:20 +0000, Derek Parnell <ddparnell at bigpond.com> wrote: > SHIFT_LEFT = define_c_func("", SHL_SPACE, {C_INT, C_INT}, C_INT) > >but that gives the error message ... > >c:\euphoria\include\dll.e:50 in function define_c_func() >type_check failure, lib is {} > > >Any ideas about how I should actually call these machine code routines? You need to use 2.4. Check that define_c_func in dll.e begins with object lib not atom lib. >What I really need is when I have an atom that exceeds a 32-bit format I >want to chop off the excess bits and only keep the low 32 bits. If speed isn't critical, this might show how, up to a point: include machine.e atom i i=#0FFFFFFF for j=1 to 40 do i=i*2+1 ? i ? int_to_bits(i,32) ? bits_to_int(int_to_bits(i,32)) if getc(0) then end if end for It seems to work up to 54 bits, I guess it depends on where you are getting these atoms from. You may need to change the sign of the result from bits_to_int if it is over 2^31-1. Regards, Pete
4. Re: Embedding machine code
- Posted by "Juergen Luethje" <j.lue at gmx.de> Feb 26, 2004
- 590 views
Derek wrote: > I wanted to use Juergen's 'bit.e' library for doing 32-bit manipulations > because he uses machine code to achieve get over Euphoria's lack of > 32-bit integers. Thanks.> However, the code doesn't work because it has lines like this ... > > > SHIFT_LEFT = define_c_func("", SHL_SPACE, {C_INT, C_INT}, C_INT) > > but that gives the error message ... > > c:\euphoria\include\dll.e:50 in function define_c_func() > type_check failure, lib is {} As others already wrote, 'bit.e' only works with Eu 2.4 or later, sorry.
> Any ideas about how I should actually call these machine code routines? Tommy Carlier wrote some sample code, that does something similar, using the old way to define and call ASM functions: http://www.listfilter.com/cgi-bin/esearch.exu?fromMonth=C&fromYear=8&toMonth=C&toYear=8&postedBy=Tommy+Carlier&keywords=rotate_left > What I really need is when I have an atom that exceeds a 32-bit format I > want to chop off the excess bits and only keep the low 32 bits. Tommy uses poke4() to put the parameters to the machine code. Does poke4() automatically only keep the low 32 bits? I don't know. If you want, I can make a different version of 'bit.e', that also runs on older Euphoria versions. Do you need all 9 functions in 'bit.e', or only some of them? Regards, Juergen
5. Re: Embedding machine code
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Feb 26, 2004
- 726 views
----- Original Message ----- From: "Juergen Luethje" <j.lue at gmx.de> To: <EUforum at topica.com> Subject: Re: Embedding machine code > > > Derek wrote: > > > I wanted to use Juergen's 'bit.e' library for doing 32-bit manipulations > > because he uses machine code to achieve get over Euphoria's lack of > > 32-bit integers. > > Thanks.> > > However, the code doesn't work because it has lines like this ... > > > > > > SHIFT_LEFT = define_c_func("", SHL_SPACE, {C_INT, C_INT}, C_INT) > > > > but that gives the error message ... > > > > c:\euphoria\include\dll.e:50 in function define_c_func() > > type_check failure, lib is {} > > As others already wrote, 'bit.e' only works with Eu 2.4 or later, sorry.
Oooops! I've forgotten to change my 'EUDIR' environment symbol back to point to the 2.4 version. Silly me! I'm trying to implement the TEA (Tiny Encryption Algorithm - http://www.ftp.cl.cam.ac.uk/ftp/papers/djw-rmn/djw-rmn-tea.html ) in Euphoria. This is a very simple algo but it works on packets of 4-bytes using shifts, xors, adds, and mults so I very quickly get bit overflows. I'm wanting to use machine code to improve the speed as I'll be using it for real-time encoding/decoding of traffic over a LAN. -- Derek