[Sbcl-help] A few more vop questions

4 views
Skip to first unread message

Andrew Sengul

unread,
Mar 11, 2023, 8:52:58 PM3/11/23
to sbcl
My vop-building system is coming along well and I have a couple
questions. In (define-vop)'s (:generator) form, the second item is a
number representing the operation's cost. I understand from the blog
post at
https://pvk.ca/Blog/2014/08/16/how-to-define-new-intrinsics-in-sbcl/
that this number is used by the compiler to choose the optimal vop when
in situations where code may compile to different vops. If I'm calling
the functions I generate explicitly, does the cost number entered have
any bearing on how they'll work? Can I just put in 0 for all costs and
be fine?

Second, is there a place where I can see the instructions that are
supported by define-vop? It appears that not all x86 instructions can be
used; for instance I was trying the TZCNT instruction to count trailing
zeroes in a register but it caused an error saying "undefined
instruction." Thanks.



_______________________________________________
Sbcl-help mailing list
Sbcl...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sbcl-help

Douglas Katzman via Sbcl-help

unread,
Mar 11, 2023, 9:33:56 PM3/11/23
to Andrew Sengul, sbcl
On Sat, Mar 11, 2023 at 8:53 PM Andrew Sengul <m...@imagegardenphoto.com> wrote:
 If I'm calling
the functions I generate explicitly, does the cost number entered have
any bearing on how they'll work? Can I just put in 0 for all costs and
be fine?
Conventionally we would put 1 if there's no choice 

Second, is there a place where I can see the instructions that are
supported by define-vop? 
* sb-assem::*inst-encoder*
#<HASH-TABLE :TEST EQL :COUNT 712 {1000549E03}>
I'll add tzcnt so you can see how it's done; maybe you can add other missing ones

Andrew Sengul

unread,
Mar 12, 2023, 12:04:05 PM3/12/23
to Douglas Katzman, sbcl

On 3/11/23 6:33 PM, Douglas Katzman wrote:
> * sb-assem::*inst-encoder*
>
> #<HASH-TABLE :TEST EQL :COUNT 712 {1000549E03}>
> I'll add tzcnt so you can see how it's done; maybe you can add other
> missing ones
Thanks, I can add other instructions if I find them missing. Another
thing: I can specify register types by passing things like unsigned-reg
or single-sse-reg, but is there a place where these register type
symbols are listed? I was looking for the one that refers to XMM
registers. Also, are there offsets associated with the vector registers
(MMX, SSE etc.) that would allow me to set a temporary variable
referring to a specific one? Thanks.

Douglas Katzman via Sbcl-help

unread,
Mar 13, 2023, 1:45:01 PM3/13/23
to Andrew Sengul, sbcl
On Sun, Mar 12, 2023 at 12:03 PM Andrew Sengul <m...@imagegardenphoto.com> wrote:

is there a place where these register type
symbols are listed?
Search for define-storage-class 
I was looking for the one that refers to XMM
registers. Also, are there offsets associated with the vector registers
(MMX, SSE etc.) that would allow me to set a temporary variable
referring to a specific one?
MMX can not be used at all.
There is seldom a reason to wire an XMM/YMM register to anything. You can specify register numbers as integers in ":offset" if you must.

Andrew Sengul

unread,
Mar 14, 2023, 10:14:51 PM3/14/23
to Douglas Katzman, sbcl
Thanks, are the AVX-512 ZMM registers not available? Also, does SBCL
reserve R12 and R13 for some purpose? Anytime I try changing them I get
an unhandled memory fault, I have to push them at the beginning of the
function and pop them at the end in order to avoid this. Interestingly,
I've seen an error message stating "unable to pack a load-TN in SC for
the result" because I reserved most of the GP registers for use with
temporary data and R12 and R13 were missing from the list of potential
registers for the purpose that it printed.

Vasily Postnicov

unread,
Mar 14, 2023, 10:36:37 PM3/14/23
to Andrew Sengul, sbcl
R12-R15 are callee-saved registers in SystemV ABI for x86-64 architecture. I believe SBCL must conform to it, otherwise SBCL - C interop would not be possible (or at least very difficult to implement). Correct me if I am wrong.

https://cs61.seas.harvard.edu/site/pdf/x86-64-abi-20210928.pdf

ср, 15 мар. 2023 г., 05:15 Andrew Sengul <m...@imagegardenphoto.com>:

Stas Boukarev

unread,
Mar 14, 2023, 10:38:43 PM3/14/23
to Vasily Postnicov, sbcl
The C calling convention has no effect on lisp code.

Stas Boukarev

unread,
Mar 14, 2023, 10:40:31 PM3/14/23
to Andrew Sengul, sbcl
There's no avx-512 support. And you can't touch some registers. Don't even push/pop them. 

Andrew Sengul

unread,
Mar 15, 2023, 12:10:07 AM3/15/23
to Stas Boukarev, sbcl
Ok, which registers are those? R12 and R13? The document Vasily linked
says "Registers %rbp, %rbx and %r12 through
%r15 'belong' to the calling function and the called function is
required to preserve their values." Must none of those registers be used
in a vop? I'm finding that my functions require the use of many registers.

On 3/14/23 7:40 PM, Stas Boukarev wrote:
> There's no avx-512 support. And you can't touch some registers. Don't
> even push/pop them. 
>
> On Wed, Mar 15, 2023 at 5:15 AM Andrew Sengul <m...@imagegardenphoto.com
> <mailto:m...@imagegardenphoto.com>> wrote:
>
> Thanks, are the AVX-512 ZMM registers not available? Also, does SBCL
> reserve R12 and R13 for some purpose? Anytime I try changing them
> I get
> an unhandled memory fault, I have to push them at the beginning of the
> function and pop them at the end in order to avoid this.
> Interestingly,
> I've seen an error message stating "unable to pack a load-TN in SC for
> the result" because I reserved most of the GP registers for use with
> temporary data and R12 and R13 were missing from the list of potential
> registers for the purpose that it printed.
>
> On 3/13/23 10:44 AM, Douglas Katzman wrote:
> >
> >
> > On Sun, Mar 12, 2023 at 12:03 PM Andrew Sengul
> > <m...@imagegardenphoto.com <mailto:m...@imagegardenphoto.com>

> <mailto:m...@imagegardenphoto.com <mailto:m...@imagegardenphoto.com>>>


> wrote:
> >
> >
> >     is there a place where these register type
> >     symbols are listed?
> >
> > Search for define-storage-class 
> >
> >     I was looking for the one that refers to XMM
> >     registers. Also, are there offsets associated with the vector
> >     registers
> >     (MMX, SSE etc.) that would allow me to set a temporary variable
> >     referring to a specific one?
> >
> > MMX can not be used at all.
> > There is seldom a reason to wire an XMM/YMM register to
> anything. You
> > can specify register numbers as integers in ":offset" if you must.
>
>
> _______________________________________________
> Sbcl-help mailing list
> Sbcl...@lists.sourceforge.net

> <mailto:Sbcl...@lists.sourceforge.net>
> https://lists.sourceforge.net/lists/listinfo/sbcl-help

Stas Boukarev

unread,
Mar 15, 2023, 12:55:41 AM3/15/23
to Andrew Sengul, sbcl
That document is irrelevant, it's for calling C. And which registers SBCL uses is not specified and my change at any time, just don't wire any registers.

Andrew Sengul

unread,
Mar 15, 2023, 1:22:36 AM3/15/23
to Stas Boukarev, sbcl
Ok, so don't give :offset parameters and let the compiler associate the
vop symbols as it will. It appears I'll need to wire at least the A and
D registers since they specifically are used for the input and output of
MUL and DIV. I had a problem where one of my argument symbols was being
mapped to the D register, whose value was clobbered by MUL and DIV ops
before it could be used, so I wired a different temporary register to
assign the value of that argument.

On 3/14/23 9:55 PM, Stas Boukarev wrote:
> That document is irrelevant, it's for calling C. And which registers
> SBCL uses is not specified and my change at any time, just don't wire
> any registers.
>
> On Wed, Mar 15, 2023 at 7:09 AM Andrew Sengul <m...@imagegardenphoto.com
> <mailto:m...@imagegardenphoto.com>> wrote:
>
> Ok, which registers are those? R12 and R13? The document Vasily linked
> says "Registers %rbp, %rbx and %r12 through
> %r15 'belong' to the calling function and the called function is
> required to preserve their values." Must none of those registers
> be used
> in a vop? I'm finding that my functions require the use of many
> registers.
>
> On 3/14/23 7:40 PM, Stas Boukarev wrote:
> > There's no avx-512 support. And you can't touch some registers.
> Don't
> > even push/pop them. 
> >
> > On Wed, Mar 15, 2023 at 5:15 AM Andrew Sengul
> <m...@imagegardenphoto.com <mailto:m...@imagegardenphoto.com>

> >     <mailto:Sbcl...@lists.sourceforge.net
> <mailto:Sbcl...@lists.sourceforge.net>>
> >     https://lists.sourceforge.net/lists/listinfo/sbcl-help
> >
>


_______________________________________________
Sbcl-help mailing list
Sbcl...@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/sbcl-help

Reply all
Reply to author
Forward
0 new messages