From: Denys R. <rt...@ma...> - 2007-08-15 19:13:16
|
Hi Juho, > Not really. SBCL is already perfectly capable of working with untagged > numbers, none of those things need to be changed as they already exist > Am I right that the the untagged numbers are called "immediate"? > in the right form. It just generally prefers to work with tagged > ones. Your function could be rewritten like this to make sbcl use an > untagged representation for I: > > (defun foo2 (a x) > (declare (type (simple-array (unsigned-byte 8) (*)) a) > (optimize (safety 0)) > (type (mod #.(ash most-positive-fixnum 2)) x)) > (let ((i -1)) > (tagbody > next-loop > (if (>= i x) > (progn nil (go end-loop)) nil) > (setq i (1+ i)) > (setf (aref a i) 55) > (go next-loop) > end-loop))) > > Basically your original example shows a weakness in the way SBCL does > representation selection. This is the process of making the decision > of how various values should be represented as machine level, > e.g. should an integer be tagged or stored as a raw word in a > register? > > SBCL will first select which VOPs it'll use, based on the type > information and the costs of various VOPs. Once those decisions have > been fixed, it'll then look at what representations the various VOPs > want to use for their arguments and return values. The DATA-VECTOR-SET > VOP wants the index argument to be untagged, the FAST-IF->-C and > FAST-+-C VOPs want their arguments to be tagged. So SBCL will decide > to store I as tagged, since it'll just need to do one tagged->untagged > conversions rather than several untagged->tagged ones. > > Now, there also happen to exist versions of the FAST-IF->-C and > FAST-+-C VOPs which deal with untagged values. If the VOP selection > The syntax of VOPs is still hard for me to read. However, it looks like FAST-IF->-C VOP does not specify what kind of arguments are expected. Its definition contains only (:translate ...) and (:generator ...) parts and I do not see two different versions of the same VOP. Perhaps, there should be a version with something like (:args (x :scs (any-reg immediate)))? By the way, does a detailed description of the macros for defining VOPs exist somewhere? I think it would be useful for those who are interested in SBCL internals. As for me, I saw only a few pages on http://sbcl-internals.cliki.net/ and it is still a mystery for me how a VOP like this works: (define-vop (fast-conditional) (:conditional) (:info target not-p) (:effects) (:affected) (:policy :fast-safe)) > had chosen those versions instead, it wouldn't need to do any > untagged<->tagged conversions. To take advantage of this the VOP and > representation selections would need to be integrated somehow. IIRC, > Nathan Froyd had some plans about how to deal with this. > Regards, Denys Rtveliashvili |