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

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"
Boris Boesler's avatar
Boris Boesler committed
15
# include <stdlib.h>
Christian Schäfer's avatar
Christian Schäfer committed
16
# include <stddef.h>
17
# include <string.h>
Christian Schäfer's avatar
Christian Schäfer committed
18
19
20
# include "tv.h"

ir_mode *mode_T;
Matthias Heil's avatar
Matthias Heil committed
21
22
23
24
25
26
27
28
29
30
31
ir_mode *mode_F;
ir_mode *mode_D;
ir_mode *mode_E;
ir_mode *mode_Bs;
ir_mode *mode_Bu;
ir_mode *mode_Hs;
ir_mode *mode_Hu;
ir_mode *mode_Is;
ir_mode *mode_Iu;
ir_mode *mode_Ls;
ir_mode *mode_Lu;
Christian Schäfer's avatar
Christian Schäfer committed
32
ir_mode *mode_C;
33
ir_mode *mode_U;
Christian Schäfer's avatar
Christian Schäfer committed
34
ir_mode *mode_b;
Matthias Heil's avatar
Matthias Heil committed
35
ir_mode *mode_P;
Christian Schäfer's avatar
Christian Schäfer committed
36
37
ir_mode *mode_X;
ir_mode *mode_M;
Matthias Heil's avatar
Matthias Heil committed
38
ir_mode *mode_BB;
Christian Schäfer's avatar
Christian Schäfer committed
39

40
INLINE ir_mode *get_modeT() { return mode_T; }
Matthias Heil's avatar
Matthias Heil committed
41
42
43
44
45
46
47
48
49
50
51
INLINE ir_mode *get_modeF() { return mode_F; }
INLINE ir_mode *get_modeD() { return mode_D; }
INLINE ir_mode *get_modeE() { return mode_E; }
INLINE ir_mode *get_modeBs() { return mode_Bs; }
INLINE ir_mode *get_modeBu() { return mode_Bu; }
INLINE ir_mode *get_modeHs() { return mode_Hs; }
INLINE ir_mode *get_modeHu() { return mode_Hu; }
INLINE ir_mode *get_modeIs() { return mode_Is; }
INLINE ir_mode *get_modeIu() { return mode_Iu; }
INLINE ir_mode *get_modeLs() { return mode_Ls; }
INLINE ir_mode *get_modeLu() { return mode_Lu; }
52
INLINE ir_mode *get_modeC() { return mode_C; }
53
INLINE ir_mode *get_modeU() { return mode_U; }
Matthias Heil's avatar
Matthias Heil committed
54
55
INLINE ir_mode *get_modeb() { return mode_b; }
INLINE ir_mode *get_modeP() { return mode_P; }
56
57
INLINE ir_mode *get_modeX() { return mode_X; }
INLINE ir_mode *get_modeM() { return mode_M; }
Matthias Heil's avatar
Matthias Heil committed
58
INLINE ir_mode *get_modeBB() { return mode_BB; }
59

Christian Schäfer's avatar
Christian Schäfer committed
60
61
62
void
init_mode (void)
{
Götz Lindenmaier's avatar
Götz Lindenmaier committed
63
64
65
  /* 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!  */
Matthias Heil's avatar
Matthias Heil committed
66
67
68
69
70
71
72
73
74
75
76
77
78
  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_E  = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_E, 0, sizeof(ir_mode));
  mode_Bs = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Bs, 0, sizeof(ir_mode));
  mode_Bu = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Bu, 0, sizeof(ir_mode));
  mode_Hs = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Hs, 0, sizeof(ir_mode));
  mode_Hu = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Hu, 0, sizeof(ir_mode));
  mode_Is = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Is, 0, sizeof(ir_mode));
  mode_Iu = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Iu, 0, sizeof(ir_mode));
  mode_Ls = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Ls, 0, sizeof(ir_mode));
  mode_Lu = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_Lu, 0, sizeof(ir_mode));
  mode_C  = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_C, 0, sizeof(ir_mode));
79
  mode_U  = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_U, 0, sizeof(ir_mode));
Matthias Heil's avatar
Matthias Heil committed
80
81
82
83
84
  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_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_BB = (ir_mode *) malloc (sizeof (ir_mode)); memset(mode_BB, 0, sizeof(ir_mode));
Christian Schäfer's avatar
Christian Schäfer committed
85
86

  mode_T->code = irm_T;
Matthias Heil's avatar
Matthias Heil committed
87
88
89
90
91
92
93
94
95
96
97
  mode_F->code = irm_F;
  mode_D->code = irm_D;
  mode_E->code = irm_E;
  mode_Bs->code = irm_Bs;
  mode_Bu->code = irm_Bu;
  mode_Hs->code = irm_Hs;
  mode_Hu->code = irm_Hu;
  mode_Is->code = irm_Is;
  mode_Iu->code = irm_Iu;
  mode_Ls->code = irm_Ls;
  mode_Lu->code = irm_Lu;
Christian Schäfer's avatar
Christian Schäfer committed
98
  mode_C->code = irm_C;
99
  mode_U->code = irm_U;
Christian Schäfer's avatar
Christian Schäfer committed
100
  mode_b->code = irm_b;
Matthias Heil's avatar
Matthias Heil committed
101
  mode_P->code = irm_P;
Christian Schäfer's avatar
Christian Schäfer committed
102
103
  mode_X->code = irm_X;
  mode_M->code = irm_M;
Matthias Heil's avatar
Matthias Heil committed
104
  mode_BB->code = irm_BB;
Christian Schäfer's avatar
Christian Schäfer committed
105
106
107
108
109
110
111
112

  /* initialize all modes */

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

  /* float */
Matthias Heil's avatar
Matthias Heil committed
113
114
115
116
117
  mode_F->name = id_from_str ("F", 1);
  mode_F->fsigned = 1;
  mode_F->ffloat = 1;
  mode_F->ld_align = 4;
  mode_F->size = 4;
Christian Schäfer's avatar
Christian Schäfer committed
118
119

  /* double */
Matthias Heil's avatar
Matthias Heil committed
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  mode_D->name = id_from_str ("D", 1);
  mode_D->fsigned = 1;
  mode_D->ffloat = 1;
  mode_D->ld_align = 4;
  mode_D->size = 8;

  /* extended */
  mode_E->name = id_from_str ("E", 1);
  mode_E->fsigned = 1;
  mode_E->ffloat = 1;
  mode_E->ld_align = 4;
  mode_E->size = 12;

  /* signed byte */
  mode_Bs->name = id_from_str ("Bs", 1);
  mode_Bs->fsigned = 1;
  mode_Bs->ffloat = 0;
  mode_Bs->ld_align = 1;
  mode_Bs->size = 1;
  mode_Bs->min = tarval_from_long (mode_Ls, 0xffffff80);
  mode_Bs->max = tarval_from_long (mode_Ls, 0x0000007f);
  mode_Bs->null = tarval_from_long (mode_Bs, 0);

  /* unsigned byte */
  mode_Bu->name = id_from_str ("Bu", 1);
  mode_Bu->fsigned = 0;
  mode_Bu->ffloat = 0;
  mode_Bu->ld_align = 1;
  mode_Bu->size = 1;
  mode_Bu->min = tarval_from_long (mode_Lu, 0x00000000);
  mode_Bu->max = tarval_from_long (mode_Lu, 0x000000ff);
  mode_Bu->null = tarval_from_long (mode_Bu, 0);
Christian Schäfer's avatar
Christian Schäfer committed
152
153

  /* signed short integer */
Matthias Heil's avatar
Matthias Heil committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  mode_Hs->name = id_from_str ("Hs", 1);
  mode_Hs->fsigned = 1;
  mode_Hs->ffloat = 0;
  mode_Hs->ld_align = 2;
  mode_Hs->size = 2;
  mode_Hs->min = tarval_from_long (mode_Ls, 0xffff8000);
  mode_Hs->max = tarval_from_long (mode_Ls, 0x00007fff);
  mode_Hs->null = tarval_from_long (mode_Hs, 0);

  /* unsigned short integer */
  mode_Hu->name = id_from_str ("Hu", 1);
  mode_Hu->fsigned = 0;
  mode_Hu->ffloat = 0;
  mode_Hu->ld_align = 2;
  mode_Hu->size = 2;
  mode_Hu->min = tarval_from_long (mode_Lu, 0x00000000);
  mode_Hu->max = tarval_from_long (mode_Lu, 0x0000ffff);
  mode_Hu->null = tarval_from_long (mode_Hu, 0);
Christian Schäfer's avatar
Christian Schäfer committed
172
173

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

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

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

  /* unsigned long integer */
Matthias Heil's avatar
Matthias Heil committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
  mode_Lu->name = id_from_str ("Lu", 1);
  mode_Lu->fsigned = 0;
  mode_Lu->ffloat = 0;
  mode_Lu->ld_align = 8;
  mode_Lu->size = 8;
  mode_Lu->min = tarval_from_long (mode_Lu, 0x00000000);
  mode_Lu->max = tarval_from_long (mode_Lu, 0xffffffff);
  mode_Lu->null = tarval_from_long (mode_Lu, 0);

  /* character */
  mode_C->name = id_from_str ("C", 1);
  mode_C->fsigned = 0;
  mode_C->ffloat = 0;
  mode_C->ld_align = 1;
  mode_C->size = 1;
  mode_C->min = tarval_from_long (mode_Ls, 0xffffff80);
  mode_C->max = tarval_from_long (mode_Ls, 0x0000007f);
  mode_C->null = tarval_from_long (mode_C, 0);
Christian Schäfer's avatar
Christian Schäfer committed
222

223
  /* unicode character */
Götz Lindenmaier's avatar
Bugfix    
Götz Lindenmaier committed
224
225
226
227
228
229
230
231
  mode_U->name = id_from_str ("U", 1);
  mode_U->fsigned = 0;
  mode_U->ffloat = 0;
  mode_U->ld_align = 1;
  mode_U->size = 2;
  mode_U->min = tarval_from_long (mode_Ls, 0xffff8000);
  mode_U->max = tarval_from_long (mode_Ls, 0x00007fff);
  mode_U->null = tarval_from_long (mode_U, 0);
232

Christian Schäfer's avatar
Christian Schäfer committed
233
234
235
236
237
238
  /* boolean */
  mode_b->name = id_from_str ("b", 1);
  mode_b->fsigned = 0;
  mode_b->ffloat = 0;

  /* pointer */
Matthias Heil's avatar
Matthias Heil committed
239
240
241
242
243
244
245
246
  mode_P->name = id_from_str ("P", 1);
  mode_P->fsigned = 0;
  mode_P->ffloat = 0;
  mode_P->ld_align = 4;
  mode_P->size = 4;
  mode_P->min = tarval_from_long (mode_Lu, 0x00000000);
  mode_P->max = tarval_from_long (mode_Lu, 0xffffffff);
  mode_P->null = tarval_from_long (mode_P, 0);
Christian Schäfer's avatar
Christian Schäfer committed
247

Götz Lindenmaier's avatar
Götz Lindenmaier committed
248
  /* Execution */
Christian Schäfer's avatar
Christian Schäfer committed
249
250
251
252
  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
253
  /* Memory */
Christian Schäfer's avatar
Christian Schäfer committed
254
255
256
257
  mode_M->name = id_from_str ("M", 1);
  mode_M->fsigned = 0;
  mode_M->ffloat = 0;

Matthias Heil's avatar
Matthias Heil committed
258
259
260
  mode_BB->name = id_from_str ("BB", 1);
  mode_BB->fsigned = 0;
  mode_BB->ffloat = 0;
Christian Schäfer's avatar
Christian Schäfer committed
261
262
263
264
265
}

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

modecode
Götz Lindenmaier's avatar
Götz Lindenmaier committed
266
get_mode_modecode (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
267
{
Boris Boesler's avatar
Boris Boesler committed
268
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
269
270
271
272
  return mode->code;
}

/*
273
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
274
set_mode_modecode (ir_mode *mode, modecode code)
Christian Schäfer's avatar
Christian Schäfer committed
275
276
277
278
279
280
281
282
{
  mode->code = code;
}
*/

ident *
get_mode_ident (ir_mode *mode)
{
Boris Boesler's avatar
Boris Boesler committed
283
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
284
285
286
287
  return mode->name;
}

/*
288
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
289
set_mode_ident (ir_mode *mode, ident *name)
Christian Schäfer's avatar
Christian Schäfer committed
290
291
292
293
294
{
  mode->name = name;
}
*/

295
INLINE const char *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
296
297
298
299
300
301
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
302
int
Götz Lindenmaier's avatar
Götz Lindenmaier committed
303
get_mode_size (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
304
{
Boris Boesler's avatar
Boris Boesler committed
305
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
306
307
308
  return mode->size;
}
/*
309
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
310
set_mode_size (ir_mode *mode, int size)
Christian Schäfer's avatar
Christian Schäfer committed
311
312
313
314
315
316
{
  mode->size = size;
}
*/

int
Götz Lindenmaier's avatar
Götz Lindenmaier committed
317
get_mode_ld_align (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
318
{
Boris Boesler's avatar
Boris Boesler committed
319
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
320
321
322
323
  return mode->ld_align;
}

/*
324
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
325
set_mode_ld_align (ir_mode *mode, int ld_align)
Christian Schäfer's avatar
Christian Schäfer committed
326
327
328
329
330
331
{
  mode->ld_align = ld_align;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
332
get_mode_min (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
333
{
Boris Boesler's avatar
Boris Boesler committed
334
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
335
336
337
338
  return mode->min;
}

/*
339
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
340
set_mode_min (ir_mode *mode, tarval *min)
Christian Schäfer's avatar
Christian Schäfer committed
341
342
343
344
345
346
{
mode->min = min;
}
*/

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
347
get_mode_max (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
348
{
Boris Boesler's avatar
Boris Boesler committed
349
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
350
351
352
353
  return mode->max;
}

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

tarval *
Götz Lindenmaier's avatar
Götz Lindenmaier committed
362
get_mode_null (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
363
{
Boris Boesler's avatar
Boris Boesler committed
364
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
365
366
367
368
  return mode->null;
}

/*
369
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
370
set_mode_null (ir_mode *mode, tarval *null)
Christian Schäfer's avatar
Christian Schäfer committed
371
372
373
374
375
376
{
  mode->null = null;
}
*/

unsigned
Götz Lindenmaier's avatar
Götz Lindenmaier committed
377
get_mode_fsigned (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
378
{
Boris Boesler's avatar
Boris Boesler committed
379
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
380
381
382
383
  return mode->fsigned;
}

/*
384
INLINE voida
Götz Lindenmaier's avatar
Götz Lindenmaier committed
385
set_mode_fsigned (ir_mode *mode, unsigned fsigned)
Christian Schäfer's avatar
Christian Schäfer committed
386
387
388
389
390
391
{
  mode->fsigned = fsigned;
}
*/

unsigned
Götz Lindenmaier's avatar
Götz Lindenmaier committed
392
get_mode_ffloat (ir_mode *mode)
Christian Schäfer's avatar
Christian Schäfer committed
393
{
Boris Boesler's avatar
Boris Boesler committed
394
  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
395
396
397
398
  return mode->ffloat;
}

/*
399
INLINE void
Götz Lindenmaier's avatar
Götz Lindenmaier committed
400
set_mode_ffloat (ir_mode *mode, unsigned ffloat)
Christian Schäfer's avatar
Christian Schäfer committed
401
402
403
404
405
406
407
408
409
410
411
{
  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:
   ---------------------------------
Matthias Heil's avatar
Matthias Heil committed
412
   float = {irm_F, irm_D, irm_E}
Christian Schäfer's avatar
Christian Schäfer committed
413
414
415

   The set of "int" is defined as:
   -------------------------------
Matthias Heil's avatar
Matthias Heil committed
416
   int   = {irm_Bs, irm_Bu, irm_Hs, irm_Hu, irm_Is, irm_Iu, irm_Ls, irm_Lu}
Christian Schäfer's avatar
Christian Schäfer committed
417
418
419

   The set of "num" is defined as:
   -------------------------------
Matthias Heil's avatar
Matthias Heil committed
420
421
   num   = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
            irm_Is, irm_Iu, irm_Ls, irm_Lu}
Christian Schäfer's avatar
Christian Schäfer committed
422
423
424
425
            = {float || int}

   The set of "data" is defined as:
   -------------------------------
Matthias Heil's avatar
Matthias Heil committed
426
   data  = {irm_F, irm_D, irm_E irm_Bs, irm_Bu, irm_Hs, irm_Hu,
427
            irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_p}
Matthias Heil's avatar
Matthias Heil committed
428
            = {num || irm_C || irm_P}
Christian Schäfer's avatar
Christian Schäfer committed
429
430
431

   The set of "datab" is defined as:
   ---------------------------------
Matthias Heil's avatar
Matthias Heil committed
432
   datab = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
433
            irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_b}
Matthias Heil's avatar
Matthias Heil committed
434
            = {data || irm_b }
Christian Schäfer's avatar
Christian Schäfer committed
435
436
437

   The set of "dataM" is defined as:
   ---------------------------------
Matthias Heil's avatar
Matthias Heil committed
438
   dataM = {irm_F, irm_D, irm_E, irm_Bs, irm_Bu, irm_Hs, irm_Hu,
439
            irm_Is, irm_Iu, irm_Ls, irm_Lu, irm_C, irm_U, irm_P, irm_M}
Christian Schäfer's avatar
Christian Schäfer committed
440
441
442
443
444
445
            = {data || irm_M}
*/

int
mode_is_signed (ir_mode *mode)
{
Boris Boesler's avatar
Boris Boesler committed
446
447
448
449
450
451
452
453
454
455
456
457
  int res;
  unsigned fsigned;

  assert(mode && "no mode given");
  fsigned = get_mode_fsigned (mode);
  if (fsigned == 1) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
Christian Schäfer's avatar
Christian Schäfer committed
458
459
}

460
INLINE int
Christian Schäfer's avatar
Christian Schäfer committed
461
462
mode_is_float (ir_mode *mode)
{
Boris Boesler's avatar
Boris Boesler committed
463
464
465
466
467
468
469
470
471
472
473
474
  int res;
  unsigned ffloat;

  assert(mode && "no mode given");
  ffloat = get_mode_ffloat (mode);
  if (ffloat == 1) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
Christian Schäfer's avatar
Christian Schäfer committed
475
476
477
}


478
INLINE int
Christian Schäfer's avatar
Christian Schäfer committed
479
480
mode_is_int (ir_mode *mode)
{
Boris Boesler's avatar
Boris Boesler committed
481
482
483
484
485
486
487
488
489
490
491
492
  int res;
  modecode code;

  assert(mode && "no mode given");
  code = get_mode_modecode (mode);
  if ((code >= irm_Bs) &&  (code <= irm_Lu)) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
Christian Schäfer's avatar
Christian Schäfer committed
493
494
495
}


496
INLINE int
Christian Schäfer's avatar
Christian Schäfer committed
497
498
499
mode_is_num (ir_mode *mode)
{
  int res;
Boris Boesler's avatar
Boris Boesler committed
500
501

  assert(mode && "no mode given");
Christian Schäfer's avatar
Christian Schäfer committed
502
503
504
505
506
507
508
509
510
  if (mode_is_int (mode) || mode_is_float (mode)) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

511
INLINE int
Christian Schäfer's avatar
Christian Schäfer committed
512
513
514
515
mode_is_data (ir_mode *mode)
{
  int res;
  modecode code;
Boris Boesler's avatar
Boris Boesler committed
516
517

  assert(mode && "no mode given");
Götz Lindenmaier's avatar
Götz Lindenmaier committed
518
  code = get_mode_modecode (mode);
519
520
  if (mode_is_num (mode) ||
      code == irm_C || code == irm_U || code == irm_P) {
Christian Schäfer's avatar
Christian Schäfer committed
521
522
523
524
525
526
527
528
529
530
531
532
533
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_datab (ir_mode *mode)
{
  int res;
  modecode code;
Boris Boesler's avatar
Boris Boesler committed
534
535

  assert(mode && "no mode given");
Götz Lindenmaier's avatar
Götz Lindenmaier committed
536
  code = get_mode_modecode (mode);
Matthias Heil's avatar
Matthias Heil committed
537
  if (mode_is_data (mode) || code == irm_b ) {
Christian Schäfer's avatar
Christian Schäfer committed
538
539
540
541
542
543
544
545
546
547
548
549
550
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}

int
mode_is_dataM (ir_mode *mode)
{
  int res;
  modecode code;
Boris Boesler's avatar
Boris Boesler committed
551
552

  assert(mode && "no mode given");
Götz Lindenmaier's avatar
Götz Lindenmaier committed
553
  code = get_mode_modecode (mode);
Christian Schäfer's avatar
Christian Schäfer committed
554
555
556
557
558
559
560
561
  if (mode_is_data (mode) || code == irm_M) {
    res = 1;
  }
  else {
    res = 0;
  }
  return res;
}
562
563
564
565
566
567
568
569
570
571

/* 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;
572
  return(false);
573
}