root/src/dps8/dps8_utils.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. getbits36
  2. getbits36_1
  3. getbits36_2
  4. getbits36_3
  5. getbits36_4
  6. getbits36_5
  7. getbits36_6
  8. getbits36_7
  9. getbits36_8
  10. getbits36_9
  11. getbits36_10
  12. getbits36_12
  13. getbits36_14
  14. getbits36_15
  15. getbits36_16
  16. getbits36_18
  17. getbits36_24
  18. getbits36_28
  19. setbits36
  20. setbits36_1
  21. setbits36_4
  22. setbits36_5
  23. setbits36_6
  24. setbits36_8
  25. setbits36_9
  26. setbits36_16
  27. setbits36_24
  28. putbits36
  29. putbits36_1
  30. putbits36_2
  31. putbits36_3
  32. putbits36_4
  33. putbits36_5
  34. putbits36_6
  35. putbits36_7
  36. putbits36_8
  37. putbits36_9
  38. putbits36_10
  39. putbits36_12
  40. putbits36_13
  41. putbits36_14
  42. putbits36_15
  43. putbits36_16
  44. putbits36_17
  45. putbits36_18
  46. putbits36_23
  47. putbits36_24
  48. putbits36_28
  49. putbits72
  50. getbits18
  51. putbits18
  52. setmask
  53. clrmask

   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 1881c7a6-f62f-11ec-b538-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2007-2013 Michael Mondy
   9  * Copyright (c) 2012-2016 Harry Reed
  10  * Copyright (c) 2013-2018 Charles Anthony
  11  * Copyright (c) 2021-2023 The DPS8M Development Team
  12  *
  13  * All rights reserved.
  14  *
  15  * This software is made available under the terms of the ICU
  16  * License, version 1.8.1 or later.  For more details, see the
  17  * LICENSE.md file at the top-level directory of this distribution.
  18  *
  19  * ---------------------------------------------------------------------------
  20  */
  21 
  22 // Interface for cfg_parse
  23 
  24 typedef struct config_value_list_s
  25   {
  26     const char * value_name;
  27     int64_t value;
  28   } config_value_list_t;
  29 
  30 typedef struct config_list_s
  31   {
  32     const char * name;  // opt name
  33     int64_t min, max;   // value limits
  34     config_value_list_t * value_list;
  35   } config_list_t;
  36 
  37 typedef struct config_state_s
  38   {
  39     char * copy;
  40     char * statement_save;
  41   } config_state_t;
  42 
  43 int cfg_parse (const char * tag, const char * cptr, config_list_t * clist, config_state_t * state, int64_t * result);
  44 void cfg_parse_done (config_state_t * state);
  45 
  46 struct opcode_s * get_iwb_info (DCDstruct *i);
  47 char * dump_flags(char * buffer, word18 flags);
  48 char *disassemble(char * result, word36 instruction);
  49 char *get_mod_string(char * msg, word6 tag);
  50 word72 convert_to_word72 (word36 even, word36 odd);
  51 void convert_to_word36 (word72 src, word36 *even, word36 *odd);
  52 
  53 word36 compl36(word36 op1, word18 *flags, bool * ovf);
  54 word18 compl18(word18 op1, word18 *flags, bool * ovf);
  55 
  56 void copyBytes(int posn, word36 src, word36 *dst);
  57 void copyChars(int posn, word36 src, word36 *dst);
  58 
  59 void putByte(word36 *dst, word9 data, int posn);
  60 void putChar(word36 *dst, word6 data, int posn);
  61 
  62 void cmp36(word36 op1, word36 op2, word18 *flags);
  63 void cmp36wl(word36 A, word36 Y, word36 Q, word18 *flags);
  64 void cmp18(word18 op1, word18 op2, word18 *flags);
  65 void cmp72(word72 op1, word72 op2, word18 *flags);
  66 
  67 char *strlower(char *q);
  68 int strmask(char *str, char *mask);
  69 char *Strtok(char *, char *);
  70 char *stripquotes(char *s);
  71 char *trim(char *s);
  72 char *ltrim(char *s);
  73 char *rtrim(char *s);
  74 
  75 //
  76 // getbitsNN/setbitsNN/putbitsNN
  77 //
  78 //   Manipulate bitfields.
  79 //     NN      the word size (18, 36, 72).
  80 //     data    the incoming word
  81 //     i       the starting bit number (DPS8 notation, 0 is the MSB)
  82 //     n       the number of bits, starting at i
  83 //     val     the bits
  84 //
  85 //   val = getbitsNN (data, i, n)
  86 //
  87 //       extract n bits from data, starting at i.
  88 //
  89 //           val = getbits36 (data, 0, 1) --> the sign bit
  90 //           val = getbits36 (data, 18, 18) --> the low eighteen bits
  91 //
  92 //   newdata = setbitsNN (data, i, n, val)
  93 //
  94 //       return 'data' with n bits of val inserted.
  95 //
  96 //           newdata = setbits36 (data, 0, 18, 1) --> move '1' into the high
  97 //                                                    18 bits.
  98 //
  99 //   putbitsNN (& data, i, n, val)
 100 //
 101 //        put val into data (equivalent to 'data = setbitsNN (data, ....)'
 102 //
 103 //           putbits (& data, 0, 18, 1) --> set the high 18 bits to '1'.
 104 //
 105 
 106 
 107 
 108 
 109 
 110 
 111 
 112 
 113 
 114 
 115 
 116 
 117 
 118 
 119 
 120 
 121 static inline word36 getbits36(word36 x, uint i, uint n) {
     /* [previous][next][first][last][top][bottom][index][help] */
 122     // bit 35 is right end, bit zero is 36th from the right
 123     int shift = 35-(int)i-(int)n+1;
 124     if (shift < 0 || shift > 35) {
 125         sim_printf ("getbits36: bad args (%012llu,i=%d,n=%d)\n", (unsigned long long)x, i, n);
 126         return 0;
 127     } else
 128         return (x >> (unsigned) shift) & ~ (~0U << n);
 129 }
 130 
 131 static inline word1 getbits36_1 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 132   {
 133     // bit 35 is right end, bit zero is 36th from the right
 134     int shift = 35-(int)i;
 135     if (shift < 0 || shift > 35) {
 136         sim_printf ("getbits36_1: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 137         return 0;
 138     } else
 139         return (x >> (unsigned) shift) & 01;
 140   }
 141 
 142 static inline word2 getbits36_2 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 143   {
 144     // bit 35 is right end, bit zero is 36th from the right
 145     int shift = 35-(int)i-(int)2+1;
 146     if (shift < 0 || shift > 35) {
 147         sim_printf ("getbits36_2: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 148         return 0;
 149     } else
 150         return (x >> (unsigned) shift) & 03;
 151   }
 152 
 153 static inline word3 getbits36_3 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 154   {
 155     // bit 35 is right end, bit zero is 36th from the right
 156     int shift = 35-(int)i-(int)3+1;
 157     if (shift < 0 || shift > 35) {
 158         sim_printf ("getbits36_3: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 159         return 0;
 160     } else
 161         return (x >> (unsigned) shift) & 07;
 162   }
 163 
 164 static inline word4 getbits36_4 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 165   {
 166     // bit 35 is right end, bit zero is 36th from the right
 167     int shift = 35-(int)i-(int)4+1;
 168     if (shift < 0 || shift > 35) {
 169         sim_printf ("getbits36_4: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 170         return 0;
 171     } else
 172         return (x >> (unsigned) shift) & 017;
 173   }
 174 
 175 static inline word5 getbits36_5 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 176   {
 177     // bit 35 is right end, bit zero is 36th from the right
 178     int shift = 35-(int)i-(int)5+1;
 179     if (shift < 0 || shift > 35) {
 180         sim_printf ("getbits36_5: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 181         return 0;
 182     } else
 183         return (x >> (unsigned) shift) & 037;
 184   }
 185 
 186 static inline word6 getbits36_6 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 187   {
 188     // bit 35 is right end, bit zero is 36th from the right
 189     int shift = 35-(int)i-(int)6+1;
 190     if (shift < 0 || shift > 35) {
 191         sim_printf ("getbits36_6: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 192         return 0;
 193     } else
 194         return (x >> (unsigned) shift) & 077;
 195   }
 196 
 197 static inline word7 getbits36_7 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 198   {
 199     // bit 35 is right end, bit zero is 36th from the right
 200     int shift = 35-(int)i-(int)7+1;
 201     if (shift < 0 || shift > 35) {
 202         sim_printf ("getbits36_7: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 203         return 0;
 204     } else
 205         return (x >> (unsigned) shift) & 0177;
 206   }
 207 
 208 static inline word8 getbits36_8 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 209   {
 210     // bit 35 is right end, bit zero is 36th from the right
 211     int shift = 35-(int)i-(int)8+1;
 212     if (shift < 0 || shift > 35) {
 213         sim_printf ("getbits36_8: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 214         return 0;
 215     } else
 216         return (x >> (unsigned) shift) & 0377;
 217   }
 218 
 219 static inline word9 getbits36_9 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 220   {
 221     // bit 35 is right end, bit zero is 36th from the right
 222     int shift = 35-(int)i-(int)9+1;
 223     if (shift < 0 || shift > 35) {
 224         sim_printf ("getbits36_9: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 225         return 0;
 226     } else
 227         return (x >> (unsigned) shift) & 0777;
 228   }
 229 
 230 static inline word10 getbits36_10 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 231   {
 232     // bit 35 is right end, bit zero is 36th from the right
 233     int shift = 35-(int)i-(int)10+1;
 234     if (shift < 0 || shift > 35) {
 235         sim_printf ("getbits36_10: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 236         return 0;
 237     } else
 238         return (x >> (unsigned) shift) & 01777;
 239   }
 240 
 241 static inline word12 getbits36_12 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 242   {
 243     // bit 35 is right end, bit zero is 36th from the right
 244     int shift = 35-(int)i-(int)12+1;
 245     if (shift < 0 || shift > 35) {
 246         sim_printf ("getbits36_12: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 247         return 0;
 248     } else
 249         return (x >> (unsigned) shift) & 07777;
 250   }
 251 
 252 static inline word14 getbits36_14 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 253   {
 254     // bit 35 is right end, bit zero is 36th from the right
 255     int shift = 35-(int)i-(int)14+1;
 256     if (shift < 0 || shift > 35) {
 257         sim_printf ("getbits36_14: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 258         return 0;
 259     } else
 260         return (x >> (unsigned) shift) & 037777;
 261   }
 262 
 263 static inline word15 getbits36_15 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 264   {
 265     // bit 35 is right end, bit zero is 36th from the right
 266     int shift = 35-(int)i-(int)15+1;
 267     if (shift < 0 || shift > 35) {
 268         sim_printf ("getbits36_15: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 269         return 0;
 270     } else
 271         return (x >> (unsigned) shift) & 077777;
 272   }
 273 
 274 static inline word16 getbits36_16 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 275   {
 276     // bit 35 is right end, bit zero is 36th from the right
 277     int shift = 35-(int)i-(int)16+1;
 278     if (shift < 0 || shift > 35) {
 279         sim_printf ("getbits36_16: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 280         return 0;
 281     } else
 282         return (x >> (unsigned) shift) & 0177777;
 283   }
 284 
 285 static inline word18 getbits36_18 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 286   {
 287     // bit 35 is right end, bit zero is 36th from the right
 288     int shift = 35-(int)i-(int)18+1;
 289     if (shift < 0 || shift > 35) {
 290         sim_printf ("getbits36_18: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 291         return 0;
 292     } else
 293         return (x >> (unsigned) shift) & 0777777;
 294   }
 295 
 296 static inline word24 getbits36_24 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 297   {
 298     // bit 35 is right end, bit zero is 36th from the right
 299     int shift = 35-(int)i-(int)24+1;
 300     if (shift < 0 || shift > 35) {
 301         sim_printf ("getbits36_24: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 302         return 0;
 303     } else
 304         return (x >> (unsigned) shift) & MASK24;
 305   }
 306 
 307 static inline word28 getbits36_28 (word36 x, uint i)
     /* [previous][next][first][last][top][bottom][index][help] */
 308   {
 309     // bit 35 is right end, bit zero is 36th from the right
 310     int shift = 35-(int)i-(int)28+1;
 311     if (shift < 0 || shift > 35) {
 312         sim_printf ("getbits36_28: bad args (%012llu,i=%d)\n", (unsigned long long)x, i);
 313         return 0;
 314     } else
 315         return (x >> (unsigned) shift) & 01777777777;
 316   }
 317 
 318 static inline word36 setbits36(word36 x, uint p, uint n, word36 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 319 {
 320     int shift = 36 - (int) p - (int) n;
 321     if (shift < 0 || shift > 35) {
 322         sim_printf ("setbits36: bad args (%012llu,pos=%d,n=%d)\n", (unsigned long long)x, p, n);
 323         return 0;
 324     }
 325     word36 mask = ~ (~0U<<n);  // n low bits on
 326     mask <<= (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 327     // caller may provide val that is too big, e.g., a word with all bits
 328     // set to one, so we mask val
 329     word36 result = (x & ~ mask) | ((val&MASKBITS(n)) << (36 - p - n));
 330     return result;
 331 }
 332 
 333 static inline word36 setbits36_1 (word36 x, uint p, word1 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 334 {
 335     const int n = 1;
 336     int shift = 36 - (int) p - (int) n;
 337     if (shift < 0 || shift > 35) {
 338         sim_printf ("setbits36_1: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 339         return 0;
 340     }
 341     word36 mask = ~ (~0U<<n);  // n low bits on
 342     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 343     // caller may provide val that is too big, e.g., a word with all bits
 344     // set to one, so we mask val
 345     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 346     return result;
 347 }
 348 
 349 static inline word36 setbits36_4 (word36 x, uint p, word4 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 350 {
 351     const int n = 4;
 352     int shift = 36 - (int) p - (int) n;
 353     if (shift < 0 || shift > 35) {
 354         sim_printf ("setbits36_4: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 355         return 0;
 356     }
 357     word36 mask = ~ (~0U<<n);  // n low bits on
 358     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 359     // caller may provide val that is too big, e.g., a word with all bits
 360     // set to one, so we mask val
 361     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 362     return result;
 363 }
 364 
 365 static inline word36 setbits36_5 (word36 x, uint p, word5 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 366 {
 367     const int n = 5;
 368     int shift = 36 - (int) p - (int) n;
 369     if (shift < 0 || shift > 35) {
 370         sim_printf ("setbits36_5: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 371         return 0;
 372     }
 373     word36 mask = ~ (~0U<<n);  // n low bits on
 374     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 375     // caller may provide val that is too big, e.g., a word with all bits
 376     // set to one, so we mask val
 377     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 378     return result;
 379 }
 380 
 381 static inline word36 setbits36_6 (word36 x, uint p, word6 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 382 {
 383     const int n = 6;
 384     int shift = 36 - (int) p - (int) n;
 385     if (shift < 0 || shift > 35) {
 386         sim_printf ("setbits36_6: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 387         return 0;
 388     }
 389     word36 mask = ~ (~0U<<n);  // n low bits on
 390     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 391     // caller may provide val that is too big, e.g., a word with all bits
 392     // set to one, so we mask val
 393     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 394     return result;
 395 }
 396 
 397 static inline word36 setbits36_8 (word36 x, uint p, word8 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 398 {
 399     const int n = 8;
 400     int shift = 36 - (int) p - (int) n;
 401     if (shift < 0 || shift > 35) {
 402         sim_printf ("setbits36_8: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 403         return 0;
 404     }
 405     word36 mask = ~ (~0U<<n);  // n low bits on
 406     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 407     // caller may provide val that is too big, e.g., a word with all bits
 408     // set to one, so we mask val
 409     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 410     return result;
 411 }
 412 
 413 static inline word36 setbits36_9 (word36 x, uint p, word9 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 414 {
 415     const int n = 9;
 416     int shift = 36 - (int) p - (int) n;
 417     if (shift < 0 || shift > 35) {
 418         sim_printf ("setbits36_9: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 419         return 0;
 420     }
 421     word36 mask = ~ (~0U<<n);  // n low bits on
 422     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 423     // caller may provide val that is too big, e.g., a word with all bits
 424     // set to one, so we mask val
 425     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 426     return result;
 427 }
 428 
 429 static inline word36 setbits36_16 (word36 x, uint p, word16 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 430 {
 431     const int n = 16;
 432     int shift = 36 - (int) p - (int) n;
 433     if (shift < 0 || shift > 35) {
 434         sim_printf ("setbits36_16: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 435         return 0;
 436     }
 437     word36 mask = ~ (~0U<<n);  // n low bits on
 438     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 439     // caller may provide val that is too big, e.g., a word with all bits
 440     // set to one, so we mask val
 441     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 442     return result;
 443 }
 444 
 445 static inline word36 setbits36_24 (word36 x, uint p, word24 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 446 {
 447     const int n = 24;
 448     int shift = 36 - (int) p - (int) n;
 449     if (shift < 0 || shift > 35) {
 450         sim_printf ("setbits36_24: bad args (%012llu,pos=%d)\n", (unsigned long long)x, p);
 451         return 0;
 452     }
 453     word36 mask = ~ (~0U<<n);  // n low bits on
 454     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 455     // caller may provide val that is too big, e.g., a word with all bits
 456     // set to one, so we mask val
 457     word36 result = (x & ~ smask) | (((word36) val & mask) << shift);
 458     return result;
 459 }
 460 
 461 static inline void putbits36 (word36 * x, uint p, uint n, word36 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 462   {
 463     int shift = 36 - (int) p - (int) n;
 464     if (shift < 0 || shift > 35)
 465       {
 466         sim_printf ("putbits36: bad args (%012llu,pos=%d,n=%d)\n", (unsigned long long)*x, p, n);
 467         return;
 468       }
 469     word36 mask = ~ (~0U << n);  // n low bits on
 470     mask <<= (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 471     // caller may provide val that is too big, e.g., a word with all bits
 472     // set to one, so we mask val
 473     * x = (* x & ~mask) | ((val & MASKBITS (n)) << (36 - p - n));
 474     return;
 475   }
 476 
 477 static inline void putbits36_1 (word36 * x, uint p, word1 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 478 {
 479     const int n = 1;
 480     int shift = 36 - (int) p - (int) n;
 481     if (shift < 0 || shift > 35) {
 482         sim_printf ("putbits36_1: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 483         return;
 484     }
 485     word36 mask = ~ (~0U<<n);  // n low bits on
 486     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 487     // caller may provide val that is too big, e.g., a word with all bits
 488     // set to one, so we mask val
 489     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 490 }
 491 
 492 static inline void putbits36_2 (word36 * x, uint p, word2 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 493 {
 494     const int n = 2;
 495     int shift = 36 - (int) p - (int) n;
 496     if (shift < 0 || shift > 35) {
 497         sim_printf ("putbits36_2: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 498         return;
 499     }
 500     word36 mask = ~ (~0U<<n);  // n low bits on
 501     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 502     // caller may provide val that is too big, e.g., a word with all bits
 503     // set to one, so we mask val
 504     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 505 }
 506 
 507 static inline void putbits36_3 (word36 * x, uint p, word3 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 508 {
 509     const int n = 3;
 510     int shift = 36 - (int) p - (int) n;
 511     if (shift < 0 || shift > 35) {
 512         sim_printf ("putbits36_3: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 513         return;
 514     }
 515     word36 mask = ~ (~0U<<n);  // n low bits on
 516     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 517     // caller may provide val that is too big, e.g., a word with all bits
 518     // set to one, so we mask val
 519     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 520 }
 521 
 522 static inline void putbits36_4 (word36 * x, uint p, word4 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 523 {
 524     const int n = 4;
 525     int shift = 36 - (int) p - (int) n;
 526     if (shift < 0 || shift > 35) {
 527         sim_printf ("putbits36_4: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 528         return;
 529     }
 530     word36 mask = ~ (~0U<<n);  // n low bits on
 531     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 532     // caller may provide val that is too big, e.g., a word with all bits
 533     // set to one, so we mask val
 534     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 535 }
 536 
 537 static inline void putbits36_5 (word36 * x, uint p, word5 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 538 {
 539     const int n = 5;
 540     int shift = 36 - (int) p - (int) n;
 541     if (shift < 0 || shift > 35) {
 542         sim_printf ("putbits36_5: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 543         return;
 544     }
 545     word36 mask = ~ (~0U<<n);  // n low bits on
 546     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 547     // caller may provide val that is too big, e.g., a word with all bits
 548     // set to one, so we mask val
 549     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 550 }
 551 
 552 static inline void putbits36_6 (word36 * x, uint p, word6 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 553 {
 554     const int n = 6;
 555     int shift = 36 - (int) p - (int) n;
 556     if (shift < 0 || shift > 35) {
 557         sim_printf ("putbits36_6: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 558         return;
 559     }
 560     word36 mask = ~ (~0U<<n);  // n low bits on
 561     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 562     // caller may provide val that is too big, e.g., a word with all bits
 563     // set to one, so we mask val
 564     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 565 }
 566 
 567 static inline void putbits36_7 (word36 * x, uint p, word7 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 568 {
 569     const int n = 7;
 570     int shift = 36 - (int) p - (int) n;
 571     if (shift < 0 || shift > 35) {
 572         sim_printf ("putbits36_7: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 573         return;
 574     }
 575     word36 mask = ~ (~0U<<n);  // n low bits on
 576     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 577     // caller may provide val that is too big, e.g., a word with all bits
 578     // set to one, so we mask val
 579     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 580 }
 581 
 582 static inline void putbits36_8 (word36 * x, uint p, word8 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 583 {
 584     const int n = 8;
 585     int shift = 36 - (int) p - (int) n;
 586     if (shift < 0 || shift > 35) {
 587         sim_printf ("putbits36_8: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 588         return;
 589     }
 590     word36 mask = ~ (~0U<<n);  // n low bits on
 591     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 592     // caller may provide val that is too big, e.g., a word with all bits
 593     // set to one, so we mask val
 594     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 595 }
 596 
 597 static inline void putbits36_9 (word36 * x, uint p, word9 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 598 {
 599     const int n = 9;
 600     int shift = 36 - (int) p - (int) n;
 601     if (shift < 0 || shift > 35) {
 602         sim_printf ("putbits36_9: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 603         return;
 604     }
 605     word36 mask = ~ (~0U<<n);  // n low bits on
 606     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 607     // caller may provide val that is too big, e.g., a word with all bits
 608     // set to one, so we mask val
 609 #ifndef __OPEN64__
 610 # ifdef __GNUC__
 611 #  ifndef __clang_version__
 612 #   if __GNUC__ > 3
 613 #    pragma GCC diagnostic push
 614 #    pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 615 #   endif /* if __GNUC__ > 3 */
 616 #  endif /* ifndef __clang_version__ */
 617 # endif /* ifdef __GNUC__ */
 618 #endif /* ifndef __OPEN64__ */
 619     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 620 #ifndef __OPEN64__
 621 # ifdef __GNUC__
 622 #  ifndef __clang_version__
 623 #   if __GNUC__ > 3
 624 #    pragma GCC diagnostic pop
 625 #   endif /* if __GNUC__ > 3 */
 626 #  endif /* ifndef __clang_version__ */
 627 # endif /* ifdef __GNUC__ */
 628 #endif /* ifndef __OPEN64__ */
 629 }
 630 
 631 static inline void putbits36_10 (word36 * x, uint p, word10 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 632 {
 633     const int n = 10;
 634     int shift = 36 - (int) p - (int) n;
 635     if (shift < 0 || shift > 35) {
 636         sim_printf ("putbits36_10: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 637         return;
 638     }
 639     word36 mask = ~ (~0U<<n);  // n low bits on
 640     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 641     // caller may provide val that is too big, e.g., a word with all bits
 642     // set to one, so we mask val
 643     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 644 }
 645 
 646 static inline void putbits36_12 (word36 * x, uint p, word12 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 647 {
 648     const int n = 12;
 649     int shift = 36 - (int) p - (int) n;
 650     if (shift < 0 || shift > 35) {
 651         sim_printf ("putbits36_12: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 652         return;
 653     }
 654     word36 mask = ~ (~0U<<n);  // n low bits on
 655     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 656     // caller may provide val that is too big, e.g., a word with all bits
 657     // set to one, so we mask val
 658     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 659 }
 660 
 661 static inline void putbits36_13 (word36 * x, uint p, word13 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 662 {
 663     const int n = 13;
 664     int shift = 36 - (int) p - (int) n;
 665     if (shift < 0 || shift > 35) {
 666         sim_printf ("putbits36_13: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 667         return;
 668     }
 669     word36 mask = ~ (~0U<<n);  // n low bits on
 670     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 671     // caller may provide val that is too big, e.g., a word with all bits
 672     // set to one, so we mask val
 673     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 674 }
 675 
 676 static inline void putbits36_14 (word36 * x, uint p, word14 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 677 {
 678     const int n = 14;
 679     int shift = 36 - (int) p - (int) n;
 680     if (shift < 0 || shift > 35) {
 681         sim_printf ("putbits36_14: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 682         return;
 683     }
 684     word36 mask = ~ (~0U<<n);  // n low bits on
 685     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 686     // caller may provide val that is too big, e.g., a word with all bits
 687     // set to one, so we mask val
 688     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 689 }
 690 
 691 static inline void putbits36_15 (word36 * x, uint p, word15 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 692 {
 693     const int n = 15;
 694     int shift = 36 - (int) p - (int) n;
 695     if (shift < 0 || shift > 35) {
 696         sim_printf ("putbits36_15: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 697         return;
 698     }
 699     word36 mask = ~ (~0U<<n);  // n low bits on
 700     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 701     // caller may provide val that is too big, e.g., a word with all bits
 702     // set to one, so we mask val
 703     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 704 }
 705 
 706 static inline void putbits36_16 (word36 * x, uint p, word16 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 707 {
 708     const int n = 16;
 709     int shift = 36 - (int) p - (int) n;
 710     if (shift < 0 || shift > 35) {
 711         sim_printf ("putbits36_16: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 712         return;
 713     }
 714     word36 mask = ~ (~0U<<n);  // n low bits on
 715     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 716     // caller may provide val that is too big, e.g., a word with all bits
 717     // set to one, so we mask val
 718     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 719 }
 720 
 721 static inline void putbits36_17 (word36 * x, uint p, word17 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 722 {
 723     const int n = 17;
 724     int shift = 36 - (int) p - (int) n;
 725     if (shift < 0 || shift > 35) {
 726         sim_printf ("putbits36_17: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 727         return;
 728     }
 729     word36 mask = ~ (~0U<<n);  // n low bits on
 730     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 731     // caller may provide val that is too big, e.g., a word with all bits
 732     // set to one, so we mask val
 733     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 734 }
 735 
 736 static inline void putbits36_18 (word36 * x, uint p, word18 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 737 {
 738     const int n = 18;
 739     int shift = 36 - (int) p - (int) n;
 740     if (shift < 0 || shift > 35) {
 741         sim_printf ("putbits36_18: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 742         return;
 743     }
 744     word36 mask = ~ (~0U<<n);  // n low bits on
 745     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 746     // caller may provide val that is too big, e.g., a word with all bits
 747     // set to one, so we mask val
 748     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 749 }
 750 
 751 static inline void putbits36_23 (word36 * x, uint p, word23 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 752 {
 753     const int n = 23;
 754     int shift = 36 - (int) p - (int) n;
 755     if (shift < 0 || shift > 35) {
 756         sim_printf ("putbits36_23: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 757         return;
 758     }
 759     word36 mask = ~ (~0U<<n);  // n low bits on
 760     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 761     // caller may provide val that is too big, e.g., a word with all bits
 762     // set to one, so we mask val
 763     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 764 }
 765 
 766 static inline void putbits36_24 (word36 * x, uint p, word24 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 767 {
 768     const int n = 24;
 769     int shift = 36 - (int) p - (int) n;
 770     if (shift < 0 || shift > 35) {
 771         sim_printf ("putbits36_24: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 772         return;
 773     }
 774     word36 mask = ~ (~0U<<n);  // n low bits on
 775     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 776     // caller may provide val that is too big, e.g., a word with all bits
 777     // set to one, so we mask val
 778     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 779 }
 780 
 781 static inline void putbits36_28 (word36 * x, uint p, word28 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 782 {
 783     const int n = 28;
 784     int shift = 36 - (int) p - (int) n;
 785     if (shift < 0 || shift > 35) {
 786         sim_printf ("putbits36_28: bad args (%012llu,pos=%d)\n", (unsigned long long)*x, p);
 787         return;
 788     }
 789     word36 mask = ~ (~0U<<n);  // n low bits on
 790     word36 smask = mask << (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 791     // caller may provide val that is too big, e.g., a word with all bits
 792     // set to one, so we mask val
 793     * x = (* x & ~ smask) | (((word36) val & mask) << shift);
 794 }
 795 
 796 static inline void putbits72 (word72 * x, uint p, uint n, word72 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 797   {
 798     int shift = 72 - (int) p - (int) n;
 799     if (shift < 0 || shift > 71)
 800       {
 801         sim_printf ("putbits72: bad args (pos=%d,n=%d)\n", p, n);
 802         return;
 803       }
 804 #ifdef NEED_128
 805 // n low bits on
 806     uint64_t lowmask = 0;
 807     uint64_t highmask = 0;
 808     if (n >= 64)
 809       {
 810         lowmask = MASK64;
 811         highmask = ~ ((~(uint64_t)0) << n);
 812         highmask &= 0377U;
 813       }
 814     else
 815       {
 816         lowmask = ~ ((~(uint64_t)0) << n);
 817       }
 818     word72 mask = construct_128 (highmask, lowmask);
 819     mask = lshift_128 (mask, (uint) shift);
 820     word72 notmask = complement_128 (mask);
 821     * x = or_128 (and_128 (* x, notmask), and_128 (lshift_128 (val, 72 - p - n), mask));
 822 #else
 823     word72 mask = ~ ((~(word72)0) << n);  // n low bits on
 824     mask <<= (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 825     // caller may provide val that is too big, e.g., a word with all bits
 826     // set to one, so we mask val
 827     * x = (* x & ~mask) | ((val & MASKBITS72 (n)) << (72 - p - n));
 828 #endif
 829     return;
 830   }
 831 
 832 //  getbits18 (data, starting bit, number of bits)
 833 
 834 static inline word18 getbits18 (word18 x, uint i, uint n)
     /* [previous][next][first][last][top][bottom][index][help] */
 835   {
 836     // bit 17 is right end, bit zero is 18th from the right
 837     int shift = 17 - (int) i - (int) n + 1;
 838     if (shift < 0 || shift > 17)
 839       {
 840         sim_printf ("getbits18: bad args (%06o,i=%d,n=%d)\n", x, i, n);
 841         return 0;
 842       }
 843     else
 844       return (x >> (unsigned) shift) & ~ (~0U << n);
 845   }
 846 
 847 //  putbits18 (data, starting bit, number of bits, bits)
 848 
 849 static inline void putbits18 (word18 * x, uint p, uint n, word18 val)
     /* [previous][next][first][last][top][bottom][index][help] */
 850   {
 851     int shift = 18 - (int) p - (int) n;
 852     if (shift < 0 || shift > 17)
 853       {
 854         sim_printf ("putbits18: bad args (%06o,pos=%d,n=%d)\n", * x, p, n);
 855         return;
 856       }
 857     word18 mask = ~ (~0U << n);  // n low bits on
 858     mask <<= (unsigned) shift;  // shift 1s to proper position; result 0*1{n}0*
 859     // caller may provide val that is too big, e.g., a word with all bits
 860     // set to one, so we mask val
 861     * x = (* x & ~mask) | ((val & MASKBITS18 (n)) << (18 - p - n));
 862     return;
 863   }
 864 
 865 //
 866 // setmask -- set bits from mask
 867 //
 868 
 869 static inline void setmask (word36 * v, word36 mask)
     /* [previous][next][first][last][top][bottom][index][help] */
 870   {
 871     * v |= mask;
 872   }
 873 
 874 //
 875 // clrmask -- clear bits from mask
 876 //
 877 
 878 static inline void clrmask (word36 * v, word36 mask)
     /* [previous][next][first][last][top][bottom][index][help] */
 879   {
 880     * v &= ~mask;
 881   }
 882 
 883 char * strdupesc (const char * str);
 884 word36 extr36 (uint8 * bits, uint woffset);
 885 void put36 (word36 val, uint8 * bits, uint woffset);
 886 int extractASCII36FromBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 *wordp);
 887 int extractWord36FromBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 *wordp);
 888 int insertASCII36toBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 word);
 889 int insertWord36toBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 word);
 890 void print_int128 (int128 n, char * p);
 891 char * print_int128o (int128 n, char * p);
 892 word36 Add36b (word36 op1, word36 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf);
 893 word36 Sub36b (word36 op1, word36 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf);
 894 word18 Add18b (word18 op1, word18 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf);
 895 word18 Sub18b (word18 op1, word18 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf);
 896 word72 Add72b (word72 op1, word72 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf);
 897 word72 Sub72b (word72 op1, word72 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf);
 898 
 899 void timespec_diff(struct timespec *start, struct timespec *stop,
 900                    struct timespec *result);
 901 
 902 #if defined(THREADZ) || defined(LOCKLESS)
 903 void currentTR (word27 * trunits, bool * ovf);
 904 #endif

/* [previous][next][first][last][top][bottom][index][help] */