gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] Re: random dreaming of faster typing: a subtypep/type-of opt


From: Camm Maguire
Subject: [Gcl-devel] Re: random dreaming of faster typing: a subtypep/type-of optimizer
Date: 13 Nov 2005 19:12:31 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Greetings!

Robert Boyer <address@hidden> writes:

> It annoys me when I write code like:
> 
>   (or (consp x)
>       (symbolp x)     
>       (stringp x))
> 
> It would be nice if
> 
>   (subtypep (type-of x) '(or cons symbol string))
> 
> compiled in-line to just a few instructions, including only one call to
> type_of, when the type is the or of certain primitives.
> 

Yes, this is a great idea, but I think what you want to expand thus is

(typep x '(or cons symbol string))

GCL already does this reasonably effectively for simple types.
Extending to the compound case should not be too dificult.  Actually,
the way this happens is that co1typep (the compiler function specially
handling typep) rewrites certain types into predicate calls
(i.e. vector -> vectorp, etc.) and the optimizer (gcl_cmpopt.lsp) does
the rest.  So it might be a wee bit tricky handling the general case
where predicates are not available, but in principle this is
straightforward. 

What we really need here, IMHO, is an automatic local declaration on
both branches of the if called with typep as the disciminant.  I.e.

(if (typep x 'list) (foo x) (bar x))

->

(if (listp x) (let ((x x)) (declare (list x)) (foo x)) (let ((x x))
(declare ((not list) x)) (bar x)))

The problem of course always lies with the compound cases, and when the
discriminant involves other functions than typep.  I.e.

(if (and (typep x 'list) (baz)) (foo x) (bar x))

->

(if (and (listp x) (baz)) (let ((x x)) (declare (list x)) (foo x))
(bar x)))

> I think something like this is done for GCL code written in C, but it would
> nice if it were available to the Lisp user.
> 
> I'm thinking of stuff like:
> 
>   TS_MEMBER(type_of(x), TS(t_array) | TS(t_vector) | TS(t_string))
> 
> I'm guessing this could work for the primitive types cons, fixnum, bignum,
> ratio, shortfloat, doublefloat, complex, character, pathname, string,
> bitvector, vector, array, hashtable, structure, symbol, package, stream, and
> readtable.
> 

Spot on to my understanding.

BTW, any feeling yet on the potential of the fork-based parallelism
for the kinds of things you all might be interested in?

Take care,

> Bob
> 
> 
> 
> 

-- 
Camm Maguire                                            address@hidden
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah




reply via email to

[Prev in Thread] Current Thread [Next in Thread]