[Openmcl-devel] arithmetic primitives
Ron Garret
ron at flownet.com
Sat Apr 18 08:55:21 PDT 2020
You can also use the FFI to call C functions, and you can use the RUN-PROGRAM function to invoke gcc. So you can write a little compiler that translates a Lispy DSL into C, compiles it, and runs the resulting code completely transparently.
rg
On Apr 18, 2020, at 5:34 AM, Bill St. Clair <wws at clozure.com> wrote:
> CCL's optimizers do a pretty good job, if you tell them to:
>
> CL-USER> (defun add (x y)
> (declare (fixnum x y) (optimize (speed 3) (safety 0)))
> (the fixnum (+ x y)))
> ADD
> CL-USER> (disassemble 'add)
> (recover-fn-from-rip) ; [0]
> (pushq (% rbp)) ; [7]
> (movq (% rsp) (% rbp)) ; [8]
> (pushq (% arg_y)) ; [11]
> (pushq (% arg_z)) ; [12]
> (movq (@ -8 (% rbp)) (% arg_y)) ; [13]
> (movq (@ -16 (% rbp)) (% arg_z)) ; [17]
> (addq (% arg_y) (% arg_z)) ; [21]
> (movq (% rbp) (% rsp)) ; [24]
> (popq (% rbp)) ; [27]
> (retq) ; [28]
> NIL
>
> On Sat, Apr 18, 2020 at 6:43 AM Michał "phoe" Herda <phoe at disroot.org> wrote:
> > I would like to use arithmetic primitives (add, mul, sub, div, ..) in
> ccl, is this possible?
>
> Hey!
>
> I assume that you mean using the raw CPU assembly instructions of the
> architecture on which you are. This means that you will not only need
> raw assembly instructions, but you will also need raw machine integers;
> basically writing assembly in CCL.
>
> It's possible to write LAP (short for Lisp Assembly Program) functions
> for Clozure Common Lisp; see
> https://github.com/Clozure/ccl/blob/275105afd94706d95ac955178316074931822c42/level-0/X86/X8632/x8632-numbers.lisp
> for example number-operating functions for x32. I am not aware if there
> any tutorials or documentation for these, though.
>
> ~phoe
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20200418/63b7c0fb/attachment.htm>
More information about the Openmcl-devel
mailing list