arith10.cpp revision 12855:588919e0e4aa
16899SN/A/***************************************************************************** 26899SN/A 36899SN/A Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 46899SN/A more contributor license agreements. See the NOTICE file distributed 56899SN/A with this work for additional information regarding copyright ownership. 66899SN/A Accellera licenses this file to you under the Apache License, Version 2.0 76899SN/A (the "License"); you may not use this file except in compliance with the 86899SN/A License. You may obtain a copy of the License at 96899SN/A 106899SN/A http://www.apache.org/licenses/LICENSE-2.0 116899SN/A 126899SN/A Unless required by applicable law or agreed to in writing, software 136899SN/A distributed under the License is distributed on an "AS IS" BASIS, 146899SN/A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 156899SN/A implied. See the License for the specific language governing 166899SN/A permissions and limitations under the License. 176899SN/A 186899SN/A *****************************************************************************/ 196899SN/A 206899SN/A/***************************************************************************** 216899SN/A 226899SN/A arith10.cpp -- 236899SN/A 246899SN/A Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 256899SN/A 266899SN/A *****************************************************************************/ 276899SN/A 286899SN/A/***************************************************************************** 296899SN/A 306899SN/A MODIFICATION LOG - modifiers, enter your name, affiliation, date and 3112564Sgabeblack@google.com changes you are making here. 3213774Sandreas.sandberg@arm.com 3312564Sgabeblack@google.com Name, Affiliation, Date: 346899SN/A Description of Modification: 356899SN/A 366899SN/A *****************************************************************************/ 376899SN/A 386899SN/A#include <stdlib.h> 3911682Sandreas.hansson@arm.com#include "systemc.h" 4011670Sandreas.hansson@arm.com#include "isaac.h" 416899SN/A 4211682Sandreas.hansson@arm.comQTIsaac<8> rng; // Platform independent random number generator. 4311670Sandreas.hansson@arm.com 446899SN/Aint 456899SN/Asc_main( int argc, char* argv[] ) 466899SN/A{ 476899SN/A signed int vali[5] = { 0, 1, -1, 7, -8 }; 486899SN/A signed int valj[5] = { 0, 1, -1, 7, -8 }; 496899SN/A 506899SN/A for (int i = 3; i < 32; ++i) { 5111688Sandreas.hansson@arm.com for (int j = 3; j < 32; ++j) { 526899SN/A cout << "i = " << i << ", j = " << j << endl; 5310524Snilay@cs.wisc.edu 547553SN/A sc_signed x(i); 556899SN/A sc_signed y(j); 566899SN/A sc_signed z(65), q(65); 579365Snilay@cs.wisc.edu 589365Snilay@cs.wisc.edu vali[3] = (1 << (i - 1)) - 1; 599365Snilay@cs.wisc.edu vali[4] = - (1 << (i - 1)); 609365Snilay@cs.wisc.edu 619365Snilay@cs.wisc.edu valj[3] = (1 << (j - 1)) - 1; 629365Snilay@cs.wisc.edu valj[4] = - (1 << (j - 1)); 636899SN/A 646899SN/A for (int ii = 0; ii < 100; ++ii) { 657538SN/A for (int jj = 0; jj < 100; ++jj) { 666899SN/A signed int qi = (ii < 5) ? vali[ii] : (rng.rand() & ((1 << i) - 1)); 677538SN/A signed int qj = (jj < 5) ? valj[jj] : (rng.rand() & ((1 << j) - 1)); 686899SN/A 696899SN/A if (qi & (1 << (i - 1))) { 706899SN/A qi = (qi << (32 - i)) >> (32 - i); 7112564Sgabeblack@google.com } 726899SN/A if (qj & (1 << (j - 1))) { 736899SN/A qj = (qj << (32 - j)) >> (32 - j); 746899SN/A } 757632SBrad.Beckmann@amd.com 766899SN/A x = qi; 777553SN/A y = qj; 787553SN/A z = x * y; 799365Snilay@cs.wisc.edu sc_assert( static_cast<sc_bigint<32> >( z.range(31,0) ) == 807553SN/A (qi * qj) ); 817553SN/A bool s; 829365Snilay@cs.wisc.edu s = ((x < 0) != (y < 0)); 839365Snilay@cs.wisc.edu sc_signed x2(i+1); 849365Snilay@cs.wisc.edu x2 = x; 859365Snilay@cs.wisc.edu if (x < 0) { 867553SN/A x2 = - x; 877553SN/A } 887553SN/A sc_signed y2(j+1); 8912564Sgabeblack@google.com y2 = y; 907553SN/A if (y < 0) { 916899SN/A y2 = - y; 9210524Snilay@cs.wisc.edu } 9310524Snilay@cs.wisc.edu 949870Sandreas.hansson@arm.com sc_unsigned xhi(16), xlo(16); 959870Sandreas.hansson@arm.com sc_unsigned yhi(16), ylo(16); 969870Sandreas.hansson@arm.com sc_unsigned zero(16); 979870Sandreas.hansson@arm.com zero = 0; 989870Sandreas.hansson@arm.com xlo = i > 14 ? x2.range(15,0) : x2.range(i,0); 999870Sandreas.hansson@arm.com xhi = i > 15 ? x2.range(i,16) : zero; 1009870Sandreas.hansson@arm.com ylo = j > 14 ? y2.range(15,0) : y2.range(j,0); 1019793Sakash.bagdia@arm.com yhi = j > 15 ? y2.range(j,16) : zero; 1027553SN/A q = (xlo * ylo) + 10310524Snilay@cs.wisc.edu (xhi * ylo + xlo * yhi) * 65536 + 10410524Snilay@cs.wisc.edu ((xhi * yhi) * 65536) * 65536; 1057553SN/A if (s) 10610519Snilay@cs.wisc.edu q = - q; 1076899SN/A if (z.range(63,0) != q.range(63,0)) { 1089793Sakash.bagdia@arm.com cout << "xlo = " << xlo << endl; 1099870Sandreas.hansson@arm.com cout << "xhi = " << xhi << endl; 1109870Sandreas.hansson@arm.com cout << "ylo = " << ylo << endl; 1119793Sakash.bagdia@arm.com cout << "yhi = " << yhi << endl; 11210120Snilay@cs.wisc.edu sc_assert(false); 1136899SN/A } 11410120Snilay@cs.wisc.edu } 1156899SN/A } 1166899SN/A } 1176899SN/A } 11810524Snilay@cs.wisc.edu return 0; 1196899SN/A} 1206899SN/A