unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Using labels-as-values on MacOS X
Date: Fri, 25 May 2012 17:31:11 +0200	[thread overview]
Message-ID: <87fwao6zwg.fsf@gnu.org> (raw)
In-Reply-To: ACF34E1C-B9FA-47F1-B178-0797F4BA7E65@raeburn.org

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

Hi,

Ken Raeburn <raeburn@raeburn.org> skribis:

> * Don't use addresses of code labels with LLVM, even if the compiler
> supports them.  At least with the version of LLVM GCC on my Mac ("gcc
> version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build
> 2336.1.00)"),

Damn, what compiler is this?  It’s not the old GCC 4.2 fork?  Is it
Clang?  GCC with DragonEgg?

> the performance seems to be quite poor; "guild compile" was showing
> about a 4x penalty in CPU time.  (For psyntax-pp.go, it was 10 minutes
> of CPU time vs 46 minutes.)

Weird, would be good to see what happens.

The two options for VM dispatching are:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: VMs --]
[-- Type: text/x-csrc, Size: 555 bytes --]

#include <stdio.h>
int
vm_jt (const unsigned int *code)
{
  static const void *jump_table[] = { &&op0, &&op1, &&op2 };
  register const unsigned int *ip = code;

#define NEXT goto *jump_table[*ip++]

  NEXT;

 op0:
  puts ("op0");
  return 0;
 op1:
  puts ("op1");
  NEXT;
 op2:
  puts ("op2");
  NEXT;
}

int
vm_switch (const unsigned int *code)
{
  register const unsigned int *ip = code;

  while (1)
    switch (*ip++)
      {
      case 0:
	puts ("op0");
	return 0;
      case 1:
	puts ("op1");
	break;
      case 2:
	puts ("op2");
	break;
      }
}

[-- Attachment #3: Type: text/plain, Size: 724 bytes --]


Could you look at the code generated by that compiler for this file?

With GCC 4.6.2 at -O2, the dispatch with labels-as-values looks like this:

	mov	-4(%rbx), %eax
	movq	jump_table.2080(,%rax,8), %rax
	addq	$4, %rbx
	jmp	*%rax

In the other case it’s a series of comparisons like this:

	cmpl	$2, %eax
	jne	.L14
	movl	$.LC2, %edi
	call	puts
	movl	(%rbx), %eax
	addq	$4, %rbx
	cmpl	$1, %eax
	jne	.L16
	movl	$.LC1, %edi
	call	puts
	jmp	.L14

> Later/future versions may do better, so we can update it with
> version-number checks, unless we want to build performance tests into
> the configure script, which doesn't sound like a great idea to me.

Agreed, but OTOH #ifdef __LLVM__ isn’t future-proof.

Thanks,
Ludo’.

  parent reply	other threads:[~2012-05-25 15:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-21  5:45 a few proposed patches Ken Raeburn
2012-05-21  6:41 ` Neil Jerram
2012-05-22  7:54 ` Andy Wingo
2012-05-22 16:51   ` Ken Raeburn
2012-05-22  8:17 ` Andy Wingo
2012-05-22  8:21   ` Andy Wingo
2012-05-22 16:54   ` Ken Raeburn
2012-05-25 14:56     ` Removing ‘GC_PTR’ Ludovic Courtès
2012-05-25 15:31 ` Ludovic Courtès [this message]
2012-05-25 16:32   ` Using labels-as-values on MacOS X Hans Aberg
2012-05-26 12:44     ` Ludovic Courtès
2012-05-26 12:58       ` Hans Aberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87fwao6zwg.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).