Home | History | Annotate | Line # | Download | only in common
cgen-ops.h revision 1.3.2.1
      1      1.1  christos /* Semantics ops support for CGEN-based simulators.
      2      1.3  christos    Copyright (C) 1996-2015 Free Software Foundation, Inc.
      3      1.1  christos    Contributed by Cygnus Solutions.
      4      1.1  christos 
      5      1.1  christos This file is part of the GNU Simulators.
      6      1.1  christos 
      7      1.1  christos This program is free software; you can redistribute it and/or modify
      8      1.1  christos it under the terms of the GNU General Public License as published by
      9      1.1  christos the Free Software Foundation; either version 3 of the License, or
     10      1.1  christos (at your option) any later version.
     11      1.1  christos 
     12      1.1  christos This program is distributed in the hope that it will be useful,
     13      1.1  christos but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1  christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1  christos GNU General Public License for more details.
     16      1.1  christos 
     17      1.1  christos You should have received a copy of the GNU General Public License
     18      1.1  christos along with this program.  If not, see <http://www.gnu.org/licenses/>.
     19      1.1  christos 
     20      1.1  christos */
     21      1.1  christos 
     22      1.1  christos #ifndef CGEN_SEM_OPS_H
     23      1.1  christos #define CGEN_SEM_OPS_H
     24      1.1  christos 
     25      1.1  christos #include <assert.h>
     26      1.1  christos 
     27  1.3.2.1  pgoyette /* TODO: This should get moved into sim-inline.h.  */
     28      1.1  christos #if defined (__GNUC__) && ! defined (SEMOPS_DEFINE_INLINE)
     29      1.1  christos #define SEMOPS_DEFINE_INLINE
     30  1.3.2.1  pgoyette #define SEMOPS_INLINE EXTERN_INLINE
     31      1.1  christos #else
     32      1.1  christos #define SEMOPS_INLINE
     33      1.1  christos #endif
     34      1.1  christos 
     35      1.1  christos /* Semantic operations.
     36      1.1  christos    At one point this file was machine generated.  Maybe it will be again.  */
     37      1.1  christos 
     38      1.1  christos /* TODO: Lazy encoding/decoding of fp values.  */
     39      1.1  christos 
     40      1.1  christos /* These don't really have a mode.  */
     41      1.1  christos #define ANDIF(x, y) ((x) && (y))
     42      1.1  christos #define ORIF(x, y) ((x) || (y))
     43      1.1  christos 
     44      1.1  christos #define SUBBI(x, y) ((x) - (y))
     45      1.1  christos #define ANDBI(x, y) ((x) & (y))
     46      1.1  christos #define ORBI(x, y) ((x) | (y))
     47      1.1  christos #define XORBI(x, y) ((x) ^ (y))
     48      1.1  christos #define NEGBI(x) (- (x))
     49      1.1  christos #define NOTBI(x) (! (BI) (x))
     50      1.1  christos #define INVBI(x) (~ (x))
     51      1.1  christos #define EQBI(x, y) ((BI) (x) == (BI) (y))
     52      1.1  christos #define NEBI(x, y) ((BI) (x) != (BI) (y))
     53      1.1  christos #define LTBI(x, y) ((BI) (x) < (BI) (y))
     54      1.1  christos #define LEBI(x, y) ((BI) (x) <= (BI) (y))
     55      1.1  christos #define GTBI(x, y) ((BI) (x) > (BI) (y))
     56      1.1  christos #define GEBI(x, y) ((BI) (x) >= (BI) (y))
     57      1.1  christos #define LTUBI(x, y) ((BI) (x) < (BI) (y))
     58      1.1  christos #define LEUBI(x, y) ((BI) (x) <= (BI) (y))
     59      1.1  christos #define GTUBI(x, y) ((BI) (x) > (BI) (y))
     60      1.1  christos #define GEUBI(x, y) ((BI) (x) >= (BI) (y))
     61      1.1  christos 
     62      1.1  christos #define ADDQI(x, y) ((QI) ((UQI) (x) + (UQI) (y)))
     64      1.1  christos #define SUBQI(x, y) ((QI) ((UQI) (x) - (UQI) (y)))
     65      1.1  christos #define MULQI(x, y) ((QI) ((UQI) (x) * (UQI) (y)))
     66      1.1  christos #define DIVQI(x, y) ((QI) (x) / (QI) (y))
     67      1.1  christos #define UDIVQI(x, y) ((UQI) (x) / (UQI) (y))
     68      1.1  christos #define MODQI(x, y) ((QI) (x) % (QI) (y))
     69      1.1  christos #define UMODQI(x, y) ((UQI) (x) % (UQI) (y))
     70      1.1  christos #define SRAQI(x, y) ((QI) (x) >> (y))
     71      1.1  christos #define SRLQI(x, y) ((UQI) (x) >> (y))
     72      1.1  christos #define SLLQI(x, y) ((UQI) (x) << (y))
     73      1.1  christos extern QI RORQI (QI, int);
     74      1.1  christos extern QI ROLQI (QI, int);
     75      1.1  christos #define ANDQI(x, y) ((x) & (y))
     76      1.1  christos #define ORQI(x, y) ((x) | (y))
     77      1.1  christos #define XORQI(x, y) ((x) ^ (y))
     78      1.1  christos #define NEGQI(x) ((QI) (- (UQI) (x)))
     79      1.1  christos #define NOTQI(x) (! (QI) (x))
     80      1.1  christos #define INVQI(x) (~ (x))
     81      1.1  christos #define ABSQI(x) ((QI) ((QI) (x) < 0 ? -(UQI) (x) : (UQI) (x)))
     82      1.1  christos #define EQQI(x, y) ((QI) (x) == (QI) (y))
     83      1.1  christos #define NEQI(x, y) ((QI) (x) != (QI) (y))
     84      1.1  christos #define LTQI(x, y) ((QI) (x) < (QI) (y))
     85      1.1  christos #define LEQI(x, y) ((QI) (x) <= (QI) (y))
     86      1.1  christos #define GTQI(x, y) ((QI) (x) > (QI) (y))
     87      1.1  christos #define GEQI(x, y) ((QI) (x) >= (QI) (y))
     88      1.1  christos #define LTUQI(x, y) ((UQI) (x) < (UQI) (y))
     89      1.1  christos #define LEUQI(x, y) ((UQI) (x) <= (UQI) (y))
     90      1.1  christos #define GTUQI(x, y) ((UQI) (x) > (UQI) (y))
     91      1.1  christos #define GEUQI(x, y) ((UQI) (x) >= (UQI) (y))
     92      1.1  christos 
     93      1.1  christos #define ADDHI(x, y) ((HI) ((UHI) (x) + (UHI) (y)))
     95      1.1  christos #define SUBHI(x, y) ((HI) ((UHI) (x) - (UHI) (y)))
     96      1.1  christos #define MULHI(x, y) ((HI) ((UHI) (x) * (UHI) (y)))
     97      1.1  christos #define DIVHI(x, y) ((HI) (x) / (HI) (y))
     98      1.1  christos #define UDIVHI(x, y) ((UHI) (x) / (UHI) (y))
     99      1.1  christos #define MODHI(x, y) ((HI) (x) % (HI) (y))
    100      1.1  christos #define UMODHI(x, y) ((UHI) (x) % (UHI) (y))
    101      1.1  christos #define SRAHI(x, y) ((HI) (x) >> (y))
    102      1.1  christos #define SRLHI(x, y) ((UHI) (x) >> (y))
    103      1.1  christos #define SLLHI(x, y) ((UHI) (x) << (y))
    104      1.1  christos extern HI RORHI (HI, int);
    105      1.1  christos extern HI ROLHI (HI, int);
    106      1.1  christos #define ANDHI(x, y) ((x) & (y))
    107      1.1  christos #define ORHI(x, y) ((x) | (y))
    108      1.1  christos #define XORHI(x, y) ((x) ^ (y))
    109      1.1  christos #define NEGHI(x) ((HI) (- (UHI) (x)))
    110      1.1  christos #define NOTHI(x) (! (HI) (x))
    111      1.1  christos #define INVHI(x) (~ (x))
    112      1.1  christos #define ABSHI(x) ((HI) ((HI) (x) < 0 ? -(UHI) (x) : (UHI) (x)))
    113      1.1  christos #define EQHI(x, y) ((HI) (x) == (HI) (y))
    114      1.1  christos #define NEHI(x, y) ((HI) (x) != (HI) (y))
    115      1.1  christos #define LTHI(x, y) ((HI) (x) < (HI) (y))
    116      1.1  christos #define LEHI(x, y) ((HI) (x) <= (HI) (y))
    117      1.1  christos #define GTHI(x, y) ((HI) (x) > (HI) (y))
    118      1.1  christos #define GEHI(x, y) ((HI) (x) >= (HI) (y))
    119      1.1  christos #define LTUHI(x, y) ((UHI) (x) < (UHI) (y))
    120      1.1  christos #define LEUHI(x, y) ((UHI) (x) <= (UHI) (y))
    121      1.1  christos #define GTUHI(x, y) ((UHI) (x) > (UHI) (y))
    122      1.1  christos #define GEUHI(x, y) ((UHI) (x) >= (UHI) (y))
    123      1.1  christos 
    124      1.1  christos #define ADDSI(x, y) ((SI) ((USI) (x) + (USI) (y)))
    126      1.1  christos #define SUBSI(x, y) ((SI) ((USI) (x) - (USI) (y)))
    127      1.1  christos #define MULSI(x, y) ((SI) ((USI) (x) * (USI) (y)))
    128      1.1  christos #define DIVSI(x, y) ((SI) (x) / (SI) (y))
    129      1.1  christos #define UDIVSI(x, y) ((USI) (x) / (USI) (y))
    130      1.1  christos #define MODSI(x, y) ((SI) (x) % (SI) (y))
    131      1.1  christos #define UMODSI(x, y) ((USI) (x) % (USI) (y))
    132      1.1  christos #define SRASI(x, y) ((SI) (x) >> (y))
    133      1.1  christos #define SRLSI(x, y) ((USI) (x) >> (y))
    134      1.1  christos #define SLLSI(x, y) ((USI) (x) << (y))
    135      1.1  christos extern SI RORSI (SI, int);
    136      1.1  christos extern SI ROLSI (SI, int);
    137      1.1  christos #define ANDSI(x, y) ((x) & (y))
    138      1.1  christos #define ORSI(x, y) ((x) | (y))
    139      1.1  christos #define XORSI(x, y) ((x) ^ (y))
    140      1.1  christos #define NEGSI(x) ((SI) (- (USI) (x)))
    141      1.1  christos #define NOTSI(x) (! (SI) (x))
    142      1.1  christos #define INVSI(x) (~ (x))
    143      1.1  christos #define ABSSI(x) ((SI) ((SI) (x) < 0 ? -(USI) (x) : (USI) (x)))
    144      1.1  christos #define EQSI(x, y) ((SI) (x) == (SI) (y))
    145      1.1  christos #define NESI(x, y) ((SI) (x) != (SI) (y))
    146      1.1  christos #define LTSI(x, y) ((SI) (x) < (SI) (y))
    147      1.1  christos #define LESI(x, y) ((SI) (x) <= (SI) (y))
    148      1.1  christos #define GTSI(x, y) ((SI) (x) > (SI) (y))
    149      1.1  christos #define GESI(x, y) ((SI) (x) >= (SI) (y))
    150      1.1  christos #define LTUSI(x, y) ((USI) (x) < (USI) (y))
    151      1.1  christos #define LEUSI(x, y) ((USI) (x) <= (USI) (y))
    152      1.1  christos #define GTUSI(x, y) ((USI) (x) > (USI) (y))
    153      1.1  christos #define GEUSI(x, y) ((USI) (x) >= (USI) (y))
    154      1.1  christos 
    155      1.1  christos #ifdef DI_FN_SUPPORT
    157      1.1  christos extern DI ADDDI (DI, DI);
    158      1.1  christos extern DI SUBDI (DI, DI);
    159      1.1  christos extern DI MULDI (DI, DI);
    160      1.1  christos extern DI DIVDI (DI, DI);
    161      1.1  christos extern DI UDIVDI (DI, DI);
    162      1.1  christos extern DI MODDI (DI, DI);
    163      1.1  christos extern DI UMODDI (DI, DI);
    164      1.1  christos extern DI SRADI (DI, int);
    165      1.1  christos extern UDI SRLDI (UDI, int);
    166      1.1  christos extern UDI SLLDI (UDI, int);
    167      1.1  christos extern DI RORDI (DI, int);
    168      1.1  christos extern DI ROLDI (DI, int);
    169      1.1  christos extern DI ANDDI (DI, DI);
    170      1.1  christos extern DI ORDI (DI, DI);
    171      1.1  christos extern DI XORDI (DI, DI);
    172      1.1  christos extern DI NEGDI (DI);
    173      1.1  christos extern int NOTDI (DI);
    174      1.1  christos extern DI INVDI (DI);
    175      1.1  christos extern int EQDI (DI, DI);
    176      1.1  christos extern int NEDI (DI, DI);
    177      1.1  christos extern int LTDI (DI, DI);
    178      1.1  christos extern int LEDI (DI, DI);
    179      1.1  christos extern int GTDI (DI, DI);
    180      1.1  christos extern int GEDI (DI, DI);
    181      1.1  christos extern int LTUDI (UDI, UDI);
    182      1.1  christos extern int LEUDI (UDI, UDI);
    183      1.1  christos extern int GTUDI (UDI, UDI);
    184      1.1  christos extern int GEUDI (UDI, UDI);
    185      1.1  christos #else /* ! DI_FN_SUPPORT */
    186      1.1  christos #define ADDDI(x, y) ((DI) ((UDI) (x) + (UDI) (y)))
    187      1.1  christos #define SUBDI(x, y) ((DI) ((UDI) (x) - (UDI) (y)))
    188      1.1  christos #define MULDI(x, y) ((DI) ((UDI) (x) * (UDI) (y)))
    189      1.1  christos #define DIVDI(x, y) ((DI) (x) / (DI) (y))
    190      1.1  christos #define UDIVDI(x, y) ((UDI) (x) / (UDI) (y))
    191      1.1  christos #define MODDI(x, y) ((DI) (x) % (DI) (y))
    192      1.1  christos #define UMODDI(x, y) ((UDI) (x) % (UDI) (y))
    193      1.1  christos #define SRADI(x, y) ((DI) (x) >> (y))
    194      1.1  christos #define SRLDI(x, y) ((UDI) (x) >> (y))
    195      1.1  christos #define SLLDI(x, y) ((UDI) (x) << (y))
    196      1.1  christos extern DI RORDI (DI, int);
    197      1.1  christos extern DI ROLDI (DI, int);
    198      1.1  christos #define ANDDI(x, y) ((x) & (y))
    199      1.1  christos #define ORDI(x, y) ((x) | (y))
    200      1.1  christos #define XORDI(x, y) ((x) ^ (y))
    201      1.1  christos #define NEGDI(x) ((DI) (- (UDI) (x)))
    202      1.1  christos #define NOTDI(x) (! (DI) (x))
    203      1.1  christos #define INVDI(x) (~ (x))
    204      1.1  christos #define ABSDI(x) ((DI) ((DI) (x) < 0 ? -(UDI) (x) : (UDI) (x)))
    205      1.1  christos #define EQDI(x, y) ((DI) (x) == (DI) (y))
    206      1.1  christos #define NEDI(x, y) ((DI) (x) != (DI) (y))
    207      1.1  christos #define LTDI(x, y) ((DI) (x) < (DI) (y))
    208      1.1  christos #define LEDI(x, y) ((DI) (x) <= (DI) (y))
    209      1.1  christos #define GTDI(x, y) ((DI) (x) > (DI) (y))
    210      1.1  christos #define GEDI(x, y) ((DI) (x) >= (DI) (y))
    211      1.1  christos #define LTUDI(x, y) ((UDI) (x) < (UDI) (y))
    212      1.1  christos #define LEUDI(x, y) ((UDI) (x) <= (UDI) (y))
    213      1.1  christos #define GTUDI(x, y) ((UDI) (x) > (UDI) (y))
    214      1.1  christos #define GEUDI(x, y) ((UDI) (x) >= (UDI) (y))
    215      1.1  christos #endif /* DI_FN_SUPPORT */
    216      1.1  christos 
    217      1.1  christos #define EXTBIQI(x) ((QI) (BI) (x))
    219      1.1  christos #define EXTBIHI(x) ((HI) (BI) (x))
    220      1.1  christos #define EXTBISI(x) ((SI) (BI) (x))
    221      1.1  christos #if defined (DI_FN_SUPPORT)
    222      1.1  christos extern DI EXTBIDI (BI);
    223      1.1  christos #else
    224      1.1  christos #define EXTBIDI(x) ((DI) (BI) (x))
    225      1.1  christos #endif
    226      1.1  christos #define EXTQIHI(x) ((HI) (QI) (x))
    227      1.1  christos #define EXTQISI(x) ((SI) (QI) (x))
    228      1.1  christos #if defined (DI_FN_SUPPORT)
    229      1.1  christos extern DI EXTQIDI (QI);
    230      1.1  christos #else
    231      1.1  christos #define EXTQIDI(x) ((DI) (QI) (x))
    232      1.1  christos #endif
    233      1.1  christos #define EXTHIHI(x) ((HI) (HI) (x))
    234      1.1  christos #define EXTHISI(x) ((SI) (HI) (x))
    235      1.1  christos #define EXTSISI(x) ((SI) (SI) (x))
    236      1.1  christos #if defined (DI_FN_SUPPORT)
    237      1.1  christos extern DI EXTHIDI (HI);
    238      1.1  christos #else
    239      1.1  christos #define EXTHIDI(x) ((DI) (HI) (x))
    240      1.1  christos #endif
    241      1.1  christos #if defined (DI_FN_SUPPORT)
    242      1.1  christos extern DI EXTSIDI (SI);
    243      1.1  christos #else
    244      1.1  christos #define EXTSIDI(x) ((DI) (SI) (x))
    245      1.1  christos #endif
    246      1.1  christos 
    247      1.1  christos #define ZEXTBIQI(x) ((QI) (BI) (x))
    249      1.1  christos #define ZEXTBIHI(x) ((HI) (BI) (x))
    250      1.1  christos #define ZEXTBISI(x) ((SI) (BI) (x))
    251      1.1  christos #if defined (DI_FN_SUPPORT)
    252      1.1  christos extern DI ZEXTBIDI (BI);
    253      1.1  christos #else
    254      1.1  christos #define ZEXTBIDI(x) ((DI) (BI) (x))
    255      1.1  christos #endif
    256      1.1  christos #define ZEXTQIHI(x) ((HI) (UQI) (x))
    257      1.1  christos #define ZEXTQISI(x) ((SI) (UQI) (x))
    258      1.1  christos #if defined (DI_FN_SUPPORT)
    259      1.1  christos extern DI ZEXTQIDI (QI);
    260      1.1  christos #else
    261      1.1  christos #define ZEXTQIDI(x) ((DI) (UQI) (x))
    262      1.1  christos #endif
    263      1.1  christos #define ZEXTHISI(x) ((SI) (UHI) (x))
    264      1.1  christos #define ZEXTHIHI(x) ((HI) (UHI) (x))
    265      1.1  christos #define ZEXTSISI(x) ((SI) (USI) (x))
    266      1.1  christos #if defined (DI_FN_SUPPORT)
    267      1.1  christos extern DI ZEXTHIDI (HI);
    268      1.1  christos #else
    269      1.1  christos #define ZEXTHIDI(x) ((DI) (UHI) (x))
    270      1.1  christos #endif
    271      1.1  christos #if defined (DI_FN_SUPPORT)
    272      1.1  christos extern DI ZEXTSIDI (SI);
    273      1.1  christos #else
    274      1.1  christos #define ZEXTSIDI(x) ((DI) (USI) (x))
    275      1.1  christos #endif
    276      1.1  christos 
    277      1.1  christos #define TRUNCQIBI(x) ((BI) (QI) (x))
    279      1.1  christos #define TRUNCHIBI(x) ((BI) (HI) (x))
    280      1.1  christos #define TRUNCHIQI(x) ((QI) (HI) (x))
    281      1.1  christos #define TRUNCSIBI(x) ((BI) (SI) (x))
    282      1.1  christos #define TRUNCSIQI(x) ((QI) (SI) (x))
    283      1.1  christos #define TRUNCSIHI(x) ((HI) (SI) (x))
    284      1.1  christos #define TRUNCSISI(x) ((SI) (SI) (x))
    285      1.1  christos #if defined (DI_FN_SUPPORT)
    286      1.1  christos extern BI TRUNCDIBI (DI);
    287      1.1  christos #else
    288      1.1  christos #define TRUNCDIBI(x) ((BI) (DI) (x))
    289      1.1  christos #endif
    290      1.1  christos #if defined (DI_FN_SUPPORT)
    291      1.1  christos extern QI TRUNCDIQI (DI);
    292      1.1  christos #else
    293      1.1  christos #define TRUNCDIQI(x) ((QI) (DI) (x))
    294      1.1  christos #endif
    295      1.1  christos #if defined (DI_FN_SUPPORT)
    296      1.1  christos extern HI TRUNCDIHI (DI);
    297      1.1  christos #else
    298      1.1  christos #define TRUNCDIHI(x) ((HI) (DI) (x))
    299      1.1  christos #endif
    300      1.1  christos #if defined (DI_FN_SUPPORT)
    301      1.1  christos extern SI TRUNCDISI (DI);
    302      1.1  christos #else
    303      1.1  christos #define TRUNCDISI(x) ((SI) (DI) (x))
    304      1.1  christos #endif
    305      1.1  christos 
    306      1.1  christos /* Composing/decomposing the various types.
    308      1.1  christos    Word ordering is endian-independent.  Words are specified most to least
    309      1.1  christos    significant and word number 0 is the most significant word.
    310      1.1  christos    ??? May also wish an endian-dependent version.  Later.  */
    311      1.1  christos 
    312      1.1  christos #ifdef SEMOPS_DEFINE_INLINE
    313      1.1  christos 
    314      1.1  christos SEMOPS_INLINE SF
    315      1.1  christos SUBWORDSISF (SI in)
    316      1.1  christos {
    317      1.1  christos   union { SI in; SF out; } x;
    318      1.1  christos   x.in = in;
    319      1.1  christos   return x.out;
    320      1.1  christos }
    321      1.1  christos 
    322      1.1  christos SEMOPS_INLINE DF
    323      1.1  christos SUBWORDDIDF (DI in)
    324      1.1  christos {
    325      1.1  christos   union { DI in; DF out; } x;
    326      1.1  christos   x.in = in;
    327      1.1  christos   return x.out;
    328      1.1  christos }
    329      1.1  christos 
    330      1.1  christos SEMOPS_INLINE QI
    331      1.1  christos SUBWORDSIQI (SI in, int byte)
    332      1.1  christos {
    333      1.1  christos   assert (byte >= 0 && byte <= 3);
    334      1.1  christos   return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
    335      1.1  christos }
    336      1.1  christos 
    337      1.1  christos SEMOPS_INLINE UQI
    338      1.1  christos SUBWORDSIUQI (SI in, int byte)
    339      1.1  christos {
    340      1.1  christos   assert (byte >= 0 && byte <= 3);
    341      1.1  christos   return (UQI) (in >> (8 * (3 - byte))) & 0xFF;
    342      1.1  christos }
    343      1.1  christos 
    344      1.1  christos SEMOPS_INLINE QI
    345      1.1  christos SUBWORDDIQI (DI in, int byte)
    346      1.1  christos {
    347      1.1  christos   assert (byte >= 0 && byte <= 7);
    348      1.1  christos   return (UQI) (in >> (8 * (7 - byte))) & 0xFF;
    349      1.1  christos }
    350      1.1  christos 
    351      1.1  christos SEMOPS_INLINE HI
    352      1.1  christos SUBWORDDIHI (DI in, int word)
    353      1.1  christos {
    354      1.1  christos   assert (word >= 0 && word <= 3);
    355      1.1  christos   return (UHI) (in >> (16 * (3 - word))) & 0xFFFF;
    356      1.1  christos }
    357      1.1  christos 
    358      1.1  christos SEMOPS_INLINE HI
    359      1.1  christos SUBWORDSIHI (SI in, int word)
    360      1.1  christos {
    361      1.1  christos   if (word == 0)
    362      1.1  christos     return (USI) in >> 16;
    363      1.1  christos   else
    364      1.1  christos     return in;
    365      1.1  christos }
    366      1.1  christos 
    367      1.1  christos SEMOPS_INLINE SI
    368      1.1  christos SUBWORDSFSI (SF in)
    369      1.1  christos {
    370      1.1  christos   union { SF in; SI out; } x;
    371      1.1  christos   x.in = in;
    372      1.1  christos   return x.out;
    373      1.1  christos }
    374      1.1  christos 
    375      1.1  christos SEMOPS_INLINE DI
    376      1.1  christos SUBWORDDFDI (DF in)
    377      1.1  christos {
    378      1.1  christos   union { DF in; DI out; } x;
    379      1.1  christos   x.in = in;
    380      1.1  christos   return x.out;
    381      1.1  christos }
    382      1.1  christos 
    383      1.1  christos SEMOPS_INLINE UQI
    384      1.1  christos SUBWORDDIUQI (DI in, int byte)
    385      1.1  christos {
    386      1.1  christos   assert (byte >= 0 && byte <= 7);
    387      1.1  christos   return (UQI) (in >> (8 * (7 - byte)));
    388      1.1  christos }
    389      1.1  christos 
    390      1.1  christos SEMOPS_INLINE SI
    391      1.1  christos SUBWORDDISI (DI in, int word)
    392      1.1  christos {
    393      1.1  christos   if (word == 0)
    394      1.1  christos     return (UDI) in >> 32;
    395      1.1  christos   else
    396      1.1  christos     return in;
    397      1.1  christos }
    398      1.1  christos 
    399      1.1  christos SEMOPS_INLINE SI
    400      1.1  christos SUBWORDDFSI (DF in, int word)
    401      1.1  christos {
    402      1.1  christos   /* Note: typedef UDI DF; */
    403      1.1  christos   if (word == 0)
    404      1.1  christos     return (UDI) in >> 32;
    405      1.1  christos   else
    406      1.1  christos     return in;
    407      1.1  christos }
    408      1.1  christos 
    409      1.1  christos SEMOPS_INLINE SI
    410      1.1  christos SUBWORDXFSI (XF in, int word)
    411      1.1  christos {
    412      1.1  christos   /* Note: typedef struct { SI parts[3]; } XF; */
    413      1.1  christos   union { XF in; SI out[3]; } x;
    414      1.1  christos   x.in = in;
    415      1.1  christos   if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
    416      1.1  christos     return x.out[word];
    417      1.1  christos   else
    418      1.1  christos     return x.out[2 - word];
    419      1.1  christos }
    420      1.1  christos 
    421      1.1  christos SEMOPS_INLINE SI
    422      1.1  christos SUBWORDTFSI (TF in, int word)
    423      1.1  christos {
    424      1.1  christos   /* Note: typedef struct { SI parts[4]; } TF; */
    425      1.1  christos   union { TF in; SI out[4]; } x;
    426      1.1  christos   x.in = in;
    427      1.1  christos   if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
    428      1.1  christos     return x.out[word];
    429      1.1  christos   else
    430      1.1  christos     return x.out[3 - word];
    431      1.1  christos }
    432      1.1  christos 
    433      1.1  christos SEMOPS_INLINE DI
    434      1.1  christos JOINSIDI (SI x0, SI x1)
    435      1.1  christos {
    436      1.1  christos   return MAKEDI (x0, x1);
    437      1.1  christos }
    438      1.1  christos 
    439      1.1  christos SEMOPS_INLINE DF
    440      1.1  christos JOINSIDF (SI x0, SI x1)
    441      1.1  christos {
    442      1.1  christos   union { SI in[2]; DF out; } x;
    443      1.1  christos   if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
    444      1.1  christos     x.in[0] = x0, x.in[1] = x1;
    445      1.1  christos   else
    446      1.1  christos     x.in[1] = x0, x.in[0] = x1;
    447      1.1  christos   return x.out;
    448      1.1  christos }
    449      1.1  christos 
    450      1.1  christos SEMOPS_INLINE XF
    451      1.1  christos JOINSIXF (SI x0, SI x1, SI x2)
    452      1.1  christos {
    453      1.1  christos   union { SI in[3]; XF out; } x;
    454      1.1  christos   if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
    455      1.1  christos     x.in[0] = x0, x.in[1] = x1, x.in[2] = x2;
    456      1.1  christos   else
    457      1.1  christos     x.in[2] = x0, x.in[1] = x1, x.in[0] = x2;
    458      1.1  christos   return x.out;
    459      1.1  christos }
    460      1.1  christos 
    461      1.1  christos SEMOPS_INLINE TF
    462      1.1  christos JOINSITF (SI x0, SI x1, SI x2, SI x3)
    463      1.1  christos {
    464      1.1  christos   union { SI in[4]; TF out; } x;
    465      1.1  christos   if (CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN)
    466      1.1  christos     x.in[0] = x0, x.in[1] = x1, x.in[2] = x2, x.in[3] = x3;
    467      1.1  christos   else
    468      1.1  christos     x.in[3] = x0, x.in[2] = x1, x.in[1] = x2, x.in[0] = x3;
    469      1.1  christos   return x.out;
    470      1.1  christos }
    471      1.1  christos 
    472      1.1  christos #else
    473      1.1  christos 
    474      1.1  christos QI SUBWORDSIQI (SI);
    475      1.1  christos HI SUBWORDSIHI (HI);
    476      1.1  christos SI SUBWORDSFSI (SF);
    477      1.1  christos SF SUBWORDSISF (SI);
    478      1.1  christos DI SUBWORDDFDI (DF);
    479      1.1  christos DF SUBWORDDIDF (DI);
    480      1.1  christos QI SUBWORDDIQI (DI, int);
    481      1.1  christos HI SUBWORDDIHI (DI, int);
    482      1.1  christos SI SUBWORDDISI (DI, int);
    483      1.1  christos SI SUBWORDDFSI (DF, int);
    484      1.1  christos SI SUBWORDXFSI (XF, int);
    485      1.1  christos SI SUBWORDTFSI (TF, int);
    486      1.1  christos 
    487      1.1  christos UQI SUBWORDSIUQI (SI);
    488      1.1  christos UQI SUBWORDDIUQI (DI);
    489      1.1  christos 
    490      1.1  christos DI JOINSIDI (SI, SI);
    491      1.1  christos DF JOINSIDF (SI, SI);
    492      1.1  christos XF JOINSIXF (SI, SI, SI);
    493      1.1  christos TF JOINSITF (SI, SI, SI, SI);
    494      1.1  christos 
    495      1.1  christos #endif /* SUBWORD,JOIN */
    496      1.1  christos 
    497      1.1  christos /* Semantic support utilities.  */
    499      1.1  christos 
    500      1.1  christos #ifdef SEMOPS_DEFINE_INLINE
    501      1.1  christos 
    502      1.1  christos SEMOPS_INLINE SI
    503      1.1  christos ADDCSI (SI a, SI b, BI c)
    504      1.1  christos {
    505      1.1  christos   SI res = ADDSI (a, ADDSI (b, c));
    506      1.1  christos   return res;
    507      1.1  christos }
    508      1.1  christos 
    509      1.1  christos SEMOPS_INLINE BI
    510      1.1  christos ADDCFSI (SI a, SI b, BI c)
    511      1.1  christos {
    512      1.1  christos   SI tmp = ADDSI (a, ADDSI (b, c));
    513      1.1  christos   BI res = ((USI) tmp < (USI) a) || (c && tmp == a);
    514      1.1  christos   return res;
    515      1.1  christos }
    516      1.1  christos 
    517      1.1  christos SEMOPS_INLINE BI
    518      1.1  christos ADDOFSI (SI a, SI b, BI c)
    519      1.1  christos {
    520      1.1  christos   SI tmp = ADDSI (a, ADDSI (b, c));
    521      1.1  christos   BI res = (((a < 0) == (b < 0))
    522      1.1  christos 	    && ((a < 0) != (tmp < 0)));
    523      1.1  christos   return res;
    524      1.1  christos }
    525      1.1  christos 
    526      1.1  christos SEMOPS_INLINE SI
    527      1.1  christos SUBCSI (SI a, SI b, BI c)
    528      1.1  christos {
    529      1.1  christos   SI res = SUBSI (a, ADDSI (b, c));
    530      1.1  christos   return res;
    531      1.1  christos }
    532      1.1  christos 
    533      1.1  christos SEMOPS_INLINE BI
    534      1.1  christos SUBCFSI (SI a, SI b, BI c)
    535      1.1  christos {
    536      1.1  christos   BI res = ((USI) a < (USI) b) || (c && a == b);
    537      1.1  christos   return res;
    538      1.1  christos }
    539      1.1  christos 
    540      1.1  christos SEMOPS_INLINE BI
    541      1.1  christos SUBOFSI (SI a, SI b, BI c)
    542      1.1  christos {
    543      1.1  christos   SI tmp = SUBSI (a, ADDSI (b, c));
    544      1.1  christos   BI res = (((a < 0) != (b < 0))
    545      1.1  christos 	    && ((a < 0) != (tmp < 0)));
    546      1.1  christos   return res;
    547      1.1  christos }
    548      1.1  christos 
    549      1.1  christos SEMOPS_INLINE HI
    550      1.1  christos ADDCHI (HI a, HI b, BI c)
    551      1.1  christos {
    552      1.1  christos   HI res = ADDHI (a, ADDHI (b, c));
    553      1.1  christos   return res;
    554      1.1  christos }
    555      1.1  christos 
    556      1.1  christos SEMOPS_INLINE BI
    557      1.1  christos ADDCFHI (HI a, HI b, BI c)
    558      1.1  christos {
    559      1.1  christos   HI tmp = ADDHI (a, ADDHI (b, c));
    560      1.1  christos   BI res = ((UHI) tmp < (UHI) a) || (c && tmp == a);
    561      1.1  christos   return res;
    562      1.1  christos }
    563      1.1  christos 
    564      1.1  christos SEMOPS_INLINE BI
    565      1.1  christos ADDOFHI (HI a, HI b, BI c)
    566      1.1  christos {
    567      1.1  christos   HI tmp = ADDHI (a, ADDHI (b, c));
    568      1.1  christos   BI res = (((a < 0) == (b < 0))
    569      1.1  christos 	    && ((a < 0) != (tmp < 0)));
    570      1.1  christos   return res;
    571      1.1  christos }
    572      1.1  christos 
    573      1.1  christos SEMOPS_INLINE HI
    574      1.1  christos SUBCHI (HI a, HI b, BI c)
    575      1.1  christos {
    576      1.1  christos   HI res = SUBHI (a, ADDHI (b, c));
    577      1.1  christos   return res;
    578      1.1  christos }
    579      1.1  christos 
    580      1.1  christos SEMOPS_INLINE BI
    581      1.1  christos SUBCFHI (HI a, HI b, BI c)
    582      1.1  christos {
    583      1.1  christos   BI res = ((UHI) a < (UHI) b) || (c && a == b);
    584      1.1  christos   return res;
    585      1.1  christos }
    586      1.1  christos 
    587      1.1  christos SEMOPS_INLINE BI
    588      1.1  christos SUBOFHI (HI a, HI b, BI c)
    589      1.1  christos {
    590      1.1  christos   HI tmp = SUBHI (a, ADDHI (b, c));
    591      1.1  christos   BI res = (((a < 0) != (b < 0))
    592      1.1  christos 	    && ((a < 0) != (tmp < 0)));
    593      1.1  christos   return res;
    594      1.1  christos }
    595      1.1  christos 
    596      1.1  christos SEMOPS_INLINE QI
    597      1.1  christos ADDCQI (QI a, QI b, BI c)
    598      1.1  christos {
    599      1.1  christos   QI res = ADDQI (a, ADDQI (b, c));
    600      1.1  christos   return res;
    601      1.1  christos }
    602      1.1  christos 
    603      1.1  christos SEMOPS_INLINE BI
    604      1.1  christos ADDCFQI (QI a, QI b, BI c)
    605      1.1  christos {
    606      1.1  christos   QI tmp = ADDQI (a, ADDQI (b, c));
    607      1.1  christos   BI res = ((UQI) tmp < (UQI) a) || (c && tmp == a);
    608      1.1  christos   return res;
    609      1.1  christos }
    610      1.1  christos 
    611      1.1  christos SEMOPS_INLINE BI
    612      1.1  christos ADDOFQI (QI a, QI b, BI c)
    613      1.1  christos {
    614      1.1  christos   QI tmp = ADDQI (a, ADDQI (b, c));
    615      1.1  christos   BI res = (((a < 0) == (b < 0))
    616      1.1  christos 	    && ((a < 0) != (tmp < 0)));
    617      1.1  christos   return res;
    618      1.1  christos }
    619      1.1  christos 
    620      1.1  christos SEMOPS_INLINE QI
    621      1.1  christos SUBCQI (QI a, QI b, BI c)
    622      1.1  christos {
    623      1.1  christos   QI res = SUBQI (a, ADDQI (b, c));
    624      1.1  christos   return res;
    625      1.1  christos }
    626      1.1  christos 
    627      1.1  christos SEMOPS_INLINE BI
    628      1.1  christos SUBCFQI (QI a, QI b, BI c)
    629      1.1  christos {
    630      1.1  christos   BI res = ((UQI) a < (UQI) b) || (c && a == b);
    631      1.1  christos   return res;
    632      1.1  christos }
    633      1.1  christos 
    634      1.1  christos SEMOPS_INLINE BI
    635      1.1  christos SUBOFQI (QI a, QI b, BI c)
    636      1.1  christos {
    637      1.1  christos   QI tmp = SUBQI (a, ADDQI (b, c));
    638      1.1  christos   BI res = (((a < 0) != (b < 0))
    639      1.1  christos 	    && ((a < 0) != (tmp < 0)));
    640      1.1  christos   return res;
    641      1.1  christos }
    642      1.1  christos 
    643      1.1  christos #else
    644      1.1  christos 
    645      1.1  christos SI ADDCSI (SI, SI, BI);
    646      1.1  christos UBI ADDCFSI (SI, SI, BI);
    647      1.1  christos UBI ADDOFSI (SI, SI, BI);
    648      1.1  christos SI SUBCSI (SI, SI, BI);
    649      1.1  christos UBI SUBCFSI (SI, SI, BI);
    650      1.1  christos UBI SUBOFSI (SI, SI, BI);
    651      1.1  christos HI ADDCHI (HI, HI, BI);
    652      1.1  christos UBI ADDCFHI (HI, HI, BI);
    653      1.1  christos UBI ADDOFHI (HI, HI, BI);
    654      1.1  christos HI SUBCHI (HI, HI, BI);
    655      1.1  christos UBI SUBCFHI (HI, HI, BI);
    656      1.1  christos UBI SUBOFHI (HI, HI, BI);
    657      1.1  christos QI ADDCQI (QI, QI, BI);
    658                    UBI ADDCFQI (QI, QI, BI);
    659                    UBI ADDOFQI (QI, QI, BI);
    660                    QI SUBCQI (QI, QI, BI);
    661                    UBI SUBCFQI (QI, QI, BI);
    662                    UBI SUBOFQI (QI, QI, BI);
    663                    
    664                    #endif
    665                    
    666                    #endif /* CGEN_SEM_OPS_H */
    667