From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Add unboxed floating point comparison instructions. Date: Wed, 21 Dec 2016 20:11:45 +0100 Message-ID: <87mvfpumfi.fsf@pobox.com> References: <87lgvjgu2s.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1482347538 22113 195.159.176.226 (21 Dec 2016 19:12:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 21 Dec 2016 19:12:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: guile-devel To: "Thompson\, David" Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Dec 21 20:12:13 2016 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJmJ7-0004lY-Kj for guile-devel@m.gmane.org; Wed, 21 Dec 2016 20:12:09 +0100 Original-Received: from localhost ([::1]:58624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cJmJC-00068S-4z for guile-devel@m.gmane.org; Wed, 21 Dec 2016 14:12:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36029) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cJmIx-000622-35 for guile-devel@gnu.org; Wed, 21 Dec 2016 14:12:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cJmIs-0001vT-Rs for guile-devel@gnu.org; Wed, 21 Dec 2016 14:11:59 -0500 Original-Received: from pb-sasl1.pobox.com ([64.147.108.66]:61127 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cJmIs-0001ut-JD for guile-devel@gnu.org; Wed, 21 Dec 2016 14:11:54 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 320EA4FDBD; Wed, 21 Dec 2016 14:11:52 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=m6XIi0iuZvqX+5RiBVXXG/yyuC0=; b=L9JVDU WidTxfaMqfuM39NVTI9af5HCsepnODmBIEVxan62lohv1MHYA9/ZVzbsUYDkhwaR 6wGtxkHJcn+KmI79pMj8MUBMk6MHIuUBx7/P0rrDNLhAGKTlZdKbUXW7vhuZrz++ zmzKtoo+exU0xIfKTueFs9Pe9eKHCuPZ6wweI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=QqvGt7RovhrHvFcZvHra9VD90DJpLr8f QDXj1PinCWrOiCjhbkI/ReKWv4QCgR54UE4IQhsHh0OCfJhCCMdCPMXNpbAYkgRj nQzf5vet6e3Aerc4MlZy89PAyL+jr/kNup1yHfDLe6XDpGRDt13GDIPNKym/cy17 kGNZ+KhIafc= Original-Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 29DD44FDBC; Wed, 21 Dec 2016 14:11:52 -0500 (EST) Original-Received: from clucks (unknown [64.18.118.244]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id A47A04FDBB; Wed, 21 Dec 2016 14:11:51 -0500 (EST) In-Reply-To: (David Thompson's message of "Wed, 14 Dec 2016 09:51:51 -0500") X-Pobox-Relay-ID: 543506F0-C7B1-11E6-8BA4-B2316462E9F6-02397024!pb-sasl1.pobox.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 64.147.108.66 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:18806 Archived-At: Hi! Patch looks good, just a couple of nits. On Wed 14 Dec 2016 15:51, "Thompson, David" writes: > + VM_DEFINE_OP (189, br_if_f64_le, "br-if-f64-<=", OP3 (X8_S24, X8_S24, B1_X7_L24)) > + { > + BR_F64_ARITHMETIC (<=); > + } Missing inline docs for this one. > @@ -283,6 +297,8 @@ BITS indicating the significant bits needed for a variable. BITS may be > (lambda (type min max) > (and (eqv? type &exact-integer) > (<= 0 min max #xffffffffffffffff)))))) > + (define (f64-operand? var) > + (operand-in-range? var &flonum -inf.0 +inf.0)) > (match cont > (($ $kfun) > (let ((types (infer-types cps label))) This one can be simplified to (eqv? type &flonum), I think. > --- a/module/language/cps/types.scm > +++ b/module/language/cps/types.scm > @@ -378,6 +378,7 @@ minimum, and maximum." > (define-syntax-rule (&max/u64 x) (min (&max x) &u64-max)) > (define-syntax-rule (&min/s64 x) (max (&min x) &s64-min)) > (define-syntax-rule (&max/s64 x) (min (&max x) &s64-max)) > +(define-syntax-rule (&max/f64 x) (min (&max x) +inf.0)) > (define-syntax-rule (&max/size x) (min (&max x) *max-size-t*)) This can be simplified to (&max x) I think, and I suspect you are missing a &min/f64 below: > +(define (infer-f64-comparison-ranges op min0 max0 min1 max1) > + (match op > + ('< (values min0 (min max0 (1- max1)) (max (1+ min0) min1) max1)) > + ('<= (values min0 (min max0 max1) (max min0 min1) max1)) > + ('>= (values (max min0 min1) max0 min1 (min max0 max1))) > + ('> (values (max min0 (1+ min1)) max0 min1 (min (1- max0) max1))))) Pretty sure this is not the right thing; the 1+/1- bits are appropriate for comparisons over integers. Since the next f64 value from a given X is only epsilon away from X, I think the right thing to do here is to remove 1+/1- entirely. > +(define-syntax-rule (define-f64-comparison-inferrer (f64-op op inverse)) > + (define-predicate-inferrer (f64-op a b true?) > + (call-with-values > + (lambda () > + (infer-f64-comparison-ranges (if true? 'op 'inverse) > + (&min/0 a) (&max/f64 a) > + (&min/0 b) (&max/f64 b))) > + (lambda (min0 max0 min1 max1) > + (restrict! a &f64 min0 max0) > + (restrict! b &f64 min1 max1))))) I think &min/0 should be replaced by (&min/f64). Probably also you need a good +nan.0 story here; does this do the right thing? e.g. (let ((a +nan.0)) (if (< a 100.0) (< a 200.0) (> a 50.0))) Does this fold to #t? I think for +nan.0 it should not, but AFAIU with your patch it does fold. (Guile has some optimizer problems related to flonums, I think; this patch doesn't have to fix them all, but it shouldn't make them worse, or if it does, we need a nice story.) > +(define-simple-type-checker (f64-< &f64 &f64)) > +(define-f64-comparison-inferrer (f64-< < >=)) Likewise we need an understanding that the inverse of < is in fact >=. Maybe it is indeed :) Cheers, Andy