Skip to content

Commit 24856c9

Browse files
committed
[GR-32049] Add bitcast from i1 to ivar.
PullRequest: graal/9138
2 parents 3af9184 + a920d6d commit 24856c9

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMIVarBit.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -31,7 +31,10 @@
3131

3232
import java.math.BigInteger;
3333

34+
import com.oracle.truffle.api.CompilerAsserts;
3435
import com.oracle.truffle.api.memory.ByteArraySupport;
36+
import com.oracle.truffle.api.nodes.ExplodeLoop;
37+
import com.oracle.truffle.llvm.runtime.vector.LLVMI1Vector;
3538

3639
/**
3740
* Abstract type for variable width integers. Depending on the concrete bit width, either the
@@ -171,4 +174,26 @@ private static byte[] longToArray(long from) {
171174
ByteArraySupport.bigEndian().putLong(array, 0, from);
172175
return array;
173176
}
177+
178+
@ExplodeLoop
179+
public static LLVMIVarBit fromI1Vector(int bits, LLVMI1Vector from) {
180+
CompilerAsserts.partialEvaluationConstant(bits);
181+
if (bits <= LLVMIVarBitSmall.MAX_SIZE) {
182+
long value = 0;
183+
for (int i = 0; i < bits; i++) {
184+
if (from.getValue(i)) {
185+
value |= 1 << i;
186+
}
187+
}
188+
return LLVMIVarBitSmall.create(bits, value, bits, false);
189+
} else {
190+
byte[] value = new byte[(bits + 7) >> 3];
191+
for (int i = 0; i < bits; i++) {
192+
if (from.getValue(i)) {
193+
value[value.length - 1 - (i >> 3)] |= 1 << (i & 7);
194+
}
195+
}
196+
return LLVMIVarBitLarge.create(bits, value, bits, false);
197+
}
198+
}
174199
}

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/cast/LLVMToVarINode.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -33,6 +33,7 @@
3333
import com.oracle.truffle.api.dsl.NodeChild;
3434
import com.oracle.truffle.api.dsl.NodeField;
3535
import com.oracle.truffle.api.dsl.Specialization;
36+
import com.oracle.truffle.api.nodes.ExplodeLoop;
3637
import com.oracle.truffle.llvm.runtime.LLVMIVarBit;
3738
import com.oracle.truffle.llvm.runtime.LLVMIVarBitLarge;
3839
import com.oracle.truffle.llvm.runtime.LLVMIVarBitSmall;
@@ -43,6 +44,7 @@
4344
import com.oracle.truffle.llvm.runtime.nodes.cast.LLVMToVarINodeGen.LLVMSignedCastToIVarNodeGen;
4445
import com.oracle.truffle.llvm.runtime.nodes.cast.LLVMToVarINodeGen.LLVMUnsignedCastToIVarNodeGen;
4546
import com.oracle.truffle.llvm.runtime.pointer.LLVMPointer;
47+
import com.oracle.truffle.llvm.runtime.vector.LLVMI1Vector;
4648

4749
@NodeChild(value = "fromNode", type = LLVMExpressionNode.class)
4850
@NodeField(type = int.class, name = "bits")
@@ -192,5 +194,12 @@ protected LLVMIVarBit do80BitFloat(LLVM80BitFloat from) {
192194
assert getBits() == LLVM80BitFloat.BIT_WIDTH;
193195
return LLVMIVarBit.create(getBits(), from.getBytesBigEndian(), LLVM80BitFloat.BIT_WIDTH, true);
194196
}
197+
198+
@Specialization
199+
@ExplodeLoop
200+
protected LLVMIVarBit doI1Vector(LLVMI1Vector from) {
201+
assert getBits() == from.getLength();
202+
return LLVMIVarBit.fromI1Vector(getBits(), from);
203+
}
195204
}
196205
}

0 commit comments

Comments
 (0)