From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7158 invoked by alias); 2 Jul 2019 10:41:45 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 7145 invoked by uid 89); 2 Jul 2019 10:41:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=H*Ad:U*aph, HX-Languages-Length:1078, letter, him X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 02 Jul 2019 10:41:43 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8016A300413A; Tue, 2 Jul 2019 10:41:37 +0000 (UTC) Received: from zarquon.pink (unknown [10.33.36.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C6625D6A9; Tue, 2 Jul 2019 10:41:36 +0000 (UTC) To: Zdenek Sojka Cc: gcc-help@gcc.gnu.org References: <4bd282e4-f193-4b22-7f97-e8f50da09717@redhat.com> From: Andrew Haley Openpgp: preference=signencrypt Subject: Re: [x86 inline asm]: width of register arguments Message-ID: Date: Tue, 02 Jul 2019 10:41:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-07/txt/msg00028.txt.bz2 On 7/2/19 6:37 AM, Zdenek Sojka wrote: > Ok, shame - it seems to behave so in my experiments: It's more complicated than that. Sometimes the size of the operand is in the name of the instruction and sometimes you need to force the size yourself. For example, with int a, x: asm("mov %1, %0" : "=&r"(a) : "r"(x)); generates mov %edx, %eax but asm("mov %b1, %b0" : "=&r"(a) : "r"(x)); generates mov %dl, %al For a real-world example, static __inline void outb_p (unsigned char __value, unsigned short int __port) { __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value), "Nd" (__port)); } On x86 the special asm out single letter directives following a '%' are defined in i386.md. I'm a bit paranoid about this stuff because my memory of GCC's inline asm goes back decades to when it was far more fragile than it is now. -- Andrew Haley (he/him) Java Platform Lead Engineer Red Hat UK Ltd. https://keybase.io/andrewhaley EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671