From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.user,gmane.lisp.guile.devel Subject: Re: mmap for guile Date: Tue, 19 Jul 2022 15:20:56 +0200 Message-ID: <4c07ec35d773ecb8d4d7ea6687a4c11cd2a221b0.camel@telenet.be> References: <56ee7537-1666-3d04-7093-732a75624e9b@gmail.com> <0cf4e4ee80169487694b844996e04f3293eab92f.camel@telenet.be> <87k08tfau0.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22079"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.42.1 Cc: guile-devel@gnu.org To: Ludovic =?ISO-8859-1?Q?Court=E8s?= , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Jul 19 15:58:08 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oDnjk-0005WZ-0D for guile-user@m.gmane-mx.org; Tue, 19 Jul 2022 15:58:08 +0200 Original-Received: from localhost ([::1]:46548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDnji-0000qX-HR for guile-user@m.gmane-mx.org; Tue, 19 Jul 2022 09:58:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDn9t-0006nY-EG for guile-user@gnu.org; Tue, 19 Jul 2022 09:21:05 -0400 Original-Received: from albert.telenet-ops.be ([2a02:1800:110:4::f00:1a]:37152) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDn9o-0005iY-Ng for guile-user@gnu.org; Tue, 19 Jul 2022 09:21:05 -0400 Original-Received: from ptr-bvsjgyig5nh0salm0pi.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:5dba:d409:33f7:a16]) by albert.telenet-ops.be with bizsmtp id x1Lw2700P20ykKC061LxRW; Tue, 19 Jul 2022 15:20:57 +0200 In-Reply-To: <87k08tfau0.fsf@gnu.org> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r22; t=1658236857; bh=hq3Ip5LbrgdhR6mbn5/+BBMF3KnniKZnrYxSk62XNYE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=UwSfa38zAVADwU/Yr/R+IkXbWSPEtfo8IOsnDRdUDLQguTglphmvZlMim236vtuYp hQeF5r1x6ObwD/41RJCOmONzlGyw5lXSd4yVKFAGZnAgElp1BqGmozcgA+2Z8IgRMW WmuLjZMi6YgjJ6e6o8J5CVI70xGc+X4cAohS8EpmLj3mxAsg7ORf6IZwIvwEya9oWC IuQbvLbkNu6AhN8n0LCX0vch3AFRW6QlmZ9jZ15ZcJjAX0b96YnN/8TEEu9ILAZyIv FvGdoAjLMGlJxYlQViUBhVokw3BR6DbEAwOtLGri8BZO/5XVtoa/DrXWvyeyURA1pY bK/auJgRPKFRA== Received-SPF: pass client-ip=2a02:1800:110:4::f00:1a; envelope-from=maximedevos@telenet.be; helo=albert.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18432 gmane.lisp.guile.devel:21259 Archived-At: Ludovic Courtès schreef op ma 04-07-2022 om 12:09 [+0200]: > I don’t think the optimizer makes any such assumption, except for > literal bytevectors. It _does_ assume that bytevector lengths don't change: ,use (rnrs bytevectors) ,compile (bytevector-u8-ref some-variable 999) ;;; : warning: possibly unbound variable `some-variable' Disassembly of at #xe8: 0 (instrument-entry 254) at (unknown file):4:9 2 (assert-nargs-ee/locals 1 3) ;; 4 slots (0 args) 3 (call-scm<-thread 3 62) at (unknown file):4:28 5 (static-ref 2 187) ;; some-variable 7 (call-scm<-scm-scm 3 3 2 111) 9 (scm-ref/immediate 3 3 1) 10 (make-immediate 2 3998) ;; 999 at (unknown file):4:42 11 (immediate-tag=? 3 7 0) ;; heap-object? at (unknown file):4:9 13 (jne 21) ;; -> L2 14 (heap-tag=? 3 127 77) ;; bytevector? 16 (jne 18) ;; -> L2 17 (word-ref/immediate 1 3 1) 18 (load-s64 0 0 999) 21 (imm-u64 L1 23 (usub/immediate 1 1 0) 24 (u64 L1 26 (pointer-ref/immediate 2 3 2) 27 (u8-ref 3 2 0) 28 (tag-fixnum 3 3) 29 (reset-frame 1) ;; 1 slot 30 (handle-interrupts) 31 (return-values) L1: 32 (throw/value+data 2 188) ;; #(out-of-range "bytevector-u8-ref" "Argument 2 out of range: ~S") L2: 34 (throw/value+data 3 212) ;; #(wrong-type-arg "bytevector-u8-ref" "Wrong type argument in position 1 (ex…") As can be seen in the above output, it first determines the length of the bytevector and then compares it again the index (for the index check) and then actually reads th byte so it assumes that the length doesn't change in-between -- it's not an atomic operation! Even if it didn't, being able to assume bytevector lengths don't change is important for optimising code like (begin (bytevector-ref bv 9000) (bytevector-ref 8999) ...)), to optimise out many range checks, though I don't know if Guile currently does that. Greetings, Maxime.