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


      1/*
      2 *  Test program for MSA instruction SLL.H
      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.H";
     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        { 0x8000800080008000ULL, 0x8000800080008000ULL, },    /*   0  */
     47        { 0xffffffffffffffffULL, 0xffffffffffffffffULL, },
     48        { 0xfc00fc00fc00fc00ULL, 0xfc00fc00fc00fc00ULL, },
     49        { 0xffe0ffe0ffe0ffe0ULL, 0xffe0ffe0ffe0ffe0ULL, },
     50        { 0xf000f000f000f000ULL, 0xf000f000f000f000ULL, },
     51        { 0xfff8fff8fff8fff8ULL, 0xfff8fff8fff8fff8ULL, },
     52        { 0xc000fff8ff00c000ULL, 0xfff8ff00c000fff8ULL, },
     53        { 0xfffef000ff80fffeULL, 0xf000ff80fffef000ULL, },
     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        { 0xa800a800a800a800ULL, 0xa800a800a800a800ULL, },
     65        { 0x5540554055405540ULL, 0x5540554055405540ULL, },
     66        { 0xa000a000a000a000ULL, 0xa000a000a000a000ULL, },
     67        { 0x5550555055505550ULL, 0x5550555055505550ULL, },
     68        { 0x80005550aa008000ULL, 0x5550aa0080005550ULL, },
     69        { 0x5554a00055005554ULL, 0xa00055005554a000ULL, },
     70        { 0x8000800080008000ULL, 0x8000800080008000ULL, },    /*  24  */
     71        { 0x5555555555555555ULL, 0x5555555555555555ULL, },
     72        { 0x5400540054005400ULL, 0x5400540054005400ULL, },
     73        { 0xaaa0aaa0aaa0aaa0ULL, 0xaaa0aaa0aaa0aaa0ULL, },
     74        { 0x5000500050005000ULL, 0x5000500050005000ULL, },
     75        { 0xaaa8aaa8aaa8aaa8ULL, 0xaaa8aaa8aaa8aaa8ULL, },
     76        { 0x4000aaa855004000ULL, 0xaaa855004000aaa8ULL, },
     77        { 0xaaaa5000aa80aaaaULL, 0x5000aa80aaaa5000ULL, },
     78        { 0x0000000000000000ULL, 0x0000000000000000ULL, },    /*  32  */
     79        { 0xccccccccccccccccULL, 0xccccccccccccccccULL, },
     80        { 0x3000300030003000ULL, 0x3000300030003000ULL, },
     81        { 0x9980998099809980ULL, 0x9980998099809980ULL, },
     82        { 0xc000c000c000c000ULL, 0xc000c000c000c000ULL, },
     83        { 0x6660666066606660ULL, 0x6660666066606660ULL, },
     84        { 0x00006660cc000000ULL, 0x6660cc0000006660ULL, },
     85        { 0x9998c00066009998ULL, 0xc00066009998c000ULL, },
     86        { 0x8000800080008000ULL, 0x8000800080008000ULL, },    /*  40  */
     87        { 0x3333333333333333ULL, 0x3333333333333333ULL, },
     88        { 0xcc00cc00cc00cc00ULL, 0xcc00cc00cc00cc00ULL, },
     89        { 0x6660666066606660ULL, 0x6660666066606660ULL, },
     90        { 0x3000300030003000ULL, 0x3000300030003000ULL, },
     91        { 0x9998999899989998ULL, 0x9998999899989998ULL, },
     92        { 0xc00099983300c000ULL, 0x99983300c0009998ULL, },
     93        { 0x6666300099806666ULL, 0x3000998066663000ULL, },
     94        { 0x0000800000000000ULL, 0x8000000000008000ULL, },    /*  48  */
     95        { 0xe38e38e38e38e38eULL, 0x38e38e38e38e38e3ULL, },
     96        { 0x38008c00e0003800ULL, 0x8c00e00038008c00ULL, },
     97        { 0x71c01c60c70071c0ULL, 0x1c60c70071c01c60ULL, },
     98        { 0xe00030008000e000ULL, 0x30008000e0003000ULL, },
     99        { 0x1c70c71871c01c70ULL, 0xc71871c01c70c718ULL, },
    100        { 0x8000c71838008000ULL, 0xc71838008000c718ULL, },
    101        { 0xc71c30001c00c71cULL, 0x30001c00c71c3000ULL, },
    102        { 0x8000000080008000ULL, 0x0000800080000000ULL, },    /*  56  */
    103        { 0x1c71c71c71c71c71ULL, 0xc71c71c71c71c71cULL, },
    104        { 0xc40070001c00c400ULL, 0x70001c00c4007000ULL, },
    105        { 0x8e20e38038e08e20ULL, 0xe38038e08e20e380ULL, },
    106        { 0x1000c00070001000ULL, 0xc00070001000c000ULL, },
    107        { 0xe38838e08e38e388ULL, 0x38e08e38e38838e0ULL, },
    108        { 0x400038e0c7004000ULL, 0x38e0c700400038e0ULL, },
    109        { 0x38e2c000e38038e2ULL, 0xc000e38038e2c000ULL, },
    110        { 0xa800c000a1885540ULL, 0xb3808000d800c000ULL, },    /*  64  */
    111        { 0x8000366043104000ULL, 0xb38078008000c000ULL, },
    112        { 0xa800300000005540ULL, 0x67000000d80000c0ULL, },
    113        { 0x0000800050c40000ULL, 0x96ce5e00f9ecb00cULL, },
    114        { 0xf8003000364cc708ULL, 0x7b808000f800c000ULL, },
    115        { 0x800003186c980800ULL, 0x7b8068008000c000ULL, },
    116        { 0xf8008c008000c708ULL, 0xf7000000f8002fc0ULL, },
    117        { 0x000060009b260000ULL, 0x25ee1a0054fc52fcULL, },
    118        { 0x6800a000e73c8b80ULL, 0xec00c00058004000ULL, },    /*  72  */
    119        { 0x80007550ce788000ULL, 0xec00fc0080004000ULL, },
    120        { 0x6800a80080008b80ULL, 0xd800800058005140ULL, },
    121        { 0x00004000739e0000ULL, 0x4fb0ff00acac2514ULL, },
    122        { 0x3c00d00078c4e24eULL, 0xf880000010000000ULL, },
    123        { 0xc000b268f1884e00ULL, 0xf880600000000000ULL, },
    124        { 0x3c0034008000e24eULL, 0xf100000010002a00ULL, },
    125        { 0x8000a000bc628000ULL, 0x1be2d800a508e2a0ULL, },
    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_H(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_H(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}