Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4422002
bitwise.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
bitwise.h
View Options
#ifndef SV_BITWISE_H
#define SV_BITWISE_H
#include
"errors.h"
#include
"silver/engine.h"
#include
"modules/bigint.h"
static
inline
ant_value_t
sv_op_band
(
sv_vm_t
*
vm
,
ant_t
*
js
)
{
ant_value_t
r
=
vm
->
stack
[
--
vm
->
sp
];
ant_value_t
l
=
vm
->
stack
[
--
vm
->
sp
];
uint8_t
lt
=
vtype
(
l
),
rty
=
vtype
(
r
);
if
(
lt
==
T_BIGINT
||
rty
==
T_BIGINT
)
{
if
(
lt
!=
T_BIGINT
||
rty
!=
T_BIGINT
)
return
js_mkerr
(
js
,
"Cannot mix BigInt value and other types"
);
ant_value_t
res
=
bigint_bitand
(
js
,
l
,
r
);
if
(
is_err
(
res
))
return
res
;
vm
->
stack
[
vm
->
sp
++
]
=
res
;
return
tov
(
0
);
}
int32_t
ai
=
(
lt
==
T_NUM
)
?
js_to_int32
(
tod
(
l
))
:
js_to_int32
(
js_to_number
(
js
,
l
));
int32_t
bi
=
(
rty
==
T_NUM
)
?
js_to_int32
(
tod
(
r
))
:
js_to_int32
(
js_to_number
(
js
,
r
));
vm
->
stack
[
vm
->
sp
++
]
=
tov
((
double
)(
ai
&
bi
));
return
tov
(
0
);
}
static
inline
ant_value_t
sv_op_bor
(
sv_vm_t
*
vm
,
ant_t
*
js
)
{
ant_value_t
r
=
vm
->
stack
[
--
vm
->
sp
];
ant_value_t
l
=
vm
->
stack
[
--
vm
->
sp
];
uint8_t
lt
=
vtype
(
l
),
rty
=
vtype
(
r
);
if
(
lt
==
T_BIGINT
||
rty
==
T_BIGINT
)
{
if
(
lt
!=
T_BIGINT
||
rty
!=
T_BIGINT
)
return
js_mkerr
(
js
,
"Cannot mix BigInt value and other types"
);
ant_value_t
res
=
bigint_bitor
(
js
,
l
,
r
);
if
(
is_err
(
res
))
return
res
;
vm
->
stack
[
vm
->
sp
++
]
=
res
;
return
tov
(
0
);
}
int32_t
ai
=
(
lt
==
T_NUM
)
?
js_to_int32
(
tod
(
l
))
:
js_to_int32
(
js_to_number
(
js
,
l
));
int32_t
bi
=
(
rty
==
T_NUM
)
?
js_to_int32
(
tod
(
r
))
:
js_to_int32
(
js_to_number
(
js
,
r
));
vm
->
stack
[
vm
->
sp
++
]
=
tov
((
double
)(
ai
|
bi
));
return
tov
(
0
);
}
static
inline
ant_value_t
sv_op_bxor
(
sv_vm_t
*
vm
,
ant_t
*
js
)
{
ant_value_t
r
=
vm
->
stack
[
--
vm
->
sp
];
ant_value_t
l
=
vm
->
stack
[
--
vm
->
sp
];
uint8_t
lt
=
vtype
(
l
),
rty
=
vtype
(
r
);
if
(
lt
==
T_BIGINT
||
rty
==
T_BIGINT
)
{
if
(
lt
!=
T_BIGINT
||
rty
!=
T_BIGINT
)
return
js_mkerr
(
js
,
"Cannot mix BigInt value and other types"
);
ant_value_t
res
=
bigint_bitxor
(
js
,
l
,
r
);
if
(
is_err
(
res
))
return
res
;
vm
->
stack
[
vm
->
sp
++
]
=
res
;
return
tov
(
0
);
}
int32_t
ai
=
(
lt
==
T_NUM
)
?
js_to_int32
(
tod
(
l
))
:
js_to_int32
(
js_to_number
(
js
,
l
));
int32_t
bi
=
(
rty
==
T_NUM
)
?
js_to_int32
(
tod
(
r
))
:
js_to_int32
(
js_to_number
(
js
,
r
));
vm
->
stack
[
vm
->
sp
++
]
=
tov
((
double
)(
ai
^
bi
));
return
tov
(
0
);
}
static
inline
ant_value_t
sv_op_bnot
(
sv_vm_t
*
vm
,
ant_t
*
js
)
{
ant_value_t
a
=
vm
->
stack
[
--
vm
->
sp
];
if
(
vtype
(
a
)
==
T_BIGINT
)
{
ant_value_t
res
=
bigint_bitnot
(
js
,
a
);
if
(
is_err
(
res
))
return
res
;
vm
->
stack
[
vm
->
sp
++
]
=
res
;
return
tov
(
0
);
}
vm
->
stack
[
vm
->
sp
++
]
=
tov
((
double
)(
~
js_to_int32
(
js_to_number
(
js
,
a
))));
return
tov
(
0
);
}
static
inline
ant_value_t
sv_op_shl
(
sv_vm_t
*
vm
,
ant_t
*
js
)
{
ant_value_t
r
=
vm
->
stack
[
--
vm
->
sp
];
ant_value_t
l
=
vm
->
stack
[
--
vm
->
sp
];
uint8_t
lt
=
vtype
(
l
),
rty
=
vtype
(
r
);
if
(
lt
==
T_BIGINT
||
rty
==
T_BIGINT
)
{
if
(
lt
!=
T_BIGINT
||
rty
!=
T_BIGINT
)
return
js_mkerr
(
js
,
"Cannot mix BigInt value and other types"
);
uint64_t
shift
=
0
;
ant_value_t
err
=
bigint_asint_bits
(
js
,
r
,
&
shift
);
if
(
is_err
(
err
))
return
err
;
ant_value_t
res
=
bigint_shift_left
(
js
,
l
,
shift
);
if
(
is_err
(
res
))
return
res
;
vm
->
stack
[
vm
->
sp
++
]
=
res
;
return
tov
(
0
);
}
int32_t
ai
=
(
lt
==
T_NUM
)
?
js_to_int32
(
tod
(
l
))
:
js_to_int32
(
js_to_number
(
js
,
l
));
uint32_t
bi
=
(
rty
==
T_NUM
)
?
js_to_uint32
(
tod
(
r
))
:
js_to_uint32
(
js_to_number
(
js
,
r
));
vm
->
stack
[
vm
->
sp
++
]
=
tov
((
double
)(
ai
<<
(
bi
&
0x1f
)));
return
tov
(
0
);
}
static
inline
ant_value_t
sv_op_shr
(
sv_vm_t
*
vm
,
ant_t
*
js
)
{
ant_value_t
r
=
vm
->
stack
[
--
vm
->
sp
];
ant_value_t
l
=
vm
->
stack
[
--
vm
->
sp
];
uint8_t
lt
=
vtype
(
l
),
rty
=
vtype
(
r
);
if
(
lt
==
T_BIGINT
||
rty
==
T_BIGINT
)
{
if
(
lt
!=
T_BIGINT
||
rty
!=
T_BIGINT
)
return
js_mkerr
(
js
,
"Cannot mix BigInt value and other types"
);
uint64_t
shift
=
0
;
ant_value_t
err
=
bigint_asint_bits
(
js
,
r
,
&
shift
);
if
(
is_err
(
err
))
return
err
;
ant_value_t
res
=
bigint_shift_right
(
js
,
l
,
shift
);
if
(
is_err
(
res
))
return
res
;
vm
->
stack
[
vm
->
sp
++
]
=
res
;
return
tov
(
0
);
}
int32_t
ai
=
(
lt
==
T_NUM
)
?
js_to_int32
(
tod
(
l
))
:
js_to_int32
(
js_to_number
(
js
,
l
));
uint32_t
bi
=
(
rty
==
T_NUM
)
?
js_to_uint32
(
tod
(
r
))
:
js_to_uint32
(
js_to_number
(
js
,
r
));
vm
->
stack
[
vm
->
sp
++
]
=
tov
((
double
)(
ai
>>
(
bi
&
0x1f
)));
return
tov
(
0
);
}
static
inline
ant_value_t
sv_op_ushr
(
sv_vm_t
*
vm
,
ant_t
*
js
)
{
ant_value_t
r
=
vm
->
stack
[
--
vm
->
sp
];
ant_value_t
l
=
vm
->
stack
[
--
vm
->
sp
];
uint8_t
lt
=
vtype
(
l
),
rty
=
vtype
(
r
);
if
(
lt
==
T_BIGINT
||
rty
==
T_BIGINT
)
{
if
(
lt
!=
T_BIGINT
||
rty
!=
T_BIGINT
)
return
js_mkerr
(
js
,
"Cannot mix BigInt value and other types"
);
uint64_t
shift
=
0
;
ant_value_t
err
=
bigint_asint_bits
(
js
,
r
,
&
shift
);
if
(
is_err
(
err
))
return
err
;
ant_value_t
res
=
bigint_shift_right_logical
(
js
,
l
,
shift
);
if
(
is_err
(
res
))
return
res
;
vm
->
stack
[
vm
->
sp
++
]
=
res
;
return
tov
(
0
);
}
uint32_t
ai
=
(
lt
==
T_NUM
)
?
js_to_uint32
(
tod
(
l
))
:
js_to_uint32
(
js_to_number
(
js
,
l
));
uint32_t
bi
=
(
rty
==
T_NUM
)
?
js_to_uint32
(
tod
(
r
))
:
js_to_uint32
(
js_to_number
(
js
,
r
));
vm
->
stack
[
vm
->
sp
++
]
=
tov
((
double
)(
ai
>>
(
bi
&
0x1f
)));
return
tov
(
0
);
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Sat, May 2, 1:01 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
540445
Default Alt Text
bitwise.h (5 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment