From patchwork Tue Aug 25 11:25:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 510463 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 02DD81401F6 for ; Tue, 25 Aug 2015 21:25:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=tv9RTVTL; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Rz4lG0xfBe8BWxFLDxgrD598YP5ekH9ME026I6X2iyFWWK9BFDy3L Wa3bm85GoMhnKB4qnf0grJZiolkUm9pcDqZItY2I3ssfY7hlkggHoisCqz7x5dR8 ZmwLP9iU8a8idsQhHydhH5GSVHm3YfBgHQCpR4xnMHthX4evzDF7Ts= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=ymXNM425N6Up0cCHBGWltL1aObY=; b=tv9RTVTL8q9voqrkNTn4 IFh9OouWeddGmwEoeoqGYNDOjZnjbPCBrQiXedkpoYyVI8se+0urdd7zS0tLGNFP LZKAfbiudjFpDvM8UxlFt3lvNk1UXLOcJiHscNiffQAU7KAh7mrRFbgi/yyNEwtT xsi50PWfMuZ9nxNHu7nz1Aw= Received: (qmail 2373 invoked by alias); 25 Aug 2015 11:25:07 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 2361 invoked by uid 89); 25 Aug 2015 11:25:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 25 Aug 2015 11:25:05 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5255CADB4 for ; Tue, 25 Aug 2015 11:25:02 +0000 (UTC) Date: Tue, 25 Aug 2015 13:25:02 +0200 From: Martin Jambor To: GCC Patches Subject: [hsa] Support unary FP operations implementable with a single HSA instruction Message-ID: <20150825112501.GB32341@virgil.suse.cz> Mail-Followup-To: GCC Patches MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, the patch below adds support for a few unary floating point buitlins that can be implemented with a single HSA instruction. More effort in the area of builtins is needed, the motivation for this was a a benchmark that previously failed with a sorry message. Committed to the hsa branch. Martin 2015-08-25 Martin Jambor * hsa-gen.c (gen_hsa_unaryop_for_builtin): New function. (gen_hsa_insns_for_call): Add support for a few unary fp operations. --- gcc/ChangeLog.hsa | 4 +++ gcc/hsa-gen.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/gcc/hsa-gen.c b/gcc/hsa-gen.c index 14cf890..1e23996 100644 --- a/gcc/hsa-gen.c +++ b/gcc/hsa-gen.c @@ -3213,6 +3213,26 @@ gen_hsa_insns_for_kernel_call (hsa_bb *hbb, gcall *call) hsa_cfun->kernel_dispatch_count++; } +/* Helper functions to create a single unary HSA operations out of calls to + builtins. OPCODE is the HSA operation to be generated. STMT is a gimple + call to a builtin. HBB is the HSA BB to which the instruction should be + added and SSA_MAP is used to map gimple SSA names to HSA pseudoreisters. */ + +static void +gen_hsa_unaryop_for_builtin (int opcode, gimple stmt, hsa_bb *hbb, + vec *ssa_map) +{ + tree lhs = gimple_call_lhs (stmt); + /* FIXME: Since calls without a LHS are not removed, double check that + they cannot have side effects. */ + if (!lhs) + return; + hsa_op_reg *dest = hsa_reg_for_gimple_ssa (lhs, ssa_map); + hsa_op_base *op = hsa_reg_or_immed_for_gimple_op (gimple_call_arg (stmt, 0), + hbb, ssa_map, NULL); + gen_hsa_unary_operation (opcode, dest, op, hbb); +} + /* Generate HSA instructions for the given call statement STMT. Instructions will be appended to HBB. SSA_MAP maps gimple SSA names to HSA pseudo registers. */ @@ -3284,22 +3304,64 @@ specialop: break; } + case BUILT_IN_FABS: + case BUILT_IN_FABSF: + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_ABS, stmt, hbb, ssa_map); + break; + + case BUILT_IN_CEIL: + case BUILT_IN_CEILF: + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_CEIL, stmt, hbb, ssa_map); + break; + + case BUILT_IN_FLOOR: + case BUILT_IN_FLOORF: + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_FLOOR, stmt, hbb, ssa_map); + break; + + case BUILT_IN_RINT: + case BUILT_IN_RINTF: + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_RINT, stmt, hbb, ssa_map); + break; + case BUILT_IN_SQRT: case BUILT_IN_SQRTF: - /* FIXME: Since calls without a LHS are not removed, double check that - they cannot have side effects. */ - if (!lhs) - return; - dest = hsa_reg_for_gimple_ssa (lhs, ssa_map); - insn = new hsa_insn_basic (2, BRIG_OPCODE_SQRT, dest->type); - insn->operands[0] = dest; - dest->set_definition (insn); - insn->operands[1] - = hsa_reg_or_immed_for_gimple_op (gimple_call_arg (stmt, 0), - hbb, ssa_map, insn); - hbb->append_insn (insn); + /* TODO: Perhaps produce BRIG_OPCODE_NSQRT with -ffast-math? */ + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_SQRT, stmt, hbb, ssa_map); + break; + + case BUILT_IN_TRUNC: + case BUILT_IN_TRUNCF: + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_TRUNC, stmt, hbb, ssa_map); break; + case BUILT_IN_COS: + case BUILT_IN_COSF: + /* FIXME: Using the native instruction may not be precise enough. + Perhaps only allow if using -ffast-math? */ + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NCOS, stmt, hbb, ssa_map); + break; + + case BUILT_IN_EXP2: + case BUILT_IN_EXP2F: + /* FIXME: Using the native instruction may not be precise enough. + Perhaps only allow if using -ffast-math? */ + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NEXP2, stmt, hbb, ssa_map); + break; + + case BUILT_IN_LOG2: + case BUILT_IN_LOG2F: + /* FIXME: Using the native instruction may not be precise enough. + Perhaps only allow if using -ffast-math? */ + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NLOG2, stmt, hbb, ssa_map); + break; + + case BUILT_IN_SIN: + case BUILT_IN_SINF: + /* FIXME: Using the native instruction may not be precise enough. + Perhaps only allow if using -ffast-math? */ + gen_hsa_unaryop_for_builtin (BRIG_OPCODE_NSIN, stmt, hbb, ssa_map); + case BUILT_IN_ATOMIC_LOAD_1: case BUILT_IN_ATOMIC_LOAD_2: case BUILT_IN_ATOMIC_LOAD_4: