2005-09-14 04:53:13 +02:00
|
|
|
/*
|
2011-02-28 04:20:16 +01:00
|
|
|
* Copyright (c) 2005-2011 Stephen Williams (steve@icarus.com)
|
2005-09-14 04:53:13 +02:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-09-14 04:53:13 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file includes functions for evaluating REAL expressions.
|
|
|
|
|
*/
|
2005-09-19 22:17:59 +02:00
|
|
|
# include "vvp_config.h"
|
2005-09-14 04:53:13 +02:00
|
|
|
# include "vvp_priv.h"
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include <stdlib.h>
|
2005-12-07 04:43:30 +01:00
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
|
# include <stdint.h>
|
|
|
|
|
#endif
|
2008-01-14 18:53:20 +01:00
|
|
|
|
|
|
|
|
#ifdef HAVE_INTTYPES_H
|
|
|
|
|
# ifndef __STDC_FORMAT_MACROS
|
|
|
|
|
# define __STDC_FORMAT_MACROS 1
|
|
|
|
|
# endif
|
|
|
|
|
# include <inttypes.h>
|
|
|
|
|
#else
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-09-14 04:53:13 +02:00
|
|
|
# include <math.h>
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Evaluate the bool64 the hard way, by evaluating the logic vector
|
|
|
|
|
* and converting it to a bool64.
|
|
|
|
|
*/
|
2008-12-18 17:45:47 +01:00
|
|
|
static int eval_bool64_logic(ivl_expr_t expr)
|
2005-09-14 04:53:13 +02:00
|
|
|
{
|
|
|
|
|
int res;
|
2010-10-22 02:04:56 +02:00
|
|
|
const char*s_flag = "";
|
2005-09-14 04:53:13 +02:00
|
|
|
|
2014-10-24 18:32:32 +02:00
|
|
|
draw_eval_vec4(expr);
|
2005-09-14 04:53:13 +02:00
|
|
|
res = allocate_word();
|
2010-10-22 02:04:56 +02:00
|
|
|
if (ivl_expr_signed(expr))
|
|
|
|
|
s_flag = "/s";
|
|
|
|
|
|
2014-01-05 21:39:52 +01:00
|
|
|
fprintf(vvp_out, " %%ix/vec4%s %d;\n", s_flag, res);
|
2005-09-14 04:53:13 +02:00
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-18 17:45:47 +01:00
|
|
|
static int draw_number_bool64(ivl_expr_t expr)
|
2005-09-14 04:53:13 +02:00
|
|
|
{
|
|
|
|
|
int res;
|
2008-12-18 17:45:47 +01:00
|
|
|
const char*bits = ivl_expr_bits(expr);
|
2005-09-14 04:53:13 +02:00
|
|
|
uint64_t val = 0;
|
2009-02-17 01:44:52 +01:00
|
|
|
unsigned long idx, low, hig;
|
2005-09-14 04:53:13 +02:00
|
|
|
|
2008-12-18 17:45:47 +01:00
|
|
|
for (idx = 0 ; idx < ivl_expr_width(expr) ; idx += 1) {
|
2005-09-14 04:53:13 +02:00
|
|
|
if (bits[idx] == '1')
|
|
|
|
|
val |= 1UL << idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
res = allocate_word();
|
2009-02-17 01:44:52 +01:00
|
|
|
low = val % UINT64_C(0x100000000);
|
|
|
|
|
hig = val / UINT64_C(0x100000000);
|
2011-02-28 04:20:16 +01:00
|
|
|
fprintf(vvp_out, " %%ix/load %d, %lu, %lu;\n", res, low, hig);
|
2005-09-14 04:53:13 +02:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-18 17:45:47 +01:00
|
|
|
int draw_eval_bool64(ivl_expr_t expr)
|
2005-09-14 04:53:13 +02:00
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
|
2008-12-18 17:45:47 +01:00
|
|
|
switch (ivl_expr_type(expr)) {
|
2005-09-14 04:53:13 +02:00
|
|
|
case IVL_EX_NUMBER:
|
2008-12-18 17:45:47 +01:00
|
|
|
res = draw_number_bool64(expr);
|
2005-09-14 04:53:13 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2008-12-18 17:45:47 +01:00
|
|
|
res = eval_bool64_logic(expr);
|
2005-09-14 04:53:13 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|