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

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