From 23a1ec9f537449f884522ed4def2171a5d37d58d Mon Sep 17 00:00:00 2001 From: Cary R Date: Tue, 13 Apr 2010 10:22:48 -0700 Subject: [PATCH] Fix thread modulus code to sign extend correctly. When the width of a long long match the vector width we do not need to sign extend and using the << operator for this case is undefined. --- vvp/vthread.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/vvp/vthread.cc b/vvp/vthread.cc index c9ce00092..3e150b181 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -3439,11 +3439,13 @@ bool of_MOD_S(vthread_t thr, vvp_code_t cp) if (rv == 0) goto x_out; - /* Sign extend the signed operands. */ - if (lv & (1LL << (cp->number-1))) - lv |= -1LL << cp->number; - if (rv & (1LL << (cp->number-1))) - rv |= -1LL << cp->number; + /* Sign extend the signed operands when needed. */ + if (cp->number < 8*sizeof(long long)) { + if (lv & (1LL << (cp->number-1))) + lv |= -1LL << cp->number; + if (rv & (1LL << (cp->number-1))) + rv |= -1LL << cp->number; + } lv %= rv;