Mercurial > hg > graal-compiler
changeset 21359:c4b87ad2c4c8
Improve code generation for zero extend on AMD64.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Wed, 13 May 2015 11:53:17 +0200 |
parents | 19801a65cf57 |
children | 88e4916f246a |
files | graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java |
diffstat | 1 files changed, 27 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Tue May 12 18:26:52 2015 -0700 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Wed May 13 11:53:17 2015 +0200 @@ -1066,16 +1066,36 @@ return result; } else { assert inputVal.getKind().getStackKind() == Kind.Int; - Variable result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Int)); - int mask = (int) CodeUtil.mask(fromBits); - append(new AMD64Binary.DataOp(AND.getRMOpcode(DWORD), DWORD, result, asAllocatable(inputVal), JavaConstant.forInt(mask))); + + LIRKind resultKind = LIRKind.derive(inputVal); + OperandSize resultSize; if (toBits > 32) { - Variable longResult = newVariable(LIRKind.derive(inputVal).changeType(Kind.Long)); - emitMove(longResult, result); - return longResult; + resultKind = resultKind.changeType(Kind.Long); + resultSize = QWORD; } else { - return result; + resultKind = resultKind.changeType(Kind.Int); + resultSize = DWORD; + } + + switch (fromBits) { + case 8: + return emitConvertOp(resultKind, MOVZXB, resultSize, inputVal); + case 16: + return emitConvertOp(resultKind, MOVZX, resultSize, inputVal); + case 32: + return emitConvertOp(resultKind, MOV, DWORD, inputVal); } + + // odd bit count, fall back on manual masking + Variable result = newVariable(resultKind); + JavaConstant mask; + if (toBits > 32) { + mask = JavaConstant.forLong(CodeUtil.mask(fromBits)); + } else { + mask = JavaConstant.forInt((int) CodeUtil.mask(fromBits)); + } + append(new AMD64Binary.DataOp(AND.getRMOpcode(DWORD), DWORD, result, asAllocatable(inputVal), mask)); + return result; } }