[Openmcl-devel] arithmetic primitives

Bill St. Clair wws at clozure.com
Sat Apr 18 05:34:05 PDT 2020


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20200418/dda57941/attachment.htm>


More information about the Openmcl-devel mailing list