1 // -*- mode: C++; c-file-style: "cc-mode" -*- 2 //************************************************************************* 3 // 4 // Copyright 2011-2011 by Wilson Snyder. This program is free software; you can 5 // redistribute it and/or modify it under the terms of either the GNU 6 // Lesser General Public License Version 3 or the Perl Artistic License 7 // Version 2.0. 8 // SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 9 // 10 //************************************************************************* 11 12 #include <cstdio> 13 #include <cstring> 14 #include "svdpi.h" 15 16 //====================================================================== 17 18 // clang-format off 19 #if defined(VERILATOR) 20 # if defined(T_DPI_SHORTCIRCUIT) 21 # include "Vt_dpi_shortcircuit__Dpi.h" 22 # elif defined(T_DPI_SHORTCIRCUIT2) 23 # include "Vt_dpi_shortcircuit2__Dpi.h" 24 # else 25 # error "Unknown test" 26 # endif 27 #elif defined(VCS) 28 # include "../vc_hdrs.h" 29 #elif defined(CADENCE) 30 # define NEED_EXTERNS 31 #else 32 # error "Unknown simulator for DPI test" 33 #endif 34 // clang-format on 35 36 #ifdef NEED_EXTERNS 37 extern "C" { 38 extern int dpii_clear(); 39 extern int dpii_count(int idx); 40 extern unsigned char dpii_inc0(int idx); 41 extern unsigned char dpii_inc1(int idx); 42 extern unsigned char dpii_incx(int idx, unsigned char value); 43 } 44 #endif 45 46 //====================================================================== 47 48 #define COUNTERS 16 49 static int global_count[COUNTERS]; 50 dpii_clear()51int dpii_clear() { 52 for (int i = 0; i < COUNTERS; ++i) global_count[i] = 0; 53 return 0; 54 } dpii_count(int idx)55int dpii_count(int idx) { return (idx >= 0 && idx < COUNTERS) ? global_count[idx] : -1; } dpii_incx(int idx,unsigned char value)56unsigned char dpii_incx(int idx, unsigned char value) { 57 if (idx >= 0 && idx < COUNTERS) global_count[idx]++; 58 return value; 59 } dpii_inc0(int idx)60unsigned char dpii_inc0(int idx) { return dpii_incx(idx, 0); } dpii_inc1(int idx)61unsigned char dpii_inc1(int idx) { return dpii_incx(idx, 1); } 62