001/*
002 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.lir.gen;
024
025import jdk.internal.jvmci.meta.*;
026
027import com.oracle.graal.compiler.common.calc.*;
028import com.oracle.graal.compiler.common.type.*;
029import com.oracle.graal.lir.*;
030
031/**
032 * This interface can be used to generate LIR for arithmetic operations.
033 *
034 * The setFlags flag in emitAdd, emitSub and emitMul indicates, that the instruction must set the
035 * flags register to be used for a later branch. (On AMD64, the condition codes are set in every
036 * arithmetic instruction, but other architectures optionally set the flags register) If setFlags is
037 * set, the instruction must set the flags register; if false, the instruction may or may not set
038 * the flags register.
039 */
040public interface ArithmeticLIRGenerator {
041
042    LIRKind getLIRKind(Stamp stamp);
043
044    Value emitNegate(Value input);
045
046    Value emitAdd(Value a, Value b, boolean setFlags);
047
048    Value emitSub(Value a, Value b, boolean setFlags);
049
050    Value emitMul(Value a, Value b, boolean setFlags);
051
052    Value emitMulHigh(Value a, Value b);
053
054    Value emitUMulHigh(Value a, Value b);
055
056    Value emitDiv(Value a, Value b, LIRFrameState state);
057
058    Value emitRem(Value a, Value b, LIRFrameState state);
059
060    Value emitUDiv(Value a, Value b, LIRFrameState state);
061
062    Value emitURem(Value a, Value b, LIRFrameState state);
063
064    Value emitNot(Value input);
065
066    Value emitAnd(Value a, Value b);
067
068    Value emitOr(Value a, Value b);
069
070    Value emitXor(Value a, Value b);
071
072    Value emitShl(Value a, Value b);
073
074    Value emitShr(Value a, Value b);
075
076    Value emitUShr(Value a, Value b);
077
078    Value emitFloatConvert(FloatConvert op, Value inputVal);
079
080    Value emitReinterpret(LIRKind to, Value inputVal);
081
082    Value emitNarrow(Value inputVal, int bits);
083
084    Value emitSignExtend(Value inputVal, int fromBits, int toBits);
085
086    Value emitZeroExtend(Value inputVal, int fromBits, int toBits);
087
088    Value emitMathAbs(Value input);
089
090    Value emitMathSqrt(Value input);
091}