irmode.c 12.4 KB
Newer Older
Christian Schäfer's avatar
Christian Schäfer committed
1
2
3
4
5
6
7
/* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
** All rights reserved.
**
** Authors: Martin Trapp, Christian Schaefer
**
*/

Boris Boesler's avatar
Boris Boesler committed
8
9
/* $Id$ */

Boris Boesler's avatar
added    
Boris Boesler committed
10
11
12
13
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

Götz Lindenmaier's avatar
Götz Lindenmaier committed
14
# include "irmode_t.h"
Christian Schäfer's avatar
Christian Schäfer committed
15
16
# include <malloc.h>
# include <stddef.h>
17
# include <string.h>
Christian Schäfer's avatar
Christian Schäfer committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# include "tv.h"

ir_mode *mode_T;
ir_mode *mode_f;
ir_mode *mode_d;
ir_mode *mode_c;
ir_mode *mode_C;
ir_mode *mode_h;
ir_mode *mode_H;
ir_mode *mode_i;
ir_mode *mode_I;
ir_mode *mode_l;
ir_mode *mode_L;
ir_mode *mode_B;
ir_mode *mode_b;
ir_mode *mode_p;
ir_mode *mode_s;
ir_mode *mode_S;
ir_mode *mode_X;
ir_mode *mode_M;
ir_mode *mode_R;
ir_mode *mode_Z;

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
INLINE ir_mode *get_modeT() { return mode_T; }
INLINE ir_mode *get_modef() { return mode_f; }
INLINE ir_mode *get_moded() { return mode_d; }
INLINE ir_mode *get_modec() { return mode_c; }
INLINE ir_mode *get_modeC() { return mode_C; }
INLINE ir_mode *get_modeh() { return mode_h; }
INLINE ir_mode *get_modeH() { return mode_H; }
INLINE ir_mode *get_modei() { return mode_i; }
INLINE ir_mode *get_modeI() { return mode_I; }
INLINE ir_mode *get_model() { return mode_l; }
INLINE ir_mode *get_modeL() { return mode_L; }
INLINE ir_mode *get_modeB() { return mode_B; }
INLINE ir_mode *get_modep() { return mode_b; }
INLINE ir_mode *get_modeb() { return mode_p; }
INLINE ir_mode *get_modes() { return mode_s; }
INLINE ir_mode *get_modeS() { return mode_S; }
INLINE ir_mode *get_modeX() { return mode_X; }
INLINE ir_mode *get_modeM() { return mode_M; }
INLINE ir_mode *get_modeR() { return mode_R; }
INLINE ir_mode *get_modeZ() { return mode_Z; }
61

Christian Schäfer's avatar
Christian Schäfer committed
62
63
64
void
init_mode (void)
{
Götz Lindenmaier's avatar
Götz Lindenmaier committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  /* allocate all modes. We need to memset them as tarval_vrfy
     reads fields before they are initialized: It compares to
     min/max when tarvals for min/max are allocated!  */
  mode_T = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_T, 0, sizeof(ir_mode));
  mode_f = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_f, 0, sizeof(ir_mode));
  mode_d = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_d, 0, sizeof(ir_mode));
  mode_c = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_c, 0, sizeof(ir_mode));
  mode_C = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_C, 0, sizeof(ir_mode));
  mode_h = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_h, 0, sizeof(ir_mode));
  mode_H = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_H, 0, sizeof(ir_mode));
  mode_i = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_i, 0, sizeof(ir_mode));
  mode_I = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_I, 0, sizeof(ir_mode));
  mode_l = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_l, 0, sizeof(ir_mode));
  mode_L = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_L, 0, sizeof(ir_mode));
  mode_B = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_B, 0, sizeof(ir_mode));
  mode_b = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_b, 0, sizeof(ir_mode));
  mode_p = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_p, 0, sizeof(ir_mode));
  mode_s = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_s, 0, sizeof(ir_mode));
  mode_S = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_S, 0, sizeof(ir_mode));
  mode_X = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_X, 0, sizeof(ir_mode));
  mode_M = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_M, 0, sizeof(ir_mode));
  mode_R = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_R, 0, sizeof(ir_mode));
  mode_Z = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Z, 0, sizeof(ir_mode));
Christian Schäfer's avatar
Christian Schäfer committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

  mode_T->code = irm_T;
  mode_f->code = irm_f;
  mode_d->code = irm_d;
  mode_c->code = irm_c;
  mode_C->code = irm_C;
  mode_h->code = irm_h;
  mode_H->code = irm_H;
  mode_i->code = irm_i;
  mode_I->code = irm_I;
  mode_l->code = irm_l;
  mode_L->code = irm_L;
  mode_B->code = irm_B;
  mode_b->code = irm_b;
  mode_p->code = irm_p;
  mode_s->code = irm_s;
  mode_S->code = irm_S;
  mode_X->code = irm_X;
  mode_M->code = irm_M;
  mode_R->code = irm_R;
  mode_Z->code = irm_Z;

  /* initialize all modes */

  mode_T->name = id_from_str ("T", 1);
  mode_T->fsigned = 0;
  mode_T->ffloat = 0;

  /* float */
  mode_f->name = id_from_str ("f", 1);
  mode_f->fsigned = 1;
  mode_f->ffloat = 1;
120
121
  mode_f->ld_align = 4;
  mode_f->size = 4;
Christian Schäfer's avatar
Christian Schäfer committed
122
123
124
125
126

  /* double */
  mode_d->name = id_from_str ("d", 1);
  mode_d->fsigned = 1;
  mode_d->ffloat = 1;
127
128
  mode_d->ld_align = 4;
  mode_d->size = 8;
Christian Schäfer's avatar
Christian Schäfer committed
129
130
131
132
133

  /* signed char */
  mode_c->name = id_from_str ("c", 1);
  mode_c->fsigned = 1;
  mode_c->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
134
  mode_c->ld_align = 1;
Christian Schäfer's avatar
Christian Schäfer committed
135
136
137
138
139
140
141
142
143
  mode_c->size = 1;
  mode_c->min = tarval_from_long (mode_l, 0xffffff80);
  mode_c->max = tarval_from_long (mode_l, 0x0000007f);
  mode_c->null = tarval_from_long (mode_c, 0);

  /* unsigned char */
  mode_C->name = id_from_str ("C", 1);
  mode_C->fsigned = 0;
  mode_C->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
144
  mode_C->ld_align = 1;
Christian Schäfer's avatar
Christian Schäfer committed
145
146
147
148
149
150
151
152
153
  mode_C->size = 1;
  mode_C->min = tarval_from_long (mode_L, 0x00000000);
  mode_C->max = tarval_from_long (mode_L, 0x000000ff);
  mode_C->null = tarval_from_long (mode_C, 0);

  /* signed short integer */
  mode_h->name = id_from_str ("h", 1);
  mode_h->fsigned = 1;
  mode_h->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
154
155
  mode_h->ld_align = 2;
  mode_h->size = 2;
Christian Schäfer's avatar
Christian Schäfer committed
156
157
158
159
160
161
162
163
  mode_h->min = tarval_from_long (mode_l, 0xffff8000);
  mode_h->max = tarval_from_long (mode_l, 0x00007fff);
  mode_h->null = tarval_from_long (mode_h, 0);

  /* unsigened short integer */
  mode_H->name = id_from_str ("H", 1);
  mode_H->fsigned = 0;
  mode_H->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
164
165
  mode_H->ld_align = 2;
  mode_H->size = 2;
Christian Schäfer's avatar
Christian Schäfer committed
166
167
168
169
170
171
172
173
  mode_H->min = tarval_from_long (mode_L, 0x00000000);
  mode_H->max = tarval_from_long (mode_L, 0x0000ffff);
  mode_H->null = tarval_from_long (mode_H, 0);

  /* signed integer */
  mode_i->name = id_from_str ("i", 1);
  mode_i->fsigned = 1;
  mode_i->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
174
  mode_i->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
175
176
177
178
179
180
181
182
183
  mode_i->size = 4;
  mode_i->min = tarval_from_long (mode_l, 0x80000000);
  mode_i->max = tarval_from_long (mode_l, 0x7fffffff);
  mode_i->null = tarval_from_long (mode_i, 0);

  /* unsigned integer */
  mode_I->name = id_from_str ("I", 1);
  mode_I->fsigned = 0;
  mode_I->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
184
  mode_I->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
185
186
187
188
189
190
191
192
193
  mode_I->size = 4;
  mode_I->min = tarval_from_long (mode_L, 0x00000000);
  mode_I->max = tarval_from_long (mode_L, 0xffffffff);
  mode_I->null = tarval_from_long (mode_I, 0);

  /* signed long integer */
  mode_l->name = id_from_str ("l", 1);
  mode_l->fsigned = 1;
  mode_l->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
194
  mode_l->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
195
196
197
198
199
200
201
202
203
  mode_l->size = 4;
  mode_l->min = tarval_from_long (mode_l, 0x80000000);
  mode_l->max = tarval_from_long (mode_l, 0x7fffffff);
  mode_I->null = tarval_from_long (mode_l, 0);

  /* unsigned long integer */
  mode_L->name = id_from_str ("L", 1);
  mode_L->fsigned = 0;
  mode_L->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
204
  mode_L->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  mode_L->size = 4;
  mode_L->min = tarval_from_long (mode_L, 0x00000000);
  mode_L->max = tarval_from_long (mode_L, 0xffffffff);
  mode_L->null = tarval_from_long (mode_L, 0);

  /* universal bits */
  mode_B->name = id_from_str ("B", 1);
  mode_B->fsigned = 0;
  mode_B->ffloat = 0;

  /* boolean */
  mode_b->name = id_from_str ("b", 1);
  mode_b->fsigned = 0;
  mode_b->ffloat = 0;

  /* pointer */
  mode_p->name = id_from_str ("p", 1);
  mode_p->fsigned = 0;
  mode_p->ffloat = 0;
Boris Boesler's avatar
Boris Boesler committed
224
  mode_p->ld_align = 4;
Christian Schäfer's avatar
Christian Schäfer committed
225
226
227
228
229
230
231
232
233
234
235
236
237
  mode_p->size = 4;
  mode_p->min = tarval_from_long (mode_L, 0x00000000);
  mode_p->max = tarval_from_long (mode_L, 0xffffffff);
  mode_p->null = tarval_from_long (mode_p, 0);

  mode_s->name = id_from_str ("s", 1);
  mode_s->fsigned = 0;
  mode_s->ffloat = 0;

  mode_S->name = id_from_str ("S", 1);
  mode_S->fsigned = 0;
  mode_S->ffloat = 0;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
238
  /* Execution */
Christian Schäfer's avatar
Christian Schäfer committed
239
240
241
242
  mode_X->name = id_from_str ("X", 1);
  mode_X->fsigned = 0;
  mode_X->ffloat = 0;

Götz Lindenmaier's avatar
Götz Lindenmaier committed
243
  /* Memory */
Christian Schäfer's avatar
Christian Schäfer committed
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
  mode_M->name = id_from_str ("M", 1);
  mode_M->fsigned = 0;
  mode_M->ffloat = 0;

  mode_R->name = id_from_str ("R", 1);
  mode_R->fsigned = 0;
  mode_R->ffloat = 0;

  mode_Z->name = id_from_str ("Z", 1);
  mode_Z->fsigned = 1;
  mode_Z->ffloat = 0;
}

/* Functions for the direct access to all attributes od a ir_mode */

modecode
Götz Lindenmaier's avatar
Götz Lindenmaier committed
260
get_mode_modecode (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
261
262
263
264
265
{
  return mode->code;
}

/*
266
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
267
set_mode_modecode (ir_mode *mode, modecode code)
Christian Schäfer's avatar
Christian Schäfer committed
268
269
270
271
272
273
274
275
276
277
278
279
{
  mode->code = code;
}
*/

ident *
get_mode_ident (ir_mode *mode)
{
  return mode->name;
}

/*
280
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
281
set_mode_ident (ir_mode *mode, ident *name)
Christian Schäfer's avatar
Christian Schäfer committed
282
283
284
285
286
{
  mode->name = name;
}
*/

287
INLINE const char *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
288
289
290
291
292
293
get_mode_name       (ir_mode *mode) {
  assert(mode);
  return id_to_str(mode->name);
}
/* void  set_mode_name       (ir_mode *mode, char *name);    */

Christian Schäfer's avatar
Christian Schäfer committed
294
int
Götz Lindenmaier's avatar
Götz Lindenmaier committed
295
get_mode_size (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
296
297
298
299
{
  return mode->size;
}
/*
300
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
301
set_mode_size (ir_mode *mode, int size)
Christian Schäfer's avatar
Christian Schäfer committed
302
303
304
305
306
307
{
  mode->size = size;
}
*/

int
Götz Lindenmaier's avatar
Götz Lindenmaier committed
308
get_mode_ld_align (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
309
310
311
312
313
{
  return mode->ld_align;
}

/*
314
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
315
set_mode_ld_align (ir_mode *mode, int ld_align)
Christian Schäfer's avatar
Christian Schäfer committed
316
317
318
319
320
321
{
  mode->ld_align = ld_align;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
322
get_mode_min (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
323
324
325
326
327
{
  return mode->min;
}

/*
328
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
329
set_mode_min (ir_mode *mode, tarval *min)
Christian Schäfer's avatar
Christian Schäfer committed
330
331
332
333
334
335
{
mode->min = min;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
336
get_mode_max (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
337
338
339
340
341
{
  return mode->max;
}

/*
342
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
343
set_mode_max (ir_mode *mode, tarval *max)
Christian Schäfer's avatar
Christian Schäfer committed
344
345
346
347
348
349
{
  mode->max = max;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
350
get_mode_null (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
351
352
353
354
355
{
  return mode->null;
}

/*
356
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
357
set_mode_null (ir_mode *mode, tarval *null)
Christian Schäfer's avatar
Christian Schäfer committed
358
359
360
361
362
363
{
  mode->null = null;
}
*/

unsigned
Götz Lindenmaier's avatar
Götz Lindenmaier committed
364
get_mode_fsigned (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
365
366
367
368
369
{
  return mode->fsigned;
}

/*
370
INLINE voida
Götz Lindenmaier's avatar
Götz Lindenmaier committed
371
set_mode_fsigned (ir_mode *mode, unsigned fsigned)
Christian Schäfer's avatar
Christian Schäfer committed
372
373
374
375
376
377
{
  mode->fsigned = fsigned;
}
*/

unsigned
Götz Lindenmaier's avatar
Götz Lindenmaier committed
378
get_mode_ffloat (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
379
380
381
382
383
{
  return mode->ffloat;
}

/*
384
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
385
set_mode_ffloat (ir_mode *mode, unsigned ffloat)
Christian Schäfer's avatar
Christian Schäfer committed
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
{
  mode->ffloat = ffloat;
}
*/

/* Functions to check, whether a modecode is signed, float, int, num, data,
   datab or dataM. For more exact definitions read the corresponding pages
   in the firm documentation or the followingenumeration

   The set of "float" is defined as:
   ---------------------------------
   float = {irm_f, irm_d}

   The set of "int" is defined as:
   -------------------------------
   int   = {irm_c, irm_C, irm_h, irm_H, irm_i, irm_I, irm_l, irm_L}

   The set of "num" is defined as:
   -------------------------------
   num   = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H,
            irm_i, irm_I, irm_l, irm_L}
            = {float || int}

   The set of "data" is defined as:
   -------------------------------
   data  = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H,
            irm_i, irm_I, irm_l, irm_L, irm_p}
            = {num || irm_p}

   The set of "datab" is defined as:
   ---------------------------------
   datab = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H,
            irm_i, irm_I, irm_l, irm_L, irm_p, irm_b, irm_B}
            = {data || irm_b || irm_B}

   The set of "dataM" is defined as:
   ---------------------------------
   dataM = {irm_f, irm_d, irm_c, irm_C, irm_h, irm_H, irm_i,
            irm_I, irm_l, irm_L, irm_p, irm_M}
            = {data || irm_M}
*/

int
mode_is_signed (ir_mode *mode)
{
   int res;
   unsigned fsigned;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
433
   fsigned = get_mode_fsigned (mode);
Christian Schäfer's avatar
Christian Schäfer committed
434
435
436
437
438
439
440
441
442
443
444
445
446
447
   if (fsigned == 1) {
     res = 1;
    }
   else {
     res = 0;
   }
   return res;
}

int
mode_is_float (ir_mode *mode)
{
   int res;
   unsigned ffloat;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
448
   ffloat = get_mode_ffloat (mode);
Christian Schäfer's avatar
Christian Schäfer committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
   if (ffloat == 1) {
      res = 1;
    }
   else {
     res = 0;
   }
   return res;
}


int
mode_is_int (ir_mode *mode)
{
   int res;
   modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
464
   code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
   if ((code >= irm_c) &&  (code <= irm_L)) {
      res = 1;
    }
   else {
     res = 0;
   }
   return res;
}


int
mode_is_num (ir_mode *mode)
{
  int res;
  if (mode_is_int (mode) || mode_is_float (mode)) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_data (ir_mode *mode)
{
  int res;
  modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
493
  code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
494
495
496
497
498
499
500
501
502
503
504
505
506
507
  if (mode_is_num (mode) || code == irm_p) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_datab (ir_mode *mode)
{
  int res;
  modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
508
  code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
509
510
511
512
513
514
515
516
517
518
519
520
521
522
  if (mode_is_data (mode) || code == irm_b || code == irm_B) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_dataM (ir_mode *mode)
{
  int res;
  modecode code;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
523
  code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
524
525
526
527
528
529
530
531
  if (mode_is_data (mode) || code == irm_M) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}
532
533
534
535
536
537
538
539
540
541

/* Returns true if sm can be converted to lm without loss. */
bool
smaller_mode(ir_mode *sm, ir_mode *lm) {
  if ((mode_is_int(sm) && mode_is_int(lm)) &&
      get_mode_modecode(sm) <= get_mode_modecode(lm))
    return true;
  if ((mode_is_float(sm) && mode_is_float(lm)) &&
      get_mode_modecode(sm) <= get_mode_modecode(lm))
    return true;
542
  return(false);
543
}