12SN/A/*
210349Sandreas.hansson@arm.com * Copyright (c) 2014 ARM Limited
310349Sandreas.hansson@arm.com * All rights reserved
410349Sandreas.hansson@arm.com *
510349Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
610349Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
710349Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
810349Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
910349Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
1010349Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
1110349Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
1210349Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
1310349Sandreas.hansson@arm.com *
141762SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
152SN/A * All rights reserved.
162SN/A *
172SN/A * Redistribution and use in source and binary forms, with or without
182SN/A * modification, are permitted provided that the following conditions are
192SN/A * met: redistributions of source code must retain the above copyright
202SN/A * notice, this list of conditions and the following disclaimer;
212SN/A * redistributions in binary form must reproduce the above copyright
222SN/A * notice, this list of conditions and the following disclaimer in the
232SN/A * documentation and/or other materials provided with the distribution;
242SN/A * neither the name of the copyright holders nor the names of its
252SN/A * contributors may be used to endorse or promote products derived from
262SN/A * this software without specific prior written permission.
272SN/A *
282SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert
412665Ssaidi@eecs.umich.edu *          Ali Saidi
4210349Sandreas.hansson@arm.com *          Andreas Hansson
432SN/A */
442SN/A
4511793Sbrandon.potter@amd.com#include "base/random.hh"
4611793Sbrandon.potter@amd.com
4710349Sandreas.hansson@arm.com#include <sstream>
4810349Sandreas.hansson@arm.com
4912334Sgabeblack@google.com#include "base/logging.hh"
505190Ssaidi@eecs.umich.edu#include "sim/serialize.hh"
512SN/A
525190Ssaidi@eecs.umich.eduRandom::Random()
532SN/A{
5410349Sandreas.hansson@arm.com    // default random seed
555190Ssaidi@eecs.umich.edu    init(5489);
562SN/A}
572SN/A
585190Ssaidi@eecs.umich.eduRandom::Random(uint32_t s)
592SN/A{
605190Ssaidi@eecs.umich.edu    init(s);
612SN/A}
622SN/A
635190Ssaidi@eecs.umich.eduRandom::~Random()
641954SN/A{
655190Ssaidi@eecs.umich.edu}
663483Ssaidi@eecs.umich.edu
6710349Sandreas.hansson@arm.comvoid
6810349Sandreas.hansson@arm.comRandom::init(uint32_t s)
695190Ssaidi@eecs.umich.edu{
7010349Sandreas.hansson@arm.com    gen.seed(s);
711954SN/A}
725190Ssaidi@eecs.umich.edu
735190Ssaidi@eecs.umich.eduvoid
7410905Sandreas.sandberg@arm.comRandom::serialize(CheckpointOut &cp) const
755190Ssaidi@eecs.umich.edu{
7610349Sandreas.hansson@arm.com    panic("Currently not used anywhere.\n");
7710349Sandreas.hansson@arm.com
7810349Sandreas.hansson@arm.com    // get the state from the generator
7910349Sandreas.hansson@arm.com    std::ostringstream oss;
8010349Sandreas.hansson@arm.com    oss << gen;
8110349Sandreas.hansson@arm.com    std::string state = oss.str();
8210905Sandreas.sandberg@arm.com    paramOut(cp, "mt_state", state);
835190Ssaidi@eecs.umich.edu}
845190Ssaidi@eecs.umich.edu
855190Ssaidi@eecs.umich.eduvoid
8610905Sandreas.sandberg@arm.comRandom::unserialize(CheckpointIn &cp)
875190Ssaidi@eecs.umich.edu{
8810349Sandreas.hansson@arm.com    panic("Currently not used anywhere.\n");
895190Ssaidi@eecs.umich.edu
9010349Sandreas.hansson@arm.com    // the random generator state did not use to be part of the
9110349Sandreas.hansson@arm.com    // checkpoint state, so be forgiving in the unserialization and
9210349Sandreas.hansson@arm.com    // keep on going if the parameter is not there
9310349Sandreas.hansson@arm.com    std::string state;
9410905Sandreas.sandberg@arm.com    if (optParamIn(cp, "mt_state", state)) {
9510349Sandreas.hansson@arm.com        std::istringstream iss(state);
9610349Sandreas.hansson@arm.com        iss >> gen;
9710349Sandreas.hansson@arm.com    }
985190Ssaidi@eecs.umich.edu}
995190Ssaidi@eecs.umich.edu
1005190Ssaidi@eecs.umich.eduRandom random_mt;
101