cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

test_mips64r6_bitswap.c (4851B)


      1/*
      2 *  Test program for MIPS64R6 instruction BITSWAP
      3 *
      4 *  Copyright (C) 2019  Wave Computing, Inc.
      5 *  Copyright (C) 2019  Aleksandar Markovic <amarkovic@wavecomp.com>
      6 *
      7 *  This program is free software: you can redistribute it and/or modify
      8 *  it under the terms of the GNU General Public License as published by
      9 *  the Free Software Foundation, either version 2 of the License, or
     10 *  (at your option) any later version.
     11 *
     12 *  This program is distributed in the hope that it will be useful,
     13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *  GNU General Public License for more details.
     16 *
     17 *  You should have received a copy of the GNU General Public License
     18 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
     19 *
     20 */
     21
     22#include <sys/time.h>
     23#include <stdint.h>
     24
     25#include "../../../../include/wrappers_mips64r6.h"
     26#include "../../../../include/test_inputs_64.h"
     27#include "../../../../include/test_utils_64.h"
     28
     29#define TEST_COUNT_TOTAL (PATTERN_INPUTS_64_COUNT + RANDOM_INPUTS_64_COUNT)
     30
     31
     32int32_t main(void)
     33{
     34    char *isa_ase_name = "mips64r6";
     35    char *group_name = "Bit Swap";
     36    char *instruction_name =   "BITSWAP";
     37    int32_t ret;
     38    uint32_t i;
     39    struct timeval start, end;
     40    double elapsed_time;
     41
     42    uint64_t b64_result[TEST_COUNT_TOTAL];
     43    uint64_t b64_expect[TEST_COUNT_TOTAL] = {
     44        0xffffffffffffffffULL,                    /*   0  */
     45        0x0000000000000000ULL,
     46        0x0000000055555555ULL,
     47        0xffffffffaaaaaaaaULL,
     48        0x0000000033333333ULL,
     49        0xffffffffccccccccULL,
     50        0x00000000711cc771ULL,
     51        0xffffffff8ee3388eULL,
     52        0x000000000f0f0f0fULL,                    /*   8  */
     53        0xfffffffff0f0f0f0ULL,
     54        0x00000000071f7cf0ULL,
     55        0xfffffffff8e0830fULL,
     56        0xfffffffff0033ff0ULL,
     57        0x000000000ffcc00fULL,
     58        0x0000000007fc017fULL,
     59        0xfffffffff803fe80ULL,
     60        0xffffffffff00ff00ULL,                    /*  16  */
     61        0x0000000000ff00ffULL,
     62        0xfffffffff01fc07fULL,
     63        0x000000000fe03f80ULL,
     64        0x0000000000ff03f0ULL,
     65        0xffffffffff00fc0fULL,
     66        0x0000000001f07f00ULL,
     67        0xfffffffffe0f80ffULL,
     68        0x000000000f00ff0fULL,                    /*  24  */
     69        0xfffffffff0ff00f0ULL,
     70        0x000000007f00f0ffULL,
     71        0xffffffff80ff0f00ULL,
     72        0xffffffffff0300ffULL,
     73        0x0000000000fcff00ULL,
     74        0xffffffffff1f00f0ULL,
     75        0x0000000000e0ff0fULL,
     76        0xffffffffffff0000ULL,                    /*  32  */
     77        0x000000000000ffffULL,
     78        0xfffffffffcff0700ULL,
     79        0x000000000300f8ffULL,
     80        0xfffffffff0ff3f00ULL,
     81        0x000000000f00c0ffULL,
     82        0xffffffffc0ffff01ULL,
     83        0x000000003f0000feULL,
     84        0x0000000000ffff0fULL,                    /*  40  */
     85        0xffffffffff0000f0ULL,
     86        0x0000000000fcff7fULL,
     87        0xffffffffff030080ULL,
     88        0x0000000000f0ffffULL,
     89        0xffffffffff0f0000ULL,
     90        0x0000000000c0ffffULL,
     91        0xffffffffff3f0000ULL,
     92        0x000000000000ffffULL,                    /*  48  */
     93        0xffffffffffff0000ULL,
     94        0x000000000000fcffULL,
     95        0xffffffffffff0300ULL,
     96        0x000000000000f0ffULL,
     97        0xffffffffffff0f00ULL,
     98        0x000000000000c0ffULL,
     99        0xffffffffffff3f00ULL,
    100        0x00000000000000ffULL,                    /*  56  */
    101        0xffffffffffffff00ULL,
    102        0x00000000000000fcULL,
    103        0xffffffffffffff03ULL,
    104        0x00000000000000f0ULL,
    105        0xffffffffffffff0fULL,
    106        0x00000000000000c0ULL,
    107        0xffffffffffffff3fULL,
    108        0x000000001446aa02ULL,                    /*  64  */
    109        0xffffffffb2c9e310ULL,
    110        0xffffffff9df3d101ULL,
    111        0x000000007a8c4772ULL,
    112        0xffffffffbef5421aULL,
    113        0xffffffffff50749fULL,
    114        0xffffffffa6533d52ULL,
    115        0x000000005965ed41ULL,
    116        0x000000006a756792ULL,                    /*  72  */
    117        0xffffffffa69ba7ebULL,
    118        0xffffffff93d363d8ULL,
    119        0xffffffff8c152675ULL,
    120        0x00000000654a5750ULL,
    121        0xffffffff98c48615ULL,
    122        0x00000000447def39ULL,
    123        0x000000004f9a7bb5ULL,
    124    };
    125
    126    gettimeofday(&start, NULL);
    127
    128    for (i = 0; i < TEST_COUNT_TOTAL; i++) {
    129        if (i < PATTERN_INPUTS_64_COUNT) {
    130            do_mips64r6_BITSWAP(b64_pattern + i, b64_result + i);
    131        } else {
    132            do_mips64r6_BITSWAP(b64_random + (i - PATTERN_INPUTS_64_COUNT),
    133                                b64_result + i);
    134        }
    135    }
    136
    137    gettimeofday(&end, NULL);
    138
    139    elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0;
    140    elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0;
    141
    142    ret = check_results_64(instruction_name, TEST_COUNT_TOTAL, elapsed_time,
    143                           b64_result, b64_expect);
    144
    145    return ret;
    146}