Home | History | Annotate | Line # | Download | only in or1k
      1      1.1  christos /* Tests instructions l.add, l.addc, l.addi and l.addic.
      2      1.1  christos 
      3  1.1.1.3  christos    Copyright (C) 2017-2025 Free Software Foundation, Inc.
      4      1.1  christos 
      5      1.1  christos    This program is free software; you can redistribute it and/or modify
      6      1.1  christos    it under the terms of the GNU General Public License as published by
      7      1.1  christos    the Free Software Foundation; either version 3 of the License, or
      8      1.1  christos    (at your option) any later version.
      9      1.1  christos 
     10      1.1  christos    This program is distributed in the hope that it will be useful,
     11      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13      1.1  christos    GNU General Public License for more details.
     14      1.1  christos 
     15      1.1  christos    You should have received a copy of the GNU General Public License
     16      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17      1.1  christos 
     18      1.1  christos # mach: or1k
     19      1.1  christos # output: report(0x00000001);\n
     20      1.1  christos # output: report(0x00000002);\n
     21      1.1  christos # output: report(0x00000003);\n
     22      1.1  christos # output: report(0x00000000);\n
     23      1.1  christos # output: report(0x00000000);\n
     24      1.1  christos # output: report(0x00000000);\n
     25      1.1  christos # output: \n
     26      1.1  christos # output: report(0x00000001);\n
     27      1.1  christos # output: report(0x00000002);\n
     28      1.1  christos # output: report(0x00000003);\n
     29      1.1  christos # output: report(0x00000000);\n
     30      1.1  christos # output: report(0x00000000);\n
     31      1.1  christos # output: report(0x00000000);\n
     32      1.1  christos # output: \n
     33      1.1  christos # output: report(0xffffffff);\n
     34      1.1  christos # output: report(0xfffffffe);\n
     35      1.1  christos # output: report(0xfffffffd);\n
     36      1.1  christos # output: report(0x00000001);\n
     37      1.1  christos # output: report(0x00000000);\n
     38      1.1  christos # output: report(0x00000000);\n
     39      1.1  christos # output: \n
     40      1.1  christos # output: report(0x40000000);\n
     41      1.1  christos # output: report(0x3fffffff);\n
     42      1.1  christos # output: report(0x7fffffff);\n
     43      1.1  christos # output: report(0x00000000);\n
     44      1.1  christos # output: report(0x00000000);\n
     45      1.1  christos # output: report(0x00000000);\n
     46      1.1  christos # output: \n
     47      1.1  christos # output: report(0x40000000);\n
     48      1.1  christos # output: report(0x40000000);\n
     49      1.1  christos # output: report(0x80000000);\n
     50      1.1  christos # output: report(0x00000000);\n
     51      1.1  christos # output: report(0x00000001);\n
     52      1.1  christos # output: report(0x00000000);\n
     53      1.1  christos # output: \n
     54      1.1  christos # output: report(0xc0000000);\n
     55      1.1  christos # output: report(0xc0000000);\n
     56      1.1  christos # output: report(0x80000000);\n
     57      1.1  christos # output: report(0x00000001);\n
     58      1.1  christos # output: report(0x00000000);\n
     59      1.1  christos # output: report(0x00000000);\n
     60      1.1  christos # output: \n
     61      1.1  christos # output: report(0xbfffffff);\n
     62      1.1  christos # output: report(0xbfffffff);\n
     63      1.1  christos # output: report(0x7ffffffe);\n
     64      1.1  christos # output: report(0x00000001);\n
     65      1.1  christos # output: report(0x00000001);\n
     66      1.1  christos # output: report(0x00000000);\n
     67      1.1  christos # output: \n
     68      1.1  christos # output: report(0x40000000);\n
     69      1.1  christos # output: report(0x40000000);\n
     70      1.1  christos # output: report(0x80000000);\n
     71      1.1  christos # output: report(0x00000000);\n
     72      1.1  christos # output: report(0x00000001);\n
     73      1.1  christos # output: report(0x00000001);\n
     74      1.1  christos # output: \n
     75      1.1  christos # output: report(0xffffffff);\n
     76      1.1  christos # output: report(0xfffffffe);\n
     77      1.1  christos # output: report(0xfffffffd);\n
     78      1.1  christos # output: report(0x00000001);\n
     79      1.1  christos # output: report(0x00000000);\n
     80      1.1  christos # output: report(0x00000000);\n
     81      1.1  christos # output: \n
     82      1.1  christos # output: report(0xbfffffff);\n
     83      1.1  christos # output: report(0xbfffffff);\n
     84      1.1  christos # output: report(0x7ffffffe);\n
     85      1.1  christos # output: report(0x00000001);\n
     86      1.1  christos # output: report(0x00000001);\n
     87      1.1  christos # output: report(0x00000001);\n
     88      1.1  christos # output: \n
     89      1.1  christos # output: report(0x00000001);\n
     90      1.1  christos # output: report(0x00000002);\n
     91      1.1  christos # output: report(0x00000003);\n
     92      1.1  christos # output: report(0x00000000);\n
     93      1.1  christos # output: report(0x00000000);\n
     94      1.1  christos # output: report(0x00000000);\n
     95      1.1  christos # output: \n
     96      1.1  christos # output: report(0xffffffff);\n
     97      1.1  christos # output: report(0xfffffffe);\n
     98      1.1  christos # output: report(0xfffffffd);\n
     99      1.1  christos # output: report(0x00000001);\n
    100      1.1  christos # output: report(0x00000000);\n
    101      1.1  christos # output: report(0x00000000);\n
    102      1.1  christos # output: \n
    103      1.1  christos # output: report(0x40000000);\n
    104      1.1  christos # output: report(0x3fffffff);\n
    105      1.1  christos # output: report(0x7fffffff);\n
    106      1.1  christos # output: report(0x00000000);\n
    107      1.1  christos # output: report(0x00000000);\n
    108      1.1  christos # output: report(0x00000000);\n
    109      1.1  christos # output: \n
    110      1.1  christos # output: report(0x40000000);\n
    111      1.1  christos # output: report(0x3fffffff);\n
    112      1.1  christos # output: report(0x80000000);\n
    113      1.1  christos # output: report(0x00000000);\n
    114      1.1  christos # output: report(0x00000001);\n
    115      1.1  christos # output: report(0x00000000);\n
    116      1.1  christos # output: \n
    117      1.1  christos # output: report(0x40000000);\n
    118      1.1  christos # output: report(0x40000000);\n
    119      1.1  christos # output: report(0x80000000);\n
    120      1.1  christos # output: report(0x00000000);\n
    121      1.1  christos # output: report(0x00000001);\n
    122      1.1  christos # output: report(0x00000000);\n
    123      1.1  christos # output: \n
    124      1.1  christos # output: report(0xffffffff);\n
    125      1.1  christos # output: report(0x00000000);\n
    126      1.1  christos # output: report(0x00000000);\n
    127      1.1  christos # output: report(0x00000001);\n
    128      1.1  christos # output: report(0x00000000);\n
    129      1.1  christos # output: report(0x00000000);\n
    130      1.1  christos # output: \n
    131      1.1  christos # output: report(0x00000000);\n
    132      1.1  christos # output: report(0xffffffff);\n
    133      1.1  christos # output: report(0x00000000);\n
    134      1.1  christos # output: report(0x00000001);\n
    135      1.1  christos # output: report(0x00000000);\n
    136      1.1  christos # output: report(0x00000000);\n
    137      1.1  christos # output: \n
    138      1.1  christos # output: report(0xc0000000);\n
    139      1.1  christos # output: report(0xc0000000);\n
    140      1.1  christos # output: report(0x80000000);\n
    141      1.1  christos # output: report(0x00000001);\n
    142      1.1  christos # output: report(0x00000000);\n
    143      1.1  christos # output: report(0x00000000);\n
    144      1.1  christos # output: \n
    145      1.1  christos # output: report(0xc0000000);\n
    146      1.1  christos # output: report(0xbfffffff);\n
    147      1.1  christos # output: report(0x80000000);\n
    148      1.1  christos # output: report(0x00000001);\n
    149      1.1  christos # output: report(0x00000000);\n
    150      1.1  christos # output: report(0x00000000);\n
    151      1.1  christos # output: \n
    152      1.1  christos # output: report(0xbfffffff);\n
    153      1.1  christos # output: report(0xbfffffff);\n
    154      1.1  christos # output: report(0x7ffffffe);\n
    155      1.1  christos # output: report(0x00000001);\n
    156      1.1  christos # output: report(0x00000001);\n
    157      1.1  christos # output: report(0x00000000);\n
    158      1.1  christos # output: \n
    159      1.1  christos # output: report(0x40000000);\n
    160      1.1  christos # output: report(0x40000000);\n
    161      1.1  christos # output: report(0x80000000);\n
    162      1.1  christos # output: report(0x00000000);\n
    163      1.1  christos # output: report(0x00000001);\n
    164      1.1  christos # output: report(0x00000001);\n
    165      1.1  christos # output: \n
    166      1.1  christos # output: report(0x40000000);\n
    167      1.1  christos # output: report(0x3fffffff);\n
    168      1.1  christos # output: report(0x80000000);\n
    169      1.1  christos # output: report(0x00000000);\n
    170      1.1  christos # output: report(0x00000001);\n
    171      1.1  christos # output: report(0x00000001);\n
    172      1.1  christos # output: \n
    173      1.1  christos # output: report(0xffffffff);\n
    174      1.1  christos # output: report(0xfffffffe);\n
    175      1.1  christos # output: report(0xfffffffd);\n
    176      1.1  christos # output: report(0x00000001);\n
    177      1.1  christos # output: report(0x00000000);\n
    178      1.1  christos # output: report(0x00000000);\n
    179      1.1  christos # output: \n
    180      1.1  christos # output: report(0x00000000);\n
    181      1.1  christos # output: report(0xffffffff);\n
    182      1.1  christos # output: report(0x00000000);\n
    183      1.1  christos # output: report(0x00000001);\n
    184      1.1  christos # output: report(0x00000000);\n
    185      1.1  christos # output: report(0x00000000);\n
    186      1.1  christos # output: \n
    187      1.1  christos # output: report(0xbfffffff);\n
    188      1.1  christos # output: report(0xbfffffff);\n
    189      1.1  christos # output: report(0x7ffffffe);\n
    190      1.1  christos # output: report(0x00000001);\n
    191      1.1  christos # output: report(0x00000001);\n
    192      1.1  christos # output: report(0x00000001);\n
    193      1.1  christos # output: \n
    194      1.1  christos # output: report(0x00000001);\n
    195      1.1  christos # output: report(0x00000002);\n
    196      1.1  christos # output: report(0x00000003);\n
    197      1.1  christos # output: report(0x00000000);\n
    198      1.1  christos # output: report(0x00000000);\n
    199      1.1  christos # output: report(0x00000000);\n
    200      1.1  christos # output: \n
    201      1.1  christos # output: report(0x00000001);\n
    202      1.1  christos # output: report(0x00000002);\n
    203      1.1  christos # output: report(0x00000003);\n
    204      1.1  christos # output: report(0x00000000);\n
    205      1.1  christos # output: report(0x00000000);\n
    206      1.1  christos # output: report(0x00000000);\n
    207      1.1  christos # output: \n
    208      1.1  christos # output: report(0xffffffff);\n
    209      1.1  christos # output: report(0x0000fffe);\n
    210      1.1  christos # output: report(0xfffffffd);\n
    211      1.1  christos # output: report(0x00000001);\n
    212      1.1  christos # output: report(0x00000000);\n
    213      1.1  christos # output: report(0x00000000);\n
    214      1.1  christos # output: \n
    215      1.1  christos # output: report(0x7fff8000);\n
    216      1.1  christos # output: report(0x00007fff);\n
    217      1.1  christos # output: report(0x7fffffff);\n
    218      1.1  christos # output: report(0x00000000);\n
    219      1.1  christos # output: report(0x00000000);\n
    220      1.1  christos # output: report(0x00000000);\n
    221      1.1  christos # output: \n
    222      1.1  christos # output: report(0x7fffc000);\n
    223      1.1  christos # output: report(0x00004000);\n
    224      1.1  christos # output: report(0x80000000);\n
    225      1.1  christos # output: report(0x00000000);\n
    226      1.1  christos # output: report(0x00000001);\n
    227      1.1  christos # output: report(0x00000000);\n
    228      1.1  christos # output: \n
    229      1.1  christos # output: report(0x80008000);\n
    230      1.1  christos # output: report(0x00008000);\n
    231      1.1  christos # output: report(0x80000000);\n
    232      1.1  christos # output: report(0x00000001);\n
    233      1.1  christos # output: report(0x00000000);\n
    234      1.1  christos # output: report(0x00000000);\n
    235      1.1  christos # output: \n
    236      1.1  christos # output: report(0x80007fff);\n
    237      1.1  christos # output: report(0x00008000);\n
    238      1.1  christos # output: report(0x7fffffff);\n
    239      1.1  christos # output: report(0x00000001);\n
    240      1.1  christos # output: report(0x00000001);\n
    241      1.1  christos # output: report(0x00000000);\n
    242      1.1  christos # output: \n
    243      1.1  christos # output: report(0x7fffc000);\n
    244      1.1  christos # output: report(0x00004000);\n
    245      1.1  christos # output: report(0x80000000);\n
    246      1.1  christos # output: report(0x00000000);\n
    247      1.1  christos # output: report(0x00000001);\n
    248      1.1  christos # output: report(0x00000001);\n
    249      1.1  christos # output: \n
    250      1.1  christos # output: report(0xffffffff);\n
    251      1.1  christos # output: report(0x0000fffe);\n
    252      1.1  christos # output: report(0xfffffffd);\n
    253      1.1  christos # output: report(0x00000001);\n
    254      1.1  christos # output: report(0x00000000);\n
    255      1.1  christos # output: report(0x00000000);\n
    256      1.1  christos # output: \n
    257      1.1  christos # output: report(0x80007fff);\n
    258      1.1  christos # output: report(0x00008000);\n
    259      1.1  christos # output: report(0x7fffffff);\n
    260      1.1  christos # output: report(0x00000001);\n
    261      1.1  christos # output: report(0x00000001);\n
    262      1.1  christos # output: report(0x00000001);\n
    263      1.1  christos # output: \n
    264      1.1  christos # output: report(0x00000001);\n
    265      1.1  christos # output: report(0x00000002);\n
    266      1.1  christos # output: report(0x00000003);\n
    267      1.1  christos # output: report(0x00000000);\n
    268      1.1  christos # output: report(0x00000000);\n
    269      1.1  christos # output: report(0x00000000);\n
    270      1.1  christos # output: \n
    271      1.1  christos # output: report(0xffffffff);\n
    272      1.1  christos # output: report(0x0000fffe);\n
    273      1.1  christos # output: report(0xfffffffd);\n
    274      1.1  christos # output: report(0x00000001);\n
    275      1.1  christos # output: report(0x00000000);\n
    276      1.1  christos # output: report(0x00000000);\n
    277      1.1  christos # output: \n
    278      1.1  christos # output: report(0x7fff8000);\n
    279      1.1  christos # output: report(0x00007fff);\n
    280      1.1  christos # output: report(0x7fffffff);\n
    281      1.1  christos # output: report(0x00000000);\n
    282      1.1  christos # output: report(0x00000000);\n
    283      1.1  christos # output: report(0x00000000);\n
    284      1.1  christos # output: \n
    285      1.1  christos # output: report(0x7fff8000);\n
    286      1.1  christos # output: report(0x00007fff);\n
    287      1.1  christos # output: report(0x80000000);\n
    288      1.1  christos # output: report(0x00000000);\n
    289      1.1  christos # output: report(0x00000001);\n
    290      1.1  christos # output: report(0x00000000);\n
    291      1.1  christos # output: \n
    292      1.1  christos # output: report(0x7fffc000);\n
    293      1.1  christos # output: report(0x00004000);\n
    294      1.1  christos # output: report(0x80000000);\n
    295      1.1  christos # output: report(0x00000000);\n
    296      1.1  christos # output: report(0x00000001);\n
    297      1.1  christos # output: report(0x00000000);\n
    298      1.1  christos # output: \n
    299      1.1  christos # output: report(0xffffffff);\n
    300      1.1  christos # output: report(0x00000000);\n
    301      1.1  christos # output: report(0x00000000);\n
    302      1.1  christos # output: report(0x00000001);\n
    303      1.1  christos # output: report(0x00000000);\n
    304      1.1  christos # output: report(0x00000000);\n
    305      1.1  christos # output: \n
    306      1.1  christos # output: report(0x00000000);\n
    307      1.1  christos # output: report(0x0000ffff);\n
    308      1.1  christos # output: report(0x00000000);\n
    309      1.1  christos # output: report(0x00000001);\n
    310      1.1  christos # output: report(0x00000000);\n
    311      1.1  christos # output: report(0x00000000);\n
    312      1.1  christos # output: \n
    313      1.1  christos # output: report(0x80008000);\n
    314      1.1  christos # output: report(0x00008000);\n
    315      1.1  christos # output: report(0x80000000);\n
    316      1.1  christos # output: report(0x00000001);\n
    317      1.1  christos # output: report(0x00000000);\n
    318      1.1  christos # output: report(0x00000000);\n
    319      1.1  christos # output: \n
    320      1.1  christos # output: report(0x80007fff);\n
    321      1.1  christos # output: report(0x00008000);\n
    322      1.1  christos # output: report(0x80000000);\n
    323      1.1  christos # output: report(0x00000001);\n
    324      1.1  christos # output: report(0x00000000);\n
    325      1.1  christos # output: report(0x00000000);\n
    326      1.1  christos # output: \n
    327      1.1  christos # output: report(0x80007fff);\n
    328      1.1  christos # output: report(0x00008000);\n
    329      1.1  christos # output: report(0x7fffffff);\n
    330      1.1  christos # output: report(0x00000001);\n
    331      1.1  christos # output: report(0x00000001);\n
    332      1.1  christos # output: report(0x00000000);\n
    333      1.1  christos # output: \n
    334      1.1  christos # output: report(0x7fffc000);\n
    335      1.1  christos # output: report(0x00004000);\n
    336      1.1  christos # output: report(0x80000000);\n
    337      1.1  christos # output: report(0x00000000);\n
    338      1.1  christos # output: report(0x00000001);\n
    339      1.1  christos # output: report(0x00000001);\n
    340      1.1  christos # output: \n
    341      1.1  christos # output: report(0x7fffc000);\n
    342      1.1  christos # output: report(0x00003fff);\n
    343      1.1  christos # output: report(0x80000000);\n
    344      1.1  christos # output: report(0x00000000);\n
    345      1.1  christos # output: report(0x00000001);\n
    346      1.1  christos # output: report(0x00000001);\n
    347      1.1  christos # output: \n
    348      1.1  christos # output: report(0xffffffff);\n
    349      1.1  christos # output: report(0x0000fffe);\n
    350      1.1  christos # output: report(0xfffffffd);\n
    351      1.1  christos # output: report(0x00000001);\n
    352      1.1  christos # output: report(0x00000000);\n
    353      1.1  christos # output: report(0x00000000);\n
    354      1.1  christos # output: \n
    355      1.1  christos # output: report(0x00000000);\n
    356      1.1  christos # output: report(0x0000ffff);\n
    357      1.1  christos # output: report(0x00000000);\n
    358      1.1  christos # output: report(0x00000001);\n
    359      1.1  christos # output: report(0x00000000);\n
    360      1.1  christos # output: report(0x00000000);\n
    361      1.1  christos # output: \n
    362      1.1  christos # output: report(0x80007fff);\n
    363      1.1  christos # output: report(0x00008000);\n
    364      1.1  christos # output: report(0x7fffffff);\n
    365      1.1  christos # output: report(0x00000001);\n
    366      1.1  christos # output: report(0x00000001);\n
    367      1.1  christos # output: report(0x00000001);\n
    368      1.1  christos # output: \n
    369      1.1  christos # output: exit(0)\n
    370      1.1  christos 
    371      1.1  christos #include "or1k-asm-test-helpers.h"
    372      1.1  christos 
    373      1.1  christos 	STANDARD_TEST_ENVIRONMENT
    374      1.1  christos 
    375      1.1  christos 	.section .exception_vectors
    376      1.1  christos 
    377      1.1  christos 	/* Range exception.  */
    378      1.1  christos 	.org	0xb00
    379      1.1  christos 
    380      1.1  christos 	/* The handling is a bit dubious at present.  We just patch the
    381      1.1  christos 	   instruction with l.nop and restart.  This will go wrong in branch
    382      1.1  christos 	   delay slots.  But we don't have those in this test.  */
    383      1.1  christos 	l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
    384      1.1  christos 	PUSH r2
    385      1.1  christos 	PUSH r3
    386      1.1  christos 	/* Save the address of the instruction that caused the problem.  */
    387      1.1  christos 	MOVE_FROM_SPR r2, SPR_EPCR_BASE
    388      1.1  christos 	LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop  */
    389      1.1  christos 	l.sw	0(r2), r3
    390      1.1  christos 	POP r3
    391      1.1  christos 	POP r2
    392      1.1  christos 	l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
    393      1.1  christos 	l.rfe
    394      1.1  christos 
    395      1.1  christos 	.section .text
    396      1.1  christos start_tests:
    397      1.1  christos 	PUSH LINK_REGISTER_R9
    398      1.1  christos 
    399      1.1  christos 	/* Test l.add  */
    400      1.1  christos 
    401      1.1  christos 	/* Add two small positive numbers  */
    402      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 1, 2
    403      1.1  christos 
    404      1.1  christos 	/* The carry flag should be ignored.  */
    405      1.1  christos 	TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.add, 1, 2
    406      1.1  christos 
    407      1.1  christos 	/* Add two small negative numbers, which should set the carry flag
    408      1.1  christos 	   but not the overflow flag.  */
    409      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, -1, -2
    410      1.1  christos 
    411      1.1  christos 	/* Add two quite large positive numbers.  Should set neither the
    412      1.1  christos 	   overflow nor the carry flag.  */
    413      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0x40000000, \
    414      1.1  christos 	  0x3fffffff
    415      1.1  christos 
    416      1.1  christos 	/* Add two large positive numbers.  Should set the overflow, but
    417      1.1  christos 	   not the carry flag.  */
    418      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0x40000000, \
    419      1.1  christos 	  0x40000000
    420      1.1  christos 
    421      1.1  christos 	/* Add two quite large negative numbers.  Should set the carry, but
    422      1.1  christos 	   not the overflow flag.  */
    423      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, -1073741824, \
    424      1.1  christos 	  -1073741824 /* -1073741824 = 0xC0000000  */
    425      1.1  christos 
    426      1.1  christos 	/* Add two large negative numbers.  Should set both the overflow
    427      1.1  christos 	   and carry flags.  */
    428      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0xbfffffff, \
    429      1.1  christos 	  0xbfffffff
    430      1.1  christos 
    431      1.1  christos 	/* Check that range exceptions are triggered.  */
    432      1.1  christos 
    433      1.1  christos 	SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    434      1.1  christos 
    435      1.1  christos 	/* Check that an overflow alone causes a RANGE Exception.  */
    436      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0x40000000, \
    437      1.1  christos 	  0x40000000
    438      1.1  christos 
    439      1.1  christos 	/* Check that a carry alone does not cause a RANGE Exception.  */
    440      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0xffffffff, \
    441      1.1  christos 	  0xfffffffe
    442      1.1  christos 
    443      1.1  christos 	/* Check that carry and overflow together cause an exception.  */
    444      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.add, 0xbfffffff, \
    445      1.1  christos 	  0xbfffffff
    446      1.1  christos 
    447      1.1  christos 	CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    448      1.1  christos 
    449      1.1  christos 	/* Test l.addc  */
    450      1.1  christos 
    451      1.1  christos 	/* Add two small positive numbers  */
    452      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV,  l.addc, 1, 2
    453      1.1  christos 
    454      1.1  christos 	/* Add two small negative numbers.  Sets the carry flag but not the
    455      1.1  christos 	   overflow flag.  */
    456      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1, -2
    457      1.1  christos 
    458      1.1  christos 	/* Add two quite large positive numbers.  Should set neither the
    459      1.1  christos 	   overflow nor the carry flag.  */
    460      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0x40000000, \
    461      1.1  christos 	  0x3fffffff
    462      1.1  christos 
    463      1.1  christos 	/* Add two quite large positive numbers with a carry in.  Should
    464      1.1  christos 	   set the overflow but not the carry flag.  */
    465      1.1  christos 	TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x40000000, \
    466      1.1  christos 	  0x3fffffff
    467      1.1  christos 
    468      1.1  christos 	/* Add two large positive numbers.  Should set the overflow, but
    469      1.1  christos 	   not the carry flag.  */
    470      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0x40000000, \
    471      1.1  christos 	  0x40000000
    472      1.1  christos 
    473      1.1  christos 	/* Add the largest unsigned value to zero with a carry.  This
    474      1.1  christos 	   potentially can break a simplistic test for carry that does not
    475      1.1  christos 	   consider the carry flag properly.  Do it both ways around.  */
    476      1.1  christos 	TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, -1,  0
    477      1.1  christos 	TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc,  0, -1
    478      1.1  christos 
    479      1.1  christos 	/* Add two quite large negative numbers.  Should set the carry, but
    480      1.1  christos 	   not the overflow flag.  Here -1073741824 is 0xC0000000.  */
    481      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1073741824, \
    482      1.1  christos 	  -1073741824
    483      1.1  christos 
    484      1.1  christos 	/* Add two quite large negative numbers that would overflow, with a
    485      1.1  christos 	   carry that just avoids the overflow.  Should set the carry, but
    486      1.1  christos 	   not the overflow flag.  Here -1073741824 is 0xC0000000 and
    487      1.1  christos 	   -1073741825 is 0xBFFFFFFF.  */
    488      1.1  christos 	TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, -1073741824, \
    489      1.1  christos 	  -1073741825
    490      1.1  christos 
    491      1.1  christos 	/* Add two large negative numbers.  Should set both the overflow
    492      1.1  christos 	   and carry flags.  */
    493      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, -1073741825, \
    494      1.1  christos 	  -1073741825
    495      1.1  christos 
    496      1.1  christos 	/* Check that range exceptions are triggered.  */
    497      1.1  christos 
    498      1.1  christos 	SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    499      1.1  christos 
    500      1.1  christos 	/* Check that an overflow alone causes a RANGE Exception, even when
    501      1.1  christos 	   it is the carry that causes the overflow.  */
    502      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0x40000000, \
    503      1.1  christos 	  0x40000000
    504      1.1  christos 	TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x40000000, \
    505      1.1  christos 	  0x3fffffff
    506      1.1  christos 
    507      1.1  christos 	/* Check that a carry alone does not cause a RANGE Exception, even
    508      1.1  christos 	   when it is the carry that causes the overflow.  */
    509      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0xffffffff, \
    510      1.1  christos 	  0xfffffffe
    511      1.1  christos 	TEST_INST_FF_I32_I32 SPR_SR_CY, SPR_SR_OV, l.addc, 0x00000000, \
    512      1.1  christos 	  0xffffffff
    513      1.1  christos 
    514      1.1  christos 	/* Check that carry and overflow together cause an exception.  */
    515      1.1  christos 	TEST_INST_FF_I32_I32 0, SPR_SR_CY | SPR_SR_OV, l.addc, 0xbfffffff, \
    516      1.1  christos 	  0xbfffffff
    517      1.1  christos 
    518      1.1  christos 	CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    519      1.1  christos 
    520      1.1  christos 	/* Test l.addi  */
    521      1.1  christos 
    522      1.1  christos 	/* Add two small positive numbers  */
    523      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 1, 2
    524      1.1  christos 
    525      1.1  christos 	/* Check carry in is ignored.  */
    526      1.1  christos 	TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addi, 1, 2
    527      1.1  christos 
    528      1.1  christos 	/* Add two small negative numbers.  Sets the carry flag but not the
    529      1.1  christos 	   overflow flag.  */
    530      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0xffffffff, \
    531      1.1  christos 	  0xfffe
    532      1.1  christos 
    533      1.1  christos 	/* Add two quite large positive numbers.  Should set neither the
    534      1.1  christos 	   overflow nor the carry flag.  */
    535      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x7fff8000, \
    536      1.1  christos 	  0x7fff
    537      1.1  christos 
    538      1.1  christos 	/* Add two large positive numbers.  Should set the overflow, but
    539      1.1  christos 	   not the carry flag.  */
    540      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x7fffc000, \
    541      1.1  christos 	  0x4000
    542      1.1  christos 
    543      1.1  christos 	/* Add two quite large negative numbers.  Should set the carry, but
    544      1.1  christos 	   not the overflow flag.  */
    545      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x80008000, \
    546      1.1  christos 	  0x8000
    547      1.1  christos 
    548      1.1  christos 	/* Add two large negative numbers.  Should set both the overflow
    549      1.1  christos 	   and carry flags.  */
    550      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x80007fff, \
    551      1.1  christos 	  0x8000
    552      1.1  christos 
    553      1.1  christos 	/* Check that range exceptions are triggered.  */
    554      1.1  christos 
    555      1.1  christos 	SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    556      1.1  christos 
    557      1.1  christos 	/* Check that an overflow alone causes a RANGE Exception.  */
    558      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x7fffc000, \
    559      1.1  christos 	  0x4000
    560      1.1  christos 
    561      1.1  christos 	/* Check that a carry alone does not cause a RANGE Exception.  */
    562      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0xffffffff, \
    563      1.1  christos 	  0xfffe
    564      1.1  christos 
    565      1.1  christos 	/* Check that carry and overflow together cause an exception.  */
    566      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addi, 0x80007fff, \
    567      1.1  christos 	  0x8000
    568      1.1  christos 
    569      1.1  christos 	CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    570      1.1  christos 
    571      1.1  christos 	/* Test l.addi */
    572      1.1  christos 
    573      1.1  christos 	/* Add two small positive numbers  */
    574      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 1, 2
    575      1.1  christos 
    576      1.1  christos 	/* Add two small negative numbers.  Sets the carry flag but not the
    577      1.1  christos 	   overflow flag.  */
    578      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0xffffffff, \
    579      1.1  christos 	  0xfffe
    580      1.1  christos 
    581      1.1  christos 	/* Add two quite large positive numbers.  Should set neither the
    582      1.1  christos 	   overflow nor the carry flag.  */
    583      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x7fff8000, \
    584      1.1  christos 	  0x7fff
    585      1.1  christos 
    586      1.1  christos 	/* Add two quite large positive numbers with a carry in.  Should
    587      1.1  christos 	   set the overflow but not the carry flag.  */
    588      1.1  christos 	TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x7fff8000, 0x7fff
    589      1.1  christos 
    590      1.1  christos 	/* Add two large positive numbers.  Should set the overflow, but
    591      1.1  christos 	   not the carry flag.  */
    592      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x7fffc000, \
    593      1.1  christos 	  0x4000
    594      1.1  christos 
    595      1.1  christos 	/* Add the largest unsigned value to zero with a carry.  This
    596      1.1  christos 	   potentially can break a simplistic test for carry that does not
    597      1.1  christos 	   consider the carry flag properly.  Do it both ways around.  */
    598      1.1  christos 	TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0xffffffff, 0x0000
    599      1.1  christos 	TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x00000000, 0xffff
    600      1.1  christos 
    601      1.1  christos 	/* Add two quite large negative numbers.  Should set the carry, but
    602      1.1  christos 	   not the overflow flag.  */
    603      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x80008000, \
    604      1.1  christos 	  0x8000
    605      1.1  christos 
    606      1.1  christos 	/* Add two quite large negative numbers that would overflow, with a
    607      1.1  christos 	   carry that just avoids the overflow.  This should set the carry,
    608      1.1  christos 	   but not the overflow flag.  */
    609      1.1  christos 	TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x80007fff, 0x8000
    610      1.1  christos 
    611      1.1  christos 	/* Add two large negative numbers.  Should set both the overflow
    612      1.1  christos 	   and carry flags.  */
    613      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x80007fff, \
    614      1.1  christos 	  0x8000
    615      1.1  christos 
    616      1.1  christos 	/* Check that range exceptions are triggered.  */
    617      1.1  christos 
    618      1.1  christos 	SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    619      1.1  christos 
    620      1.1  christos 	/* Check that an overflow alone causes a RANGE Exception, even when
    621      1.1  christos 	   it is the carry that causes the overflow.  */
    622      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x7fffc000, \
    623      1.1  christos 	  0x4000
    624      1.1  christos 	TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x7fffc000, 0x3fff
    625      1.1  christos 
    626      1.1  christos 	/* Check that a carry alone does not cause a RANGE Exception, even
    627      1.1  christos 	   when it is the carry that causes the overflow.  */
    628      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0xffffffff, \
    629      1.1  christos 	  0xfffe
    630      1.1  christos 	TEST_INST_FF_I32_I16 SPR_SR_CY, SPR_SR_OV, l.addic, 0x00000000, 0xffff
    631      1.1  christos 
    632      1.1  christos 	/* Check that carry and overflow together cause an exception.  */
    633      1.1  christos 	TEST_INST_FF_I32_I16 0, SPR_SR_CY | SPR_SR_OV, l.addic, 0x80007fff, \
    634      1.1  christos 	  0x8000
    635      1.1  christos 
    636      1.1  christos 	CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
    637      1.1  christos 
    638      1.1  christos 	POP LINK_REGISTER_R9
    639      1.1  christos 	RETURN_TO_LINK_REGISTER_R9
    640