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_msubv_d.c (10661B)


      1/*
      2 *  Test program for MSA instruction MSUBV.D
      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            3 * (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 = "Int Multiply";
     38    char *instruction_name =  "MSUBV.D";
     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        { 0xffffffffffffffffULL, 0xffffffffffffffffULL, },    /*   0  */
     47        { 0xffffffffffffffffULL, 0xffffffffffffffffULL, },
     48        { 0xaaaaaaaaaaaaaaa9ULL, 0xaaaaaaaaaaaaaaa9ULL, },
     49        { 0xfffffffffffffffeULL, 0xfffffffffffffffeULL, },
     50        { 0xcccccccccccccccaULL, 0xcccccccccccccccaULL, },
     51        { 0xfffffffffffffffdULL, 0xfffffffffffffffdULL, },
     52        { 0xe38e38e38e38e38bULL, 0x38e38e38e38e38e0ULL, },
     53        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     54        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },    /*   8  */
     55        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     56        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     57        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     58        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     59        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     60        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     61        { 0xfffffffffffffffcULL, 0xfffffffffffffffcULL, },
     62        { 0xaaaaaaaaaaaaaaa6ULL, 0xaaaaaaaaaaaaaaa6ULL, },    /*  16  */
     63        { 0xaaaaaaaaaaaaaaa6ULL, 0xaaaaaaaaaaaaaaa6ULL, },
     64        { 0x71c71c71c71c71c2ULL, 0x71c71c71c71c71c2ULL, },
     65        { 0x5555555555555550ULL, 0x5555555555555550ULL, },
     66        { 0xddddddddddddddd8ULL, 0xddddddddddddddd8ULL, },
     67        { 0xfffffffffffffffaULL, 0xfffffffffffffffaULL, },
     68        { 0xed097b425ed097aeULL, 0xd097b425ed097b3cULL, },
     69        { 0xaaaaaaaaaaaaaaa4ULL, 0xaaaaaaaaaaaaaaa4ULL, },
     70        { 0xfffffffffffffff9ULL, 0xfffffffffffffff9ULL, },    /*  24  */
     71        { 0xfffffffffffffff9ULL, 0xfffffffffffffff9ULL, },
     72        { 0xe38e38e38e38e387ULL, 0xe38e38e38e38e387ULL, },
     73        { 0x555555555555554eULL, 0x555555555555554eULL, },
     74        { 0x9999999999999992ULL, 0x9999999999999992ULL, },
     75        { 0xaaaaaaaaaaaaaaa3ULL, 0xaaaaaaaaaaaaaaa3ULL, },
     76        { 0xa12f684bda12f67dULL, 0x12f684bda12f6844ULL, },
     77        { 0xfffffffffffffff8ULL, 0xfffffffffffffff8ULL, },
     78        { 0xccccccccccccccc4ULL, 0xccccccccccccccc4ULL, },    /*  32  */
     79        { 0xccccccccccccccc4ULL, 0xccccccccccccccc4ULL, },
     80        { 0x555555555555554cULL, 0x555555555555554cULL, },
     81        { 0x9999999999999990ULL, 0x9999999999999990ULL, },
     82        { 0xa3d70a3d70a3d700ULL, 0xa3d70a3d70a3d700ULL, },
     83        { 0x666666666666665cULL, 0x666666666666665cULL, },
     84        { 0xe93e93e93e93e934ULL, 0x2d82d82d82d82d78ULL, },
     85        { 0x3333333333333328ULL, 0x3333333333333328ULL, },
     86        { 0x666666666666665bULL, 0x666666666666665bULL, },    /*  40  */
     87        { 0x666666666666665bULL, 0x666666666666665bULL, },
     88        { 0x888888888888887dULL, 0x888888888888887dULL, },
     89        { 0x999999999999998eULL, 0x999999999999998eULL, },
     90        { 0x5c28f5c28f5c28eaULL, 0x5c28f5c28f5c28eaULL, },
     91        { 0xccccccccccccccc1ULL, 0xccccccccccccccc1ULL, },
     92        { 0x2d82d82d82d82d77ULL, 0x3e93e93e93e93e88ULL, },
     93        { 0xfffffffffffffff4ULL, 0xfffffffffffffff4ULL, },
     94        { 0xe38e38e38e38e382ULL, 0x38e38e38e38e38d7ULL, },    /*  48  */
     95        { 0xe38e38e38e38e382ULL, 0x38e38e38e38e38d7ULL, },
     96        { 0xd097b425ed097b36ULL, 0x097b425ed097b419ULL, },
     97        { 0xc71c71c71c71c710ULL, 0x71c71c71c71c71baULL, },
     98        { 0x49f49f49f49f49e8ULL, 0x38e38e38e38e38d6ULL, },
     99        { 0xaaaaaaaaaaaaaa9eULL, 0xaaaaaaaaaaaaaa9dULL, },
    100        { 0xf9add3c0ca4587daULL, 0x587e6b74f0329154ULL, },
    101        { 0x8e38e38e38e38e2cULL, 0xe38e38e38e38e380ULL, },
    102        { 0xaaaaaaaaaaaaaa9dULL, 0xaaaaaaaaaaaaaa9cULL, },    /*  56  */
    103        { 0xaaaaaaaaaaaaaa9dULL, 0xaaaaaaaaaaaaaa9cULL, },
    104        { 0x684bda12f684bd93ULL, 0x84bda12f684bda04ULL, },
    105        { 0xc71c71c71c71c70eULL, 0x71c71c71c71c71b8ULL, },
    106        { 0x1111111111111102ULL, 0x7777777777777768ULL, },
    107        { 0xe38e38e38e38e37fULL, 0x38e38e38e38e38d4ULL, },
    108        { 0x781948b0fcd6e9d1ULL, 0xc3f35ba781948b00ULL, },
    109        { 0xfffffffffffffff0ULL, 0xfffffffffffffff0ULL, },
    110        { 0x52ba41969e9c6ff0ULL, 0xcd6802158b677f60ULL, },    /*  64  */
    111        { 0x63129bf5b78505f0ULL, 0x1556f7f61c4e5b90ULL, },
    112        { 0x5a4c8855f350a5f0ULL, 0x6a36586fc42edea0ULL, },
    113        { 0x5e6b001b04d82c70ULL, 0xe819332c365e3f20ULL, },
    114        { 0x6ec35a7a1dc0c270ULL, 0x3008290cc7451b50ULL, },
    115        { 0x37152f411fd35230ULL, 0xc7e3b2957c56b340ULL, },
    116        { 0xcc49f1d861667630ULL, 0x1808e0646811cb90ULL, },
    117        { 0xde8a7f544022c1c0ULL, 0x9886bc9978437610ULL, },
    118        { 0xd5c46bb47bee61c0ULL, 0xed661d132023f920ULL, },    /*  72  */
    119        { 0x6af92e4bbd8185c0ULL, 0x3d8b4ae20bdf1170ULL, },
    120        { 0xe4d44869d87d45c0ULL, 0x6409d23bd9c847e0ULL, },
    121        { 0x6e2e9ce94e99c4c0ULL, 0xc30837db04ed7360ULL, },
    122        { 0x724d14ae60214b40ULL, 0x40eb1297771cd3e0ULL, },
    123        { 0x848da22a3edd96d0ULL, 0xc168eecc874e7e60ULL, },
    124        { 0x0de7f6a9b4fa15d0ULL, 0x2067546bb273a9e0ULL, },
    125        { 0xc233bfd40310460cULL, 0x0d9585bacf54c5e0ULL, },
    126        { 0x061015122724c70cULL, 0x0169d01f7cb17f60ULL, },    /*  80  */
    127        { 0x23dacc726f603aacULL, 0xf3ea8c4eaa8b5ce0ULL, },
    128        { 0xd82df953c25380acULL, 0xba87b7f0f99bbb60ULL, },
    129        { 0x546cb94a0c5e7444ULL, 0x3818c320ce1bdf60ULL, },
    130        { 0xa38f9428761ecf44ULL, 0x63113b9e681b66e0ULL, },
    131        { 0x7dc23fbe59fe7924ULL, 0x156ddd68750e6260ULL, },
    132        { 0x8a17717d36df5b24ULL, 0x36b1f5939596d2e0ULL, },
    133        { 0x7e854cd9a677ce2cULL, 0xf2b6202eb36946e0ULL, },
    134        { 0x246d8d067437a72cULL, 0x04c6347e9c1ff460ULL, },    /*  88  */
    135        { 0xc48a013a554339ccULL, 0xcb81fd31acc4a5e0ULL, },
    136        { 0xb971282c0b508fccULL, 0x20d62d6344ce5060ULL, },
    137        { 0x835f812f0bc6a7a4ULL, 0x17bd6b5a08275460ULL, },
    138        { 0xc0ee1b9557ab4aa4ULL, 0x170471a9d22d5fe0ULL, },
    139        { 0xc6f66d89431f7984ULL, 0x5c6f5a646cad3f60ULL, },
    140        { 0x5ae0b289f6ac0b84ULL, 0x6f9f6bc81fdb6be0ULL, },
    141        { 0x2f584ee03fd2014cULL, 0xa7e34ccbd1bc3fe0ULL, },
    142        { 0x5947927731cb724cULL, 0xf76af1f9a05f4160ULL, },    /*  96  */
    143        { 0x68112ad490e3a34cULL, 0x7f944a22f5d630e0ULL, },
    144        { 0x1cf6705c5faa944cULL, 0x801292d47291e660ULL, },
    145        { 0x5519f2782cb0454cULL, 0x3d691c2dd53919e0ULL, },
    146        { 0xe5c979861aac06ecULL, 0x585247d6e899e160ULL, },
    147        { 0x2450b27896665b8cULL, 0x8276d8ad504f46e0ULL, },
    148        { 0x2716d456a4a5ab2cULL, 0x46e1f3460c71c260ULL, },
    149        { 0x5751460331251dccULL, 0xdc1dc7a4a693abe0ULL, },
    150        { 0x3bf387b7f37473ccULL, 0x8efb4ff7cc92de60ULL, },    /* 104  */
    151        { 0xc3103a3df066c9ccULL, 0x7d3b07351cd59ee0ULL, },
    152        { 0x0d612554557c1fccULL, 0x5dbabfc2ac8ed560ULL, },
    153        { 0x1cd018ef103475ccULL, 0xca277277956f49e0ULL, },
    154        { 0x15d520225c2e79a4ULL, 0x08f2025804e95de0ULL, },
    155        { 0x820f9c65be3ea1acULL, 0x37094edbda6ef1e0ULL, },
    156        { 0x0f18515c62838744ULL, 0xcfbd4b5627d005e0ULL, },
    157        { 0x11d549f26502488cULL, 0x8de999d53cdc99e0ULL, },
    158    };
    159
    160    reset_msa_registers();
    161
    162    gettimeofday(&start, NULL);
    163
    164    for (i = 0; i < PATTERN_INPUTS_SHORT_COUNT; i++) {
    165        for (j = 0; j < PATTERN_INPUTS_SHORT_COUNT; j++) {
    166            do_msa_MSUBV_D(b128_pattern[i], b128_pattern[j],
    167                           b128_result[PATTERN_INPUTS_SHORT_COUNT * i + j]);
    168        }
    169    }
    170
    171    for (i = 0; i < RANDOM_INPUTS_SHORT_COUNT; i++) {
    172        for (j = 0; j < RANDOM_INPUTS_SHORT_COUNT; j++) {
    173            do_msa_MSUBV_D(b128_random[i], b128_random[j],
    174                           b128_result[((PATTERN_INPUTS_SHORT_COUNT) *
    175                                        (PATTERN_INPUTS_SHORT_COUNT)) +
    176                                       RANDOM_INPUTS_SHORT_COUNT * i + j]);
    177        }
    178    }
    179
    180    for (i = 0; i < RANDOM_INPUTS_SHORT_COUNT; i++) {
    181        for (j = 0; j < RANDOM_INPUTS_SHORT_COUNT; j++) {
    182            do_msa_MSUBV_D__DDT(b128_random[i], b128_random[j],
    183                                b128_result[
    184                                    ((PATTERN_INPUTS_SHORT_COUNT) *
    185                                     (PATTERN_INPUTS_SHORT_COUNT)) +
    186                                    ((RANDOM_INPUTS_SHORT_COUNT) *
    187                                     (RANDOM_INPUTS_SHORT_COUNT)) +
    188                                    RANDOM_INPUTS_SHORT_COUNT * i + j]);
    189        }
    190    }
    191
    192    for (i = 0; i < RANDOM_INPUTS_SHORT_COUNT; i++) {
    193        for (j = 0; j < RANDOM_INPUTS_SHORT_COUNT; j++) {
    194            do_msa_MSUBV_D__DSD(b128_random[i], b128_random[j],
    195                                b128_result[
    196                                    ((PATTERN_INPUTS_SHORT_COUNT) *
    197                                     (PATTERN_INPUTS_SHORT_COUNT)) +
    198                                    (2 * (RANDOM_INPUTS_SHORT_COUNT) *
    199                                     (RANDOM_INPUTS_SHORT_COUNT)) +
    200                                    RANDOM_INPUTS_SHORT_COUNT * i + j]);
    201        }
    202    }
    203
    204    gettimeofday(&end, NULL);
    205
    206    elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0;
    207    elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0;
    208
    209    ret = check_results_128(isa_ase_name, group_name, instruction_name,
    210                            TEST_COUNT_TOTAL, elapsed_time,
    211                            &b128_result[0][0], &b128_expect[0][0]);
    212
    213    return ret;
    214}