29#include <gtest/gtest.h>
39TEST(CondCodes, FindCarryWithNoCarryIn8Bit)
41 EXPECT_TRUE(
findCarry(8, 0x100, 0x80, 0x80));
48TEST(CondCodes, FindNoCarryWithNoCarryIn8Bit)
50 EXPECT_FALSE(
findCarry(8, 0xff, 0xf0, 0x0f));
57TEST(CondCodes, FindCarryWithCarryIn8Bit)
59 EXPECT_TRUE(
findCarry(8, 0x100, 0x80, 0x7f));
66TEST(CondCodes, FindNoCarryWithCarryIn8Bit)
68 EXPECT_FALSE(
findCarry(8, 0xff, 0x80, 0x7e));
75TEST(CondCodes, FindCarryWithNoCarryIn32Bit)
77 EXPECT_TRUE(
findCarry(32, 0x100000000, 0x80000000, 0x80000000));
84TEST(CondCodes, FindNoCarryWithNoCarryIn32Bit)
86 EXPECT_FALSE(
findCarry(32, 0xffffffff, 0xffff0000, 0x0000ffff));
89TEST(CondCodes, FindCarryWithCarryIn32Bit)
95 EXPECT_TRUE(
findCarry(32, 0x100000000, 0x80000000, 0x7fffffff));
98 EXPECT_FALSE(
findCarry(32, 0xffffffff, 0x80000000, 0x7ffffffe));
101 EXPECT_TRUE(
findCarry(32, 0x100000000, 0xffffffff, 0x00000000));
104TEST(CondCodes, FindCarryWithNoCarryIn64Bit)
108 EXPECT_TRUE(
findCarry(64, 0x0000000000000000,
110 0x8000000000000000));
117 EXPECT_FALSE(
findCarry(64, 0x0000000000000000,
119 0x0000000000000000));
124 EXPECT_FALSE(
findCarry(64, 0xffffffffffffffff,
126 0x7fffffffffffffff));
131 EXPECT_FALSE(
findCarry(64, 0xffffffffffffffff,
133 0x00000000ffffffff));
136TEST(CondCodes, FindCarryWithCarryIn64Bit)
142 EXPECT_TRUE(
findCarry(64, 0x0000000000000000,
144 0x7fffffffffffffff));
151 EXPECT_FALSE(
findCarry(64, 0x0000000000000001,
153 0x0000000000000000));
159 EXPECT_TRUE(
findCarry(64, 0x0000000000000000,
161 0x7fffffffffffffff));
167 EXPECT_TRUE(
findCarry(64, 0x0000000000000000,
169 0x0000000000000001));
172TEST(CondCodes, FindOverflow8Bit)
186TEST(CondCodes, FindOverflow32Bit)
192 EXPECT_TRUE(
findOverflow(32, 0x80000000, 0x7fffffff, 0x00000001));
197 EXPECT_FALSE(
findOverflow(32, 0x7fffffff, 0x40000000, 0x3fffffff));
200TEST(CondCodes, FindOverflow64Bit)
209 0x0000000000000001));
216 0x3fffffffffffffff));
229TEST(CondCodes, OddParityOverflow)
234TEST(CondCodes, EvenParityOverflow)
TEST(CondCodes, FindCarryWithNoCarryIn8Bit)
static bool findNegative(int width, uint64_t dest)
Calculate the negative flag.
static bool findOverflow(int width, uint64_t dest, uint64_t src1, uint64_t src2)
Calculate the overflow flag from an addition.
static bool findZero(int width, uint64_t dest)
Calculate the zero flag.
static bool findParity(int width, uint64_t dest)
Calculate the parity of a value.
static bool findCarry(int width, uint64_t dest, uint64_t src1, uint64_t src2)
Calculate the carry flag from an addition.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.