1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
//*************************************************************************
//
// Copyright 2009-2017 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// Lesser General Public License Version 3 or the Perl Artistic License
// Version 2.0.
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
//
//*************************************************************************
#include "svdpi.h"
#include <cstdio>
#include <cstring>
#include <iostream>
// These require the above. Comment prevents clang-format moving them
#include "TestCheck.h"
//======================================================================
// clang-format off
#if defined(VERILATOR)
# include "Vt_dpi_open__Dpi.h"
#elif defined(VCS)
# include "../vc_hdrs.h"
#elif defined(NC)
# define NEED_EXTERNS
// #elif defined(MS)
// # define NEED_EXTERNS
#else
# error "Unknown simulator for DPI test"
#endif
// clang-format on
#ifdef NEED_EXTERNS
extern "C" {
// If get ncsim: *F,NOFDPI: Function {foo} not found in default libdpi.
// Then probably forgot to list a function here.
extern void dpii_unused(const svOpenArrayHandle u);
extern void dpii_open_p0_u1(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_p1_u0(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_p1_u1(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_p1_u2(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_p1_u3(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_pw_u0(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_pw_u1(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_pw_u2(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_pw_u3(int c, int p, int u, const svOpenArrayHandle i,
const svOpenArrayHandle o);
extern void dpii_open_bit(const svOpenArrayHandle i, const svOpenArrayHandle o);
extern void dpii_open_byte(const svOpenArrayHandle i, const svOpenArrayHandle o);
extern void dpii_open_int(const svOpenArrayHandle i, const svOpenArrayHandle o);
extern void dpii_open_integer(const svOpenArrayHandle i, const svOpenArrayHandle o);
extern void dpii_open_logic(const svOpenArrayHandle i, const svOpenArrayHandle o);
extern void dpii_open_int_u1(int u, const svOpenArrayHandle i, const svOpenArrayHandle o);
extern void dpii_open_int_u2(int u, const svOpenArrayHandle i, const svOpenArrayHandle o);
extern void dpii_open_int_u3(int u, const svOpenArrayHandle i, const svOpenArrayHandle o);
extern int dpii_failure();
}
#endif
int errors = 0;
int dpii_failure() { return errors; }
void dpii_unused(const svOpenArrayHandle u) {}
void _dpii_all(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
#ifdef TEST_VERBOSE
fprintf(stderr, "-:%s:%d: For case c=%d p=%d u=%d data=%p\n", //
__FILE__, __LINE__, c, p, u, svGetArrayPtr(i));
#endif
(void)svGetArrayPtr(i);
#ifndef NC
// NC always returns zero and warns
(void)svSizeOfArray(i);
#endif
#ifndef VCS // VCS does not support dimension 0 query
if (p) {
int d = 0;
if (c == 0 || c == 1) {
TEST_CHECK_HEX_EQ(svLeft(i, d), 1);
TEST_CHECK_HEX_EQ(svRight(i, d), -1);
TEST_CHECK_HEX_EQ(svLow(i, d), -1);
TEST_CHECK_HEX_EQ(svHigh(i, d), 1);
// TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
TEST_CHECK_HEX_EQ(svSize(i, d), 3);
} else if (c == 2) {
TEST_CHECK_HEX_EQ(svLeft(i, d), 95);
TEST_CHECK_HEX_EQ(svRight(i, d), 1);
TEST_CHECK_HEX_EQ(svLow(i, d), 1);
TEST_CHECK_HEX_EQ(svHigh(i, d), 95);
// TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
TEST_CHECK_HEX_EQ(svSize(i, d), 95);
} else {
TEST_CHECK_HEX_EQ(0, 1);
}
}
#endif
if (u >= 1) {
int d = 1;
if (c == 0) {
TEST_CHECK_HEX_EQ(svLeft(i, d), -2);
TEST_CHECK_HEX_EQ(svRight(i, d), 2);
TEST_CHECK_HEX_EQ(svLow(i, d), -2);
TEST_CHECK_HEX_EQ(svHigh(i, d), 2);
// TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
TEST_CHECK_HEX_EQ(svSize(i, d), 5);
} else if (c == 1) {
TEST_CHECK_HEX_EQ(svLeft(i, d), 2);
TEST_CHECK_HEX_EQ(svRight(i, d), -2);
TEST_CHECK_HEX_EQ(svLow(i, d), -2);
TEST_CHECK_HEX_EQ(svHigh(i, d), 2);
// TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
TEST_CHECK_HEX_EQ(svSize(i, d), 5);
}
}
if (u >= 2) {
int d = 2;
if (c == 0) {
TEST_CHECK_HEX_EQ(svLeft(i, d), -3);
TEST_CHECK_HEX_EQ(svRight(i, d), 3);
TEST_CHECK_HEX_EQ(svLow(i, d), -3);
TEST_CHECK_HEX_EQ(svHigh(i, d), 3);
// TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
TEST_CHECK_HEX_EQ(svSize(i, d), 7);
} else if (c == 1) {
TEST_CHECK_HEX_EQ(svLeft(i, d), 3);
TEST_CHECK_HEX_EQ(svRight(i, d), -3);
TEST_CHECK_HEX_EQ(svLow(i, d), -3);
TEST_CHECK_HEX_EQ(svHigh(i, d), 3);
// TEST_CHECK_HEX_EQ(svIncrement(i, d), 0);
TEST_CHECK_HEX_EQ(svSize(i, d), 7);
}
}
#ifdef VERILATOR
// Check out-of-bounds read doesn't access bad memory (when sanitizer used)
(void)svLeft(i, -1);
(void)svRight(i, -1);
(void)svLow(i, -1);
(void)svHigh(i, -1);
(void)svIncrement(i, -1);
(void)svSize(i, -1);
//
(void)svLeft(i, 99);
(void)svRight(i, 99);
(void)svLow(i, 99);
(void)svHigh(i, 99);
(void)svIncrement(i, 99);
(void)svSize(i, 99);
#endif
if (c == 2 && p == 1 && u == 3) {
for (int a = svLow(i, 1); a <= svHigh(i, 1); ++a) {
for (int b = svLow(i, 2); b <= svHigh(i, 2); ++b) {
for (int c = svLow(i, 3); c <= svHigh(i, 3); ++c) {
// printf("Copy abc %d,%d,%d\n", a,b,c);
svLogicVecVal vec[3];
svGetLogicArrElemVecVal(vec, i, a, b, c);
#ifdef NC
// printf(" %08lx_%08lx_%08lx\n", vec[2].a, vec[1].a, vec[0].a);
vec[0].a = (~vec[0].a);
vec[1].a = (~vec[1].a);
vec[2].a = (~vec[2].a) & 0x7fffffff;
// vec[0].b = vec[0].b;
// vec[1].b = vec[1].b;
// vec[2].b = vec[2].b;
#else
vec[0].aval = (~vec[0].aval);
vec[1].aval = (~vec[1].aval);
vec[2].aval = (~vec[2].aval) & 0x7fffffff;
// vec[0].bval = vec[0].bval;
// vec[1].bval = vec[1].bval;
// vec[2].bval = vec[2].bval;
#endif
svPutLogicArrElemVecVal(o, vec, a, b, c);
}
}
}
}
}
void dpii_open_p0_u1(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_p1_u0(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_p1_u1(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_p1_u2(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_p1_u3(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_pw_u0(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_pw_u1(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_pw_u2(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_pw_u3(int c, int p, int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_all(c, p, u, i, o);
}
void dpii_open_bit(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
void dpii_open_byte(const svOpenArrayHandle i, const svOpenArrayHandle o) {
intptr_t arrPtr = (intptr_t)svGetArrayPtr(i);
TEST_CHECK_HEX_NE(arrPtr, 0); // All the arrays should actually exist
#ifndef NC
// NC always returns zero and warns
int sizeInputOfArray = svSizeOfArray(i);
TEST_CHECK_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size
TEST_CHECK_HEX_NE(svDimensions(i), 0); // All the test cases are unpacked arrays
#endif
}
void dpii_open_integer(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
void dpii_open_logic(const svOpenArrayHandle i, const svOpenArrayHandle o) {}
static void _dpii_open_int_ux(int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
intptr_t arrPtr = (intptr_t)svGetArrayPtr(i);
TEST_CHECK_HEX_NE(arrPtr, 0); // All the arrays should actually exist
#ifndef NC
// NC always returns zero and warns
int sizeInputOfArray = svSizeOfArray(i);
TEST_CHECK_HEX_NE(sizeInputOfArray, 0); // None of the test cases have zero size
TEST_CHECK_HEX_EQ(svDimensions(i), u);
#endif
int dim = svDimensions(i);
for (int a = svLow(i, 1); a <= svHigh(i, 1); ++a) {
if (dim == 1) {
intptr_t ip = (intptr_t)svGetArrElemPtr(i, a);
intptr_t i2p = (intptr_t)svGetArrElemPtr1(i, a);
TEST_CHECK_HEX_EQ(ip, i2p);
TEST_CHECK_HEX_NE(ip, 0);
intptr_t op = (intptr_t)svGetArrElemPtr(o, a);
TEST_CHECK_HEX_NE(op, 0);
*reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip);
} else {
for (int b = svLow(i, 2); b <= svHigh(i, 2); ++b) {
if (dim == 2) {
intptr_t ip = (intptr_t)svGetArrElemPtr(i, a, b);
intptr_t i2p = (intptr_t)svGetArrElemPtr2(i, a, b);
TEST_CHECK_HEX_EQ(ip, i2p);
TEST_CHECK_HEX_NE(ip, 0);
intptr_t op = (intptr_t)svGetArrElemPtr(o, a, b);
TEST_CHECK_HEX_NE(op, 0);
*reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip);
} else {
for (int c = svLow(i, 3); c <= svHigh(i, 3); ++c) {
if (dim == 3) {
intptr_t ip = (intptr_t)svGetArrElemPtr(i, a, b, c);
intptr_t i2p = (intptr_t)svGetArrElemPtr3(i, a, b, c);
TEST_CHECK_HEX_EQ(ip, i2p);
TEST_CHECK_HEX_NE(ip, 0);
intptr_t op = (intptr_t)svGetArrElemPtr(o, a, b, c);
TEST_CHECK_HEX_NE(op, 0);
*reinterpret_cast<int*>(op) = ~*reinterpret_cast<int*>(ip);
}
}
}
}
}
}
}
void dpii_open_int_u1(int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_open_int_ux(u, i, o);
}
void dpii_open_int_u2(int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_open_int_ux(u, i, o);
}
void dpii_open_int_u3(int u, const svOpenArrayHandle i, const svOpenArrayHandle o) {
_dpii_open_int_ux(u, i, o);
}
|