10
10
%% of arithmetic on SPARC.
11
11
%% XXX: This code is seldom used, and hence also
13
%% Look here for strange bugs appering when
13
%% Look here for strange bugs appearing when
14
14
%% turning on rtl_prop.
16
16
%% History : * 2002-10-23 Erik Stenman (happi@csd.uu.se):
20
%% $Date: 2003/04/23 11:58:14 $
20
%% $Date: 2004/04/30 06:58:44 $
22
22
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24
-include("../main/hipe.hrl").
26
24
-module(hipe_rtl_arith_32).
27
-export([eval_alu/3,eval_alub/4, eval_cond/3]).
25
-export([eval_alu/3, eval_alub/4, eval_cond/3, eval_cond_bits/5]).
31
-define(WORDMASK,16#ffffffff).
32
-define(MAX_SIGNED_INT, 16#7fffffff).
33
-define(MIN_SIGNED_INT,-16#80000000).
28
-define(SIGN_BIT, 31).
29
-define(WORDMASK, 16#ffffffff).
30
-define(MAX_SIGNED_INT, 16#7fffffff).
31
-define(MIN_SIGNED_INT, -16#80000000).
34
32
-define(MAX_UNSIGNED_INT, 16#ffffffff).
39
%% {Res, Sign, Zero, Overflow, Carry}
40
%% Res will be a number in the range
41
%% MAX_SIGNED_INT >= Res >= MIN_SIGNED_INT
42
%% The other four values are flags that are either true or false
44
eval_alu(Op, Arg1, Arg2)
45
when Arg1 =< ?MAX_SIGNED_INT,
46
Arg1 >= ?MIN_SIGNED_INT,
47
Arg2 =< ?MAX_SIGNED_INT,
48
Arg2 >= ?MIN_SIGNED_INT ->
50
Sign1 = sign_bit(Arg1),
51
Sign2 = sign_bit(Arg2),
55
Res = (Arg1 - Arg2) band ?WORDMASK,
58
V = (Sign1 and (not Sign2) and (not N))
60
((not Sign1) and Sign2 and N),
61
C = ((not Sign1) and Sign2)
63
(N and ((not Sign1) or Sign2));
66
Res = (Arg1 + Arg2) band ?WORDMASK,
69
V = (Sign1 and Sign2 and (not N))
71
((not Sign1) and (not Sign2) and N),
74
((not N) and (Sign1 or Sign2));
76
Res = (Arg1 bsr Arg2) band ?WORDMASK,
82
Res = (Arg1 bsr Arg2) band shiftmask(Arg2),
88
Res = (Arg1 bsl Arg2) band ?WORDMASK,
94
Res = (Arg1 bor Arg2) band ?WORDMASK,
100
Res = (Arg1 band Arg2) band ?WORDMASK,
106
Res = (Arg1 bxor Arg2) band ?WORDMASK,
112
Res = N = Z = V = C = 0,
113
?EXIT({"unknown alu op", Op})
115
{two_comp_to_erl(Res),N,Z,V,C};
116
eval_alu(Op,Arg1,Arg2) ->
117
?EXIT({argument_overflow,Op,Arg1,Arg2}).
120
eval_alub(Op, Cond, Arg1, Arg2) ->
121
{Res,N,Z,V,C} = eval_alu(Op,Arg1,Arg2),
128
{Res, not (Z or (N xor V))};
132
{Res, not (N xor V)};
140
{Res, Z or (N xor V)};
148
?EXIT({'condition code not handled',Cond})
151
eval_cond(Cond, Arg1, Arg2) ->
152
{_,Bool} = eval_alub('sub', Cond, Arg1, Arg2),
157
((Val bsr ?SIGN_BIT) band 1) =:= 1.
158
two_comp_to_erl(V) ->
159
if V > ?MAX_SIGNED_INT ->
160
- ((?MAX_UNSIGNED_INT + 1) - V);
166
round(math:pow(2,Setbits)-1).
34
-include("../main/hipe.hrl"). %% for ?EXIT
36
-include("hipe_rtl_arith.inc").