Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bf5of-0005wL-OU for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Aug 2016 13:44:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bf5of-000804-AI for pgsql-hackers@arkaria.postgresql.org; Wed, 31 Aug 2016 13:44:33 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bf5oc-0007vS-S2 for pgsql-hackers@postgresql.org; Wed, 31 Aug 2016 13:44:30 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bf5oZ-0006Ue-HA for pgsql-hackers@postgresql.org; Wed, 31 Aug 2016 13:44:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u7VDiECf018069; Wed, 31 Aug 2016 09:44:14 -0400 From: Tom Lane To: Heikki Linnakangas cc: pgsql-hackers Subject: Re: Use static inline functions for Float <-> Datum conversions In-reply-to: <752262dc-0a51-22bd-9cfa-88532d2d8dc2@iki.fi> References: <6355.1472643514@sss.pgh.pa.us> <752262dc-0a51-22bd-9cfa-88532d2d8dc2@iki.fi> Comments: In-reply-to Heikki Linnakangas message dated "Wed, 31 Aug 2016 15:22:30 +0300" Date: Wed, 31 Aug 2016 09:44:14 -0400 Message-ID: <18068.1472651054@sss.pgh.pa.us> X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Heikki Linnakangas writes: > On 08/31/2016 02:38 PM, Tom Lane wrote: >> I wonder whether there is a compiler-dependent way of avoiding the union >> trick ... or maybe gcc is already smart enough that it doesn't matter? > It seems to compile into a single instruction, so it can't get any > better from a performance point of view. Yeah, confirmed here. On my not-real-new gcc (version 4.4.7, which ships with RHEL6), these test functions: Datum compare_int8(PG_FUNCTION_ARGS) { int64 x = PG_GETARG_INT64(0); int64 y = PG_GETARG_INT64(1); PG_RETURN_BOOL(x < y); } Datum compare_float8(PG_FUNCTION_ARGS) { double x = PG_GETARG_FLOAT8(0); double y = PG_GETARG_FLOAT8(1); PG_RETURN_BOOL(x < y); } compile into this (at -O2): compare_int8: .cfi_startproc movq 40(%rdi), %rax cmpq %rax, 32(%rdi) setl %al movzbl %al, %eax ret .cfi_endproc compare_float8: .cfi_startproc movsd 40(%rdi), %xmm0 xorl %eax, %eax ucomisd 32(%rdi), %xmm0 seta %al ret .cfi_endproc (Not sure why the compiler does the widening of the comparison result differently, but it doesn't look like it matters.) Before this patch, that looked like: compare_float8: .cfi_startproc pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 movq %rdi, %rbx subq $16, %rsp .cfi_def_cfa_offset 32 movq 32(%rdi), %rdi call DatumGetFloat8 movq 40(%rbx), %rdi movsd %xmm0, 8(%rsp) call DatumGetFloat8 xorl %eax, %eax ucomisd 8(%rsp), %xmm0 seta %al addq $16, %rsp .cfi_def_cfa_offset 16 popq %rbx .cfi_def_cfa_offset 8 ret .cfi_endproc Nice. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers