summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/cg/tshlshr.pp
blob: fee24145acce894e7d86c0fdf46d87c76b06a1e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
{***********************************************************}
{ CODE GENERATOR TEST SUITE                                *}
{***********************************************************}
{ NODE TESTED : secondshlshr()                             *}
{***********************************************************}
{ PRE-REQUISITES: secondload()                              }
{                 secondassign()                            }
{                 secondtypeconv()                          }
{                 secondinline() with strings only!         }
{                 secondadd() comparison                    }
{                 secondifn()                               }
{***********************************************************}
{ DEFINES  :  FPC if target is Free Pascal compiler         }
{***********************************************************}
{ REMARKS: None                                             }
{***********************************************************}
Program tshlshr;

{----------------------------------------------------}
{ Cases to test:                                     }
{   RIGHT NODE (shift count value)                   }
{     - LOC_CREGISTER                                }
{     - LOC_REFERENCE / LOC_MEM                      }
{     - LOC_REGISTER                                 }
{     - numeric constant                             }
{   LEFT NODE (value to shift)                       }
{     - LOC_CREGISTER                                }
{     - LOC_REFERENCE / LOC_MEM                      }
{     - LOC_REGISTER                                 }
{----------------------------------------------------}
procedure test(value, required: {$ifndef fpc}longint{$else fpc}int64{$endif fpc});
begin
  if value <> required then
    begin
      writeln('Got ',value,' instead of ',required);
      halt(1);
    end
  else
    writeln('Passed!');
end;

type
tint64record = packed record
{$ifdef ENDIAN_BIG}
   highval : longint;
   lowval  : longint;
{$else}
   lowval  : longint;
   highval : longint;
{$endif}
end;


var
 longres :  longint;
 longcnt : longint;
 bytecnt : shortint;
 byteres : shortint;
{$IFDEF FPC}
 int64res : int64;
 int64cnt : int64;
 int64rec : tint64record;
{$ENDIF}
Begin
   WriteLn('------------------------------ LONGINT --------------------------------');
   { left : LOC_REFERENCE     }
   { right : numeric constant }
   WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
   longres:=1;
   longres := longres shl 15;
   Write('(SHL) Value should be 32768...');
   test(longres, 32768);

   longres:=-1;
   longres := longres shl 15;
   Write('(SHL) Value should be -32768...');
   test(longres, -32768);

   longres:=1;
   longres := longres shl 33;
   Write('(SHL) Value should be 2...');
   test(longres, 2);

   longres:=$8000;
   longres := longres shr 15;
   Write('(SHR) Value should be 1...');
   test(longres, 1);

   longres:=-1;
   longres := longres shr 15;
   Write('(SHR) Value should be 131071...');
   test(longres, 131071);

   longres:=$FFFF;
   longres := longres shr 33;
   Write('(SHR) Value should be 32767...');
   test(longres, 32767);

   { left : LOC_REFERENCE }
   { right : LOC_REFERENCE }
   WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');

{
   longres := 1;
   longcnt := -2;
   longres:=longres shl longcnt ;
   Write('(SHL) Value should be 1073741824...');
   test(longres, 1073741824);
}

   longres:=1;
   longcnt:=15;
   longres := longres shl longcnt;
   Write('(SHL) Value should be 32768...');
   test(longres, 32768);

   longres:=-1;
   longcnt := 15;
   longres := longres shl longcnt;
   Write('(SHL) Value should be -32768...');
   test(longres, -32768);

{
   longres := 1;
   longcnt := -2;
   longres:=longres shr longcnt ;
   Write('(SHR) Value should be 0...');
   test(longres, 0);
}

   longres:=32768;
   longcnt:=15;
   longres := longres shr longcnt;
   Write('(SHR) Value should be 1...');
   test(longres, 1);

   longres:=-1;
   longcnt := 15;
   longres := longres shl longcnt;
   Write('(SHR) Value should be -32768...');
   test(longres, -32768);

   { left : LOC_REFERENCE }
   { right : LOC_REGISRER }
{
   WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
   longres := 1;
   bytecnt := -2;
   longres:=longres shl bytecnt ;
   Write('(SHL) Value should be 1073741824...');
   test(longres, 1073741824);
}

   longres:=1;
   bytecnt:=15;
   longres := longres shl bytecnt;
   Write('(SHL) Value should be 32768...');
   test(longres, 32768);

   longres:=-1;
   bytecnt := 15;
   longres := longres shl bytecnt;
   Write('(SHL) Value should be -32768...');
   test(longres, -32768);

{
   longres := 1;
   bytecnt := -2;
   longres:=longres shr bytecnt ;
   Write('(SHR) Value should be 0...');
   test(longres, 0);
}

   longres:=32768;
   bytecnt:=15;
   longres := longres shr bytecnt;
   Write('(SHR) Value should be 1...');
   test(longres, 1);

   longres:=-1;
   bytecnt := 15;
   longres := longres shr bytecnt;
   Write('(SHR) Value should be 131071...');
   test(longres, 131071);

   WriteLn('(left) : LOC_REGISTER; (right) : LOC_REGISTER');
   byteres := 1;
   bytecnt := 2;
   byteres := byteres shl bytecnt;
   Write('(SHL) Value should be 4...');
   test(byteres, 4);


   byteres := 4;
   bytecnt := 2;
   byteres := byteres shr bytecnt;
   Write('(SHR) Value should be 1...');
   test(byteres, 1);

{$IFDEF FPC}
   WriteLn('------------------------------  INT64  --------------------------------');
   { left : LOC_REFERENCE     }
   { right : numeric constant }
   WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
   int64res:=1;
   int64res := int64res shl 15;
   Write('(SHL) Value should be 32768...');
   test(int64res, 32768);

   int64res:=-1;
   int64res := int64res shl 15;
   Write('(SHL) Value should be -32768...');
   test(int64res, -32768);


   int64res:=1;
   int64res := int64res shl 65;
   Write('(SHL) Value should be 2...');
   test(int64res, 2);

   int64res:=$8000;
   int64res := int64res shr 15;
   Write('(SHR) Value should be 1...');
   test(int64res, 1);

   int64res:=$FFFF;
   int64res := int64res shr 65;
   Write('(SHR) Value should be 32767...');
   test(int64res, 32767);

   { left : LOC_REFERENCE }
   { right : LOC_REFERENCE }
{
   WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
   int64res := 1;
   int64cnt := -2;
   int64res:=int64res shl int64cnt ;
   Write('(SHL) Value should be 1073741824...');
   test(int64res, 1073741824);
}

   int64res:=1;
   int64cnt:=15;
   int64res := int64res shl int64cnt;
   Write('(SHL) Value should be 32768...');
   test(int64res, 32768);


   int64res:=-1;
   int64cnt := 15;
   int64res := int64res shl int64cnt;
   Write('(SHL) Value should be -32768...');
   test(int64res, -32768);

   int64res := 1;
   int64cnt := 33;
   int64res := int64res shl int64cnt;
   Write('(SHL) Value should be 2 in high longint (85899345)...');
   move(int64res,int64rec, sizeof(int64));
   test(int64rec.highval, 2);
{   test(int64res, 8589934592);}


{
   int64res := 1;
   int64cnt := -2;
   int64res:=int64res shr int64cnt ;
   Write('(SHR) Value should be 0...');
   test(int64res and $FFFFFFFF, 0);
}
   int64res:=32768;
   int64cnt:=15;
   int64res := int64res shr int64cnt;
   Write('(SHR) Value should be 1...');
   test(int64res, 1);

   int64res:=-1;
   int64cnt := 15;
   int64res := int64res shl int64cnt;
   Write('(SHR) Value should be -32768...');
   test(int64res, -32768);

   { left : LOC_REFERENCE }
   { right : LOC_REGISRER }
{
  WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
   int64res := 1;
   bytecnt := -2;
   int64res:=int64res shl bytecnt ;
   Write('(SHL) Value should be 1073741824...');
   test(int64res, 1073741824);
}

   int64res:=1;
   bytecnt:=15;
   int64res := int64res shl bytecnt;
   Write('(SHL) Value should be 32768...');
   test(int64res, 32768);


   int64res:=-1;
   bytecnt := 15;
   int64res := int64res shl bytecnt;
   Write('(SHL) Value should be -32768...');
   test(int64res, -32768);

{
   int64res := 1;
   bytecnt := -2;
   int64res:=int64res shr bytecnt ;
   Write('(SHR) Value should be 0...');
   test(int64res and $FFFFFFFF, 0);
}

   int64res:=32768;
   bytecnt:=15;
   int64res := int64res shr bytecnt;
   Write('(SHR) Value should be 1...');
   test(int64res, 1);

   int64res := 1;
   bytecnt := 33;
   int64res := int64res shl bytecnt;
   Write('(SHL) Value should be 2 in high longint (85899345)...');
   move(int64res,int64rec, sizeof(int64));
   test(int64rec.highval, 2);

{   int64res:=-1;
   bytecnt := 15;
   int64res := int64res shr bytecnt;
   WriteLn('(SHR) Value should be 131071...',int64res);}

{$ENDIF}
end.