Clean up warnings for round() function declaration.
[iverilog.git] / libveriuser / getsimtime.c
blob5eedb5bb860f2dab7493183318a42d7ae2a20228
1 /* vi:sw=6
2 * Copyright (c) 2002,2003 Michael Ruff (mruff at chiaro.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #ifdef HAVE_CVS_IDENT
20 #ident "$Id: getsimtime.c,v 1.11 2003/06/21 23:40:15 steve Exp $"
21 #endif
23 #include <veriuser.h>
24 #include <vpi_user.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include "config.h"
28 #include "priv.h"
29 #include <assert.h>
32 * some TF time routines implemented using VPI interface
35 static ivl_u64_t
36 scale(int high, int low, void*obj) {
37 vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
38 ivl_u64_t scaled;
40 scaled = high;
41 scaled = (scaled << 32) | low;
42 scaled *= pow(10, vpi_get(vpiTimePrecision,0) -
43 vpi_get(vpiTimeUnit,obj ? (vpiHandle)obj : hand));
45 return scaled;
49 PLI_INT32 tf_gettime(void)
51 s_vpi_time time;
52 time.type = vpiSimTime;
53 vpi_get_time (0, &time);
54 return scale(time.high, time.low, 0) & 0xffffffff;
57 char *tf_strgettime(void)
59 static char buf[32];
60 s_vpi_time time;
62 time.type = vpiSimTime;
63 vpi_get_time (0, &time);
64 if (time.high)
65 snprintf(buf, sizeof(buf)-1, "%u%08u", time.high, time.low);
66 else
67 snprintf(buf, sizeof(buf)-1, "%u", time.low);
68 return buf;
71 PLI_INT32 tf_igetlongtime(PLI_INT32 *high, void*obj)
73 s_vpi_time time;
74 ivl_u64_t scaled;
75 time.type = vpiSimTime;
76 vpi_get_time ((vpiHandle)obj, &time);
77 scaled = scale(time.high, time.low, obj);
79 *high = (scaled >> 32) & 0xffffffff;
80 return scaled & 0xffffffff;
83 PLI_INT32 tf_getlongtime(PLI_INT32 *high)
85 return tf_igetlongtime(high, 0);
88 /* Alias for commercial simulators */
89 PLI_INT32 tf_getlongsimtime(PLI_INT32 *high) \
90 __attribute__ ((weak, alias ("tf_getlongtime")));
92 void tf_scale_longdelay(void*obj, PLI_INT32 low, PLI_INT32 high,
93 PLI_INT32 *alow, PLI_INT32 *ahigh)
95 ivl_u64_t scaled = scale(high, low, obj);
96 *ahigh = (scaled >> 32) & 0xffffffff;
97 *alow = scaled & 0xffffffff;
100 void tf_unscale_longdelay(void*obj, PLI_INT32 low, PLI_INT32 high,
101 PLI_INT32 *alow, PLI_INT32 *ahigh)
103 ivl_u64_t unscaled;
104 vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
106 unscaled = high;
107 unscaled = (unscaled << 32) | low;
108 unscaled *= pow(10, vpi_get(vpiTimeUnit, hand) -
109 vpi_get(vpiTimePrecision, 0));
111 *ahigh = (unscaled >> 32) & 0xffffffff;
112 *alow = unscaled & 0xffffffff;
115 void tf_scale_realdelay(void*obj, double real, double *areal)
117 vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
119 *areal = real * pow(10, vpi_get(vpiTimePrecision, 0) -
120 vpi_get(vpiTimeUnit, hand));
123 void tf_unscale_realdelay(void*obj, double real, double *areal)
125 vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
127 *areal = real * pow(10, vpi_get(vpiTimeUnit, hand) -
128 vpi_get(vpiTimePrecision, 0));
131 PLI_INT32 tf_gettimeprecision(void)
133 PLI_INT32 rc;
134 vpiHandle hand;
135 vpiHandle sys = vpi_handle(vpiSysTfCall,0);
136 assert(sys);
138 hand = vpi_handle(vpiScope, sys);
139 rc = vpi_get(vpiTimePrecision, hand);
141 if (pli_trace)
142 fprintf(pli_trace, "tf_gettimeprecision(<%s>) --> %d\n",
143 vpi_get_str(vpiName, sys), rc);
145 return rc;
148 PLI_INT32 tf_igettimeprecision(void*obj)
150 PLI_INT32 rc;
152 if (obj == 0) {
153 /* If the obj pointer is null, then get the simulation
154 time precision. */
155 rc = vpi_get(vpiTimePrecision, 0);
157 } else {
159 vpiHandle scope = vpi_handle(vpiScope, (vpiHandle)obj);
160 assert(scope);
161 rc = vpi_get(vpiTimePrecision, scope);
164 if (pli_trace)
165 fprintf(pli_trace, "tf_igettimeprecision(<%s>) --> %d\n",
166 obj? vpi_get_str(vpiName, obj) : ".", rc);
168 return rc;
172 PLI_INT32 tf_gettimeunit()
174 vpiHandle hand = vpi_handle(vpiScope, vpi_handle(vpiSysTfCall,0));
175 return vpi_get(vpiTimeUnit, hand);
178 PLI_INT32 tf_igettimeunit(void*obj)
180 return vpi_get(!obj ? vpiTimePrecision : vpiTimeUnit, (vpiHandle)obj);
185 * $Log: getsimtime.c,v $
186 * Revision 1.11 2003/06/21 23:40:15 steve
187 * gettimeprecision will null argument has specific meaning.
189 * Revision 1.10 2003/06/13 19:23:42 steve
190 * Add a bunch more PLI1 routines.
192 * Revision 1.9 2003/06/04 01:56:20 steve
193 * 1) Adds configure logic to clean up compiler warnings
194 * 2) adds acc_compare_handle, acc_fetch_range, acc_next_scope and
195 * tf_isetrealdelay, acc_handle_scope
196 * 3) makes acc_next reentrant
197 * 4) adds basic vpiWire type support
198 * 5) fills in some acc_object_of_type() and acc_fetch_{full}type()
199 * 6) add vpiLeftRange/RigthRange to signals
201 * Revision 1.8 2003/05/30 04:01:55 steve
202 * Add tf_scale_longdelay.
204 * Revision 1.7 2003/05/28 03:14:20 steve
205 * Missing time related declarations.
207 * Revision 1.6 2003/05/27 16:22:10 steve
208 * PLI get time units/precision.
210 * Revision 1.5 2003/04/12 18:57:14 steve
211 * More acc_ function stubs.
213 * Revision 1.4 2003/03/13 04:35:09 steve
214 * Add a bunch of new acc_ and tf_ functions.
216 * Revision 1.3 2003/03/06 00:27:54 steve
217 * Fill in required fields when getting time.
219 * Revision 1.2 2002/08/12 01:35:02 steve
220 * conditional ident string using autoconfig.
222 * Revision 1.1 2002/05/31 18:25:51 steve
223 * Add tf_getlongtime (mruff)