Skip to content

Commit

Permalink
Add regression and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rudihorn committed Dec 10, 2021
1 parent 5400b72 commit 283004c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
*
* All rights reserved.
*
Expand Down Expand Up @@ -49,14 +49,14 @@ public final class LLVMIVarBitSmall extends LLVMIVarBit {
private final int bits;
private final long value;

LLVMIVarBitSmall(int bits, long value) {
public LLVMIVarBitSmall(int bits, long value) {
this.bits = bits;
this.value = value;

assert bits <= MAX_SIZE;
}

LLVMIVarBitSmall(int bits, byte[] arr, int arrBits, boolean signExtend) {
public LLVMIVarBitSmall(int bits, byte[] arr, int arrBits, boolean signExtend) {
this.bits = bits;

long v = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma pack(1)
struct {
int v : 30;
int : 4;
} c = { -1 };

int main() {
return c.v != -1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.oracle.truffle.llvm.tests.runtime;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.oracle.truffle.llvm.runtime.LLVMIVarBitSmall;

public class LLVMIVarBitSmallTest {
@Test
public void unpackUnsignedLong() {
LLVMIVarBitSmall v = new LLVMIVarBitSmall(40, 0x00FF_FFFF_FF00L);
assertEquals(0x00FF_FFFF_FF00L, v.getZeroExtendedLongValue());
}

@Test
public void unpackSignedLong() {
LLVMIVarBitSmall v = new LLVMIVarBitSmall(40, 0x00FF_FFFF_FF00L);

assertTrue("v.getLongValue() is negative", v.getLongValue() < 0);
assertEquals(0xFFFF_FFFF_FFFF_FF00L, v.getLongValue());
}

@Test
public void arithMeticShiftRight() {
LLVMIVarBitSmall v = new LLVMIVarBitSmall(40, 0x00FF_FFFF_FC00L).arithmeticRightShift(new LLVMIVarBitSmall(32, 10));
assertEquals(-1L, v.getLongValue());
}
}

0 comments on commit 283004c

Please sign in to comment.