From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5597 invoked by alias); 12 Jun 2009 16:32:48 -0000 Received: (qmail 5587 invoked by uid 22791); 12 Jun 2009 16:32:47 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-fx0-f222.google.com (HELO mail-fx0-f222.google.com) (209.85.220.222) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 12 Jun 2009 16:32:33 +0000 Received: by fxm22 with SMTP id 22so2669865fxm.8 for ; Fri, 12 Jun 2009 09:32:31 -0700 (PDT) Received: by 10.86.31.19 with SMTP id e19mr3991714fge.24.1244824350728; Fri, 12 Jun 2009 09:32:30 -0700 (PDT) Received: from yakj.usersys.redhat.com (nat-pool-brq.redhat.com [62.40.79.66]) by mx.google.com with ESMTPS id 4sm3004592fge.18.2009.06.12.09.32.29 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 12 Jun 2009 09:32:30 -0700 (PDT) Message-ID: <4A328311.2020803@gmail.com> Date: Fri, 12 Jun 2009 16:32:00 -0000 From: Paolo Bonzini User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 Newsgroups: gmane.comp.gcc.devel To: Zachary Turner CC: gcc@gcc.gnu.org Subject: Re: naked functions on x86 architecture References: <478231340906120920m74bd9c0i88861d5e759a8fb1@mail.gmail.com> In-Reply-To: <478231340906120920m74bd9c0i88861d5e759a8fb1@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-06/txt/msg00274.txt.bz2 > This is one example, but it illustrates a general concept that I think > is really useful and I personally have used numerous times for lots of > other instructions than SCAS. If there is a way to achieve this > without using a naked function then please advise. Keeping the __asm syntax, I'd be surprised if this did not work: template int find_first_nonzero_scas(T* x, int cnt) { int result = 0; __asm { xor eax, eax mov edi, x mov ecx, cnt } if (sizeof (T) == 1) __asm { rep scasb; mov result, edi } if (sizeof (T) == 2) __asm { rep scasw; mov result, edi } if (sizeof (T) == 4) __asm { rep scasl; mov result, edi } result -= reinterpret_cast(x); result /= sizeof(T); return --result; } Paolo