Reducing performance cost of asserts
Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
parent
b0d9b994eb
commit
d221e90706
@ -72,21 +72,23 @@ class assertion_failure : public std::runtime_error
|
||||
int line;
|
||||
};
|
||||
|
||||
inline void except_assert_impl(bool expr, const char *message, const char *expr_str, const char *filename, int line)
|
||||
NPNR_NORETURN
|
||||
inline bool assert_fail_impl(const char *message, const char *expr_str, const char *filename, int line)
|
||||
{
|
||||
if (!expr)
|
||||
throw assertion_failure(message, expr_str, filename, line);
|
||||
throw assertion_failure(message, expr_str, filename, line);
|
||||
}
|
||||
|
||||
NPNR_NORETURN
|
||||
inline void assert_false_impl(std::string message, std::string filename, int line)
|
||||
inline bool assert_fail_impl_str(std::string message, const char *expr_str, const char *filename, int line)
|
||||
{
|
||||
throw assertion_failure(message, "false", filename, line);
|
||||
throw assertion_failure(message, expr_str, filename, line);
|
||||
}
|
||||
|
||||
#define NPNR_ASSERT(cond) except_assert_impl((cond), #cond, #cond, __FILE__, __LINE__)
|
||||
#define NPNR_ASSERT_MSG(cond, msg) except_assert_impl((cond), msg, #cond, __FILE__, __LINE__)
|
||||
#define NPNR_ASSERT_FALSE(msg) assert_false_impl(msg, __FILE__, __LINE__)
|
||||
|
||||
#define NPNR_ASSERT(cond) ((void)((cond) || (assert_fail_impl(#cond, #cond, __FILE__, __LINE__))))
|
||||
#define NPNR_ASSERT_MSG(cond, msg) ((void)((cond) || (assert_fail_impl(msg, #cond, __FILE__, __LINE__))))
|
||||
#define NPNR_ASSERT_FALSE(msg) (assert_fail_impl(msg, "false", __FILE__, __LINE__))
|
||||
#define NPNR_ASSERT_FALSE_STR(msg) (assert_fail_impl_str(msg, "false", __FILE__, __LINE__))
|
||||
|
||||
struct BaseCtx;
|
||||
struct Context;
|
||||
|
@ -36,7 +36,7 @@ const ConfigEntryPOD &find_config(const TileInfoPOD &tile, const std::string &na
|
||||
return tile.entries[i];
|
||||
}
|
||||
}
|
||||
NPNR_ASSERT_FALSE("unable to find config bit " + name);
|
||||
NPNR_ASSERT_FALSE_STR("unable to find config bit " + name);
|
||||
}
|
||||
|
||||
std::tuple<int8_t, int8_t, int8_t> get_ieren(const BitstreamInfoPOD &bi, int8_t x, int8_t y, int8_t z)
|
||||
|
Loading…
Reference in New Issue
Block a user