Beispiel #1
0
        public void SignedCastModuleTest()
        {
            var sim    = new CombinationalRTLSimulator <SignedCastModule>();
            var values = new short[] {
                short.MinValue,
                -257, -256, -255,
                -1, 0, 1,
                127, 128, 129,
                254, 255, 256,
                short.MaxValue,
                -32641,
                -128, -127, -126,
            };

            foreach (var value in values.Reverse())
            {
                sim.TopLevel.Cycle(new SignedCastModuleInputs()
                {
                    ShortValue = value
                });
                Assert.AreEqual((byte)value, sim.TopLevel.ByteValue);
                Assert.AreEqual((sbyte)value, sim.TopLevel.SByteValue);
                Assert.AreEqual((ushort)value, sim.TopLevel.UShortValue);
                Assert.AreEqual((int)value, sim.TopLevel.IntValue);
                Assert.AreEqual((uint)value, sim.TopLevel.UIntValue);
            }
        }
Beispiel #2
0
        public void UnsignedCastModuleTest()
        {
            var sim    = new CombinationalRTLSimulator <UnsignedCastModule>();
            var values = new ushort[] {
                0,
                127, 128, 129,
                254, 255, 256,
                0x7FFE,
                0x7FFF,
                0x8000,
                0x8001,
                ushort.MaxValue
            };

            foreach (var value in values)
            {
                sim.TopLevel.Cycle(new UnsignedCastModuleInputs()
                {
                    UShortValue = value
                });
                Assert.AreEqual((byte)value, sim.TopLevel.ByteValue);
                Assert.AreEqual((sbyte)value, sim.TopLevel.SByteValue);
                Assert.AreEqual((short)value, sim.TopLevel.ShortValue);
                Assert.AreEqual((int)value, sim.TopLevel.IntValue);
                Assert.AreEqual((uint)value, sim.TopLevel.UIntValue);
            }
        }
Beispiel #3
0
        public void BitArrayModuleTest()
        {
            var sim = new CombinationalRTLSimulator <BitArrayModule>();

            sim.TopLevel.Cycle(new BitArrayInputs()
            {
                Value = 0xC2
            });
            Assert.AreEqual(0xC2, (byte)sim.TopLevel.Direct);
            Assert.AreEqual(0xC, (byte)sim.TopLevel.High);
            Assert.AreEqual(0x2, (byte)sim.TopLevel.Low);
            Assert.AreEqual(0x43, (byte)sim.TopLevel.Reversed);
            Assert.AreEqual(0x3, (byte)sim.TopLevel.ReversedHigh);
            Assert.AreEqual(0x4, (byte)sim.TopLevel.ReversedLow);
            Assert.AreEqual(0x9, (byte)sim.TopLevel.Picks);
            Assert.AreEqual(0xD, (byte)sim.TopLevel.FromBits1);
            Assert.AreEqual(0x7, (byte)sim.TopLevel.FromBits2);
        }
Beispiel #4
0
        public void CombinationalROMModuleTest()
        {
            var sim = new CombinationalRTLSimulator <CombinationalROMModule>();

            var buff = CombinationalROMModule.GetBuffer();

            for (var idx = 0; idx < buff.Length; idx++)
            {
                sim.TopLevel.Cycle(new CombinationalROMModuleInputs()
                {
                    ReadAddress1 = (byte)idx,
                    ReadAddress2 = (byte)(255 - idx)
                });

                Assert.AreEqual(buff[idx], sim.TopLevel.Value1);
                Assert.AreEqual(buff[255 - idx], sim.TopLevel.Value2);
            }
        }
        public void Test()
        {
            var sim = new CombinationalRTLSimulator <InstructionDecoderModule>();
            var tl  = sim.TopLevel;

            tl.Cycle(new InstructionDecoderInputs()
            {
                Instruction = 0x8358D8C1
            });

            // regs, opcodes
            Assert.AreEqual("1000001", tl.OpCode.AsBinaryString(), "OpCode");
            Assert.AreEqual("10001", tl.RD.AsBinaryString(), "RD");
            Assert.AreEqual("10001", tl.RS1.AsBinaryString(), "RS1");
            Assert.AreEqual("10101", tl.RS2.AsBinaryString(), "RS2");
            Assert.AreEqual("101", tl.Funct3.AsBinaryString(), "Funct2");
            Assert.AreEqual("1000001", tl.Funct7.AsBinaryString(), "Funct7");

            // immediates

            // IType
            tl.Cycle(new InstructionDecoderInputs()
            {
                Instruction = 0x8018D8C1
            });
            Assert.AreEqual("100000000001".PadLeft(32, '1'), tl.ITypeImm.AsBinaryString(), "IType");

            // SType
            tl.Cycle(new InstructionDecoderInputs()
            {
                Instruction = 0x8358D8C1
            });
            Assert.AreEqual("100000110001".PadLeft(32, '1'), tl.STypeImm.AsBinaryString(), "SType");

            // BType
            tl.Cycle(new InstructionDecoderInputs()
            {
                Instruction = 0xC358D9C1
            });
            Assert.AreEqual("1110000110010".PadLeft(32, '1'), tl.BTypeImm.AsBinaryString(), "BType");

            tl.Cycle(new InstructionDecoderInputs()
            {
                Instruction = 0xC358D941
            });
            Assert.AreEqual("1010000110010".PadLeft(32, '1'), tl.BTypeImm.AsBinaryString(), "BType");

            // UType
            tl.Cycle(new InstructionDecoderInputs()
            {
                Instruction = 0x800018C1
            });
            Assert.AreEqual("10000000000000000001".PadRight(32, '0'), tl.UTypeImm.AsBinaryString(), "UType");

            // JType
            tl.Cycle(new InstructionDecoderInputs()
            {
                Instruction = 0xC03818C1
            });
            Assert.AreEqual("110000001110000000010".PadLeft(32, '1'), tl.JTypeImm.AsBinaryString(), "JType");
        }