From patchwork Thu Dec 5 13:01:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Nevill X-Patchwork-Id: 22069 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C1A4223FBA for ; Thu, 5 Dec 2013 13:01:09 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id md12sf50058936pbc.0 for ; Thu, 05 Dec 2013 05:01:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:subject:from:reply-to:to :cc:date:in-reply-to:references:organization:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type:content-transfer-encoding; bh=gPi91SIIGK0q3cfJcWDQZvLkiZS78v9F7prwVjG4OOc=; b=AwogRvFuZsUH8oJEnsuFGRzXe1mqYJDHkGDsyI+0aHLte81xypnYUDgo5sJhZBQS2+ Qb2j+I1HzIWPtPr54BgGrFOS0pO9GjqdzAr0L4oaRUm4Y36lmA+dKJMgEdEcsWrVd8xG 6mEKq+SuZmgjJHrYR52Hp7GCAfxRwIFhoBCcOjIX+7d/reDWuBSpm5LrVqSsiIGSMk83 /NfWIc6sVZ8ca5pyYyclz8qZR4RtosA4ZdwSiFu44pwCAndfhRTsZRWZWx8ypGTHhG9a 9jEE+/ssNmpKlDHreKN1fY9Yi9rJa/sCo3zK05GSgf/h0uzY+7tNLC43L3TtK15xGweR GwpA== X-Gm-Message-State: ALoCoQlzkT+yEJ27206OxPegrnrqkYF3VNNzUisiB/Q4hKST7/sLs/y47B6EC9fsA6jcZery5zUf X-Received: by 10.68.136.229 with SMTP id qd5mr10992228pbb.6.1386248468596; Thu, 05 Dec 2013 05:01:08 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.47.103 with SMTP id c7ls751361qen.24.gmail; Thu, 05 Dec 2013 05:01:08 -0800 (PST) X-Received: by 10.52.106.107 with SMTP id gt11mr34568103vdb.7.1386248468461; Thu, 05 Dec 2013 05:01:08 -0800 (PST) Received: from mail-ve0-f177.google.com (mail-ve0-f177.google.com [209.85.128.177]) by mx.google.com with ESMTPS id sl9si19592022vdc.86.2013.12.05.05.01.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 05:01:08 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.177; Received: by mail-ve0-f177.google.com with SMTP id db12so13323949veb.8 for ; Thu, 05 Dec 2013 05:01:08 -0800 (PST) X-Received: by 10.58.67.168 with SMTP id o8mr12920870vet.22.1386248468264; Thu, 05 Dec 2013 05:01:08 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp13090vcz; Thu, 5 Dec 2013 05:01:07 -0800 (PST) X-Received: by 10.14.69.200 with SMTP id n48mr16087559eed.54.1386248467287; Thu, 05 Dec 2013 05:01:07 -0800 (PST) Received: from mail-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) by mx.google.com with ESMTPS id p46si10720950eem.189.2013.12.05.05.01.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Dec 2013 05:01:07 -0800 (PST) Received-SPF: neutral (google.com: 74.125.83.51 is neither permitted nor denied by best guess record for domain of edward.nevill@linaro.org) client-ip=74.125.83.51; Received: by mail-ee0-f51.google.com with SMTP id b15so3050357eek.24 for ; Thu, 05 Dec 2013 05:01:06 -0800 (PST) X-Received: by 10.14.175.3 with SMTP id y3mr12322274eel.59.1386248466858; Thu, 05 Dec 2013 05:01:06 -0800 (PST) Received: from [192.168.1.112] (validation.linaro.org. [88.98.47.97]) by mx.google.com with ESMTPSA id o47sm106057666eem.21.2013.12.05.05.01.05 for (version=SSLv3 cipher=RC4-SHA bits=128/128); Thu, 05 Dec 2013 05:01:06 -0800 (PST) Message-ID: <1386248464.8800.20.camel@localhost.localdomain> Subject: RFR: Re: [aarch64-port-dev ] Error in server compiler when packing/unpacking data from arrays using shift and mask ops. From: Edward Nevill Reply-To: edward.nevill@linaro.org To: Andy Johnson Cc: aarch64-port-dev@openjdk.java.net, patches@linaro.org Date: Thu, 05 Dec 2013 13:01:04 +0000 In-Reply-To: References: Organization: Linaro X-Mailer: Evolution 3.8.5 (3.8.5-2.fc19) Mime-Version: 1.0 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: edward.nevill@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Wed, 2013-12-04 at 16:07 -0500, Andy Johnson wrote: > The jtreg hotspot/compiler test TestCharVect.java contains the following > code snippet: > long l0 = (long)a1[i*4+0]; > long l1 = (long)a1[i*4+1]; > long l2 = (long)a1[i*4+2]; > long l3 = (long)a1[i*4+3]; > p4[i] = (l0 & 0xFFFFl) | > ((l1 & 0xFFFFl) << 16) | > ((l2 & 0xFFFFl) << 32) | > ((l3 & 0xFFFFl) << 48); Much code elided. > > 0x00007fcac91a7d28: sbfx x15, x15, #16, #16 <<<<<<<<<<< > 0x00007fcac91a7d2c: sbfiz x14, x14, #32, #32 > 0x00007fcac91a7d30: sbfiz x16, x17, #16, #32 > 0x00007fcac91a7d34: sxtw x11, w11 > 0x00007fcac91a7d38: orr x11, x11, x16 > 0x00007fcac91a7d3c: orr x11, x11, x14 > 0x00007fcac91a7d40: sbfiz x14, x5, #32, #32 > 0x00007fcac91a7d44: sbfiz x16, x1, #16, #32 > 0x00007fcac91a7d48: sxtw x17, w3 > 0x00007fcac91a7d4c: orr x16, x17, x16 > 0x00007fcac91a7d50: orr x14, x16, x14 > 0x00007fcac91a7d54: orr x14, x14, x15 > 0x00007fcac91a7d58: add xscratch1, x13, #0x10 > 0x00007fcac91a7d5c: str x14, [xscratch1,w0,sxtw #3] > 0x00007fcac91a7d60: sbfx x14, x18, #16, #16 <<<<<<<<<<<<< I believe the lines marked "<<<<<<<<<" are the source of the problem. What they are trying to do is shift left by 48, what they in fact do is a bitfield extract of bit 16..31. This is due to the baroque encoding of the sbfiz and sbfx instructions. I believe the following patch will fix the problem. Ok to push? Ed. --- CUT HERE --- exporting patch: # HG changeset patch # User Edward Nevill edward.nevill@linaro.org # Date 1386246975 0 # Thu Dec 05 12:36:15 2013 +0000 # Node ID 9a4f9705f626b50214d9b11917fd0aaef88685f3 # Parent 141fc5d4229ae66293617edb25050506932471ec Fix lshift_ext in C2 for shifts >= 32 --- CUT HERE --- The following gcc test program shows how gcc encodes shifts and shows how sbfm encodes variusly to sbfiz/sbfx. I had to write this to try to get my head around the sbfm encoding. --- CUT HERE --- long shift8(int a) { return (long)a << 8; } long shift16(int a) { return (long)a << 16; } long shift24(int a) { return (long)a << 24; } long shift32(int a) { return (long)a << 32; } long shift40(int a) { return (long)a << 40; } long shift48(int a) { return (long)a << 48; } long shift56(int a) { return (long)a << 56; } long asm_shift8(int a) { long b; asm("sbfm %[result], %[source], 56, 31" : [result]"=r" (b) : [source]"r" (a)); return b; } long asm_shift16(int a) { long b; asm("sbfm %[result], %[source], 48, 31" : [result]"=r" (b) : [source]"r" (a)); return b; } long asm_shift24(int a) { long b; asm("sbfm %[result], %[source], 40, 31" : [result]"=r" (b) : [source]"r" (a)); return b; } long asm_shift32(int a) { long b; asm("sbfm %[result], %[source], 32, 31" : [result]"=r" (b) : [source]"r" (a)); return b; } long asm_shift40(int a) { long b; asm("sbfm %[result], %[source], 24, 31" : [result]"=r" (b) : [source]"r" (a)); return b; } long asm_shift48(int a) { long b; asm("sbfm %[result], %[source], 16, 31" : [result]"=r" (b) : [source]"r" (a)); return b; } long asm_shift56(int a) { long b; asm("sbfm %[result], %[source], 8, 31" : [result]"=r" (b) : [source]"r" (a)); return b; } --- CUT HERE --- And here is the output from objdump when compiled gcc -O3 -c shift.c --- CUT HERE --- shift.o: file format elf64-littleaarch64 Disassembly of section .text: 0000000000000000 : 0: 93787c00 sbfiz x0, x0, #8, #32 4: d65f03c0 ret 0000000000000008 : 8: 93707c00 sbfiz x0, x0, #16, #32 c: d65f03c0 ret 0000000000000010 : 10: 93687c00 sbfiz x0, x0, #24, #32 14: d65f03c0 ret 0000000000000018 : 18: d3607c00 lsl x0, x0, #32 1c: d65f03c0 ret 0000000000000020 : 20: d3585c00 lsl x0, x0, #40 24: d65f03c0 ret 0000000000000028 : 28: d3503c00 lsl x0, x0, #48 2c: d65f03c0 ret 0000000000000030 : 30: d3481c00 lsl x0, x0, #56 34: d65f03c0 ret 0000000000000038 : 38: 93787c00 sbfiz x0, x0, #8, #32 3c: d65f03c0 ret 0000000000000040 : 40: 93707c00 sbfiz x0, x0, #16, #32 44: d65f03c0 ret 0000000000000048 : 48: 93687c00 sbfiz x0, x0, #24, #32 4c: d65f03c0 ret 0000000000000050 : 50: 93607c00 sbfiz x0, x0, #32, #32 54: d65f03c0 ret 0000000000000058 : 58: 93587c00 sbfx x0, x0, #24, #8 5c: d65f03c0 ret 0000000000000060 : 60: 93507c00 sbfx x0, x0, #16, #16 64: d65f03c0 ret 0000000000000068 : 68: 93487c00 sbfx x0, x0, #8, #24 6c: d65f03c0 ret --- CUT HERE --- diff -r 141fc5d4229a -r 9a4f9705f626 src/cpu/aarch64/vm/aarch64.ad --- a/src/cpu/aarch64/vm/aarch64.ad Mon Dec 02 17:19:42 2013 +0000 +++ b/src/cpu/aarch64/vm/aarch64.ad Thu Dec 05 12:36:15 2013 +0000 @@ -6930,8 +6930,13 @@ format %{ "sbfm $dst, $src, 64-$scale, 31\t" %} ins_encode %{ - __ sbfm(as_Register($dst$$reg), - as_Register($src$$reg), (64u - $scale$$constant) & 63, 31); + if ($scale$$constant >= 32) + // If scale >= 32 must encode this as LSL, sbfm encodes as SBFX, not SBFIZ + __ ubfm(as_Register($dst$$reg), + as_Register($src$$reg), (64u - $scale$$constant) & 63, 63 - $scale$$constant); + else + __ sbfm(as_Register($dst$$reg), + as_Register($src$$reg), (64u - $scale$$constant) & 63, 31); %} ins_pipe(pipe_class_default);