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_msa_sll_w.c (7519B)


      1/*
      2 *  Test program for MSA instruction SLL.W
      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_msa.h"
     26#include "../../../../include/test_inputs_128.h"
     27#include "../../../../include/test_utils_128.h"
     28
     29#define TEST_COUNT_TOTAL (                                                \
     30            (PATTERN_INPUTS_SHORT_COUNT) * (PATTERN_INPUTS_SHORT_COUNT) + \
     31            (RANDOM_INPUTS_SHORT_COUNT) * (RANDOM_INPUTS_SHORT_COUNT))
     32
     33
     34int32_t main(void)
     35{
     36    char *isa_ase_name = "MSA";
     37    char *group_name = "Shift";
     38    char *instruction_name =  "SLL.W";
     39    int32_t ret;
     40    uint32_t i, j;
     41    struct timeval start, end;
     42    double elapsed_time;
     43
     44    uint64_t b128_result[TEST_COUNT_TOTAL][2];
     45    uint64_t b128_expect[TEST_COUNT_TOTAL][2] = {
     46        { 0x8000000080000000ULL, 0x8000000080000000ULL, },    /*   0  */
     47        { 0xffffffffffffffffULL, 0xffffffffffffffffULL, },
     48        { 0xfffffc00fffffc00ULL, 0xfffffc00fffffc00ULL, },
     49        { 0xffe00000ffe00000ULL, 0xffe00000ffe00000ULL, },
     50        { 0xfffff000fffff000ULL, 0xfffff000fffff000ULL, },
     51        { 0xfff80000fff80000ULL, 0xfff80000fff80000ULL, },
     52        { 0xfffffff8ffffc000ULL, 0xff000000fffffff8ULL, },
     53        { 0xf0000000fffe0000ULL, 0xffffff80f0000000ULL, },
     54        { 0x0000000000000000ULL, 0x0000000000000000ULL, },    /*   8  */
     55        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     56        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     57        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     58        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     59        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     60        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     61        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     62        { 0x0000000000000000ULL, 0x0000000000000000ULL, },    /*  16  */
     63        { 0xaaaaaaaaaaaaaaaaULL, 0xaaaaaaaaaaaaaaaaULL, },
     64        { 0xaaaaa800aaaaa800ULL, 0xaaaaa800aaaaa800ULL, },
     65        { 0x5540000055400000ULL, 0x5540000055400000ULL, },
     66        { 0xaaaaa000aaaaa000ULL, 0xaaaaa000aaaaa000ULL, },
     67        { 0x5550000055500000ULL, 0x5550000055500000ULL, },
     68        { 0x55555550aaaa8000ULL, 0xaa00000055555550ULL, },
     69        { 0xa000000055540000ULL, 0x55555500a0000000ULL, },
     70        { 0x8000000080000000ULL, 0x8000000080000000ULL, },    /*  24  */
     71        { 0x5555555555555555ULL, 0x5555555555555555ULL, },
     72        { 0x5555540055555400ULL, 0x5555540055555400ULL, },
     73        { 0xaaa00000aaa00000ULL, 0xaaa00000aaa00000ULL, },
     74        { 0x5555500055555000ULL, 0x5555500055555000ULL, },
     75        { 0xaaa80000aaa80000ULL, 0xaaa80000aaa80000ULL, },
     76        { 0xaaaaaaa855554000ULL, 0x55000000aaaaaaa8ULL, },
     77        { 0x50000000aaaa0000ULL, 0xaaaaaa8050000000ULL, },
     78        { 0x0000000000000000ULL, 0x0000000000000000ULL, },    /*  32  */
     79        { 0xccccccccccccccccULL, 0xccccccccccccccccULL, },
     80        { 0x3333300033333000ULL, 0x3333300033333000ULL, },
     81        { 0x9980000099800000ULL, 0x9980000099800000ULL, },
     82        { 0xccccc000ccccc000ULL, 0xccccc000ccccc000ULL, },
     83        { 0x6660000066600000ULL, 0x6660000066600000ULL, },
     84        { 0x6666666033330000ULL, 0xcc00000066666660ULL, },
     85        { 0xc000000099980000ULL, 0x66666600c0000000ULL, },
     86        { 0x8000000080000000ULL, 0x8000000080000000ULL, },    /*  40  */
     87        { 0x3333333333333333ULL, 0x3333333333333333ULL, },
     88        { 0xcccccc00cccccc00ULL, 0xcccccc00cccccc00ULL, },
     89        { 0x6660000066600000ULL, 0x6660000066600000ULL, },
     90        { 0x3333300033333000ULL, 0x3333300033333000ULL, },
     91        { 0x9998000099980000ULL, 0x9998000099980000ULL, },
     92        { 0x99999998ccccc000ULL, 0x3300000099999998ULL, },
     93        { 0x3000000066660000ULL, 0x9999998030000000ULL, },
     94        { 0x8000000000000000ULL, 0x0000000080000000ULL, },    /*  48  */
     95        { 0xe38e38e38e38e38eULL, 0x38e38e38e38e38e3ULL, },
     96        { 0x38e38c00e38e3800ULL, 0x8e38e00038e38c00ULL, },
     97        { 0x1c60000071c00000ULL, 0xc70000001c600000ULL, },
     98        { 0xe38e30008e38e000ULL, 0x38e38000e38e3000ULL, },
     99        { 0xc71800001c700000ULL, 0x71c00000c7180000ULL, },
    100        { 0x1c71c71838e38000ULL, 0x380000001c71c718ULL, },
    101        { 0x30000000c71c0000ULL, 0x71c71c0030000000ULL, },
    102        { 0x0000000080000000ULL, 0x8000000000000000ULL, },    /*  56  */
    103        { 0x1c71c71c71c71c71ULL, 0xc71c71c71c71c71cULL, },
    104        { 0xc71c70001c71c400ULL, 0x71c71c00c71c7000ULL, },
    105        { 0xe38000008e200000ULL, 0x38e00000e3800000ULL, },
    106        { 0x1c71c00071c71000ULL, 0xc71c70001c71c000ULL, },
    107        { 0x38e00000e3880000ULL, 0x8e38000038e00000ULL, },
    108        { 0xe38e38e0c71c4000ULL, 0xc7000000e38e38e0ULL, },
    109        { 0xc000000038e20000ULL, 0x8e38e380c0000000ULL, },
    110        { 0xae6cc00028625540ULL, 0x80000000bb00c000ULL, },    /*  64  */
    111        { 0x4357366062554000ULL, 0x78000000c0000000ULL, },
    112        { 0xab9b300028625540ULL, 0x0000000000c00000ULL, },
    113        { 0x5cd9800095500000ULL, 0x5e000000fe7bb00cULL, },
    114        { 0xe00630004d93c708ULL, 0x80000000f52fc000ULL, },
    115        { 0xddf0031893c70800ULL, 0x68000000c0000000ULL, },
    116        { 0xf8018c004d93c708ULL, 0x000000002fc00000ULL, },
    117        { 0xc00c6000f1c20000ULL, 0x1a000000153f52fcULL, },
    118        { 0xaaeaa000b9cf8b80ULL, 0xc0000000b2514000ULL, },    /*  72  */
    119        { 0x62d57550cf8b8000ULL, 0xfc00000040000000ULL, },
    120        { 0x6abaa800b9cf8b80ULL, 0x8000000051400000ULL, },
    121        { 0x55d54000e2e00000ULL, 0xff000000ab2b2514ULL, },
    122        { 0xf164d0005e31e24eULL, 0x000000002e2a0000ULL, },
    123        { 0x8278b26831e24e00ULL, 0x6000000000000000ULL, },
    124        { 0x3c5934005e31e24eULL, 0x000000002a000000ULL, },
    125        { 0xe2c9a00078938000ULL, 0xd8000000a942e2a0ULL, },
    126    };
    127
    128    reset_msa_registers();
    129
    130    gettimeofday(&start, NULL);
    131
    132    for (i = 0; i < PATTERN_INPUTS_SHORT_COUNT; i++) {
    133        for (j = 0; j < PATTERN_INPUTS_SHORT_COUNT; j++) {
    134            do_msa_SLL_W(b128_pattern[i], b128_pattern[j],
    135                         b128_result[PATTERN_INPUTS_SHORT_COUNT * i + j]);
    136        }
    137    }
    138
    139    for (i = 0; i < RANDOM_INPUTS_SHORT_COUNT; i++) {
    140        for (j = 0; j < RANDOM_INPUTS_SHORT_COUNT; j++) {
    141            do_msa_SLL_W(b128_random[i], b128_random[j],
    142                         b128_result[((PATTERN_INPUTS_SHORT_COUNT) *
    143                                      (PATTERN_INPUTS_SHORT_COUNT)) +
    144                                     RANDOM_INPUTS_SHORT_COUNT * i + j]);
    145        }
    146    }
    147
    148    gettimeofday(&end, NULL);
    149
    150    elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0;
    151    elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0;
    152
    153    ret = check_results_128(isa_ase_name, group_name, instruction_name,
    154                            TEST_COUNT_TOTAL, elapsed_time,
    155                            &b128_result[0][0], &b128_expect[0][0]);
    156
    157    return ret;
    158}