Re: [ooc-compiler] Implementation of SYSTEM.LSH
Brought to you by:
mva
|
From: August K. <fus...@co...> - 2005-12-05 14:40:33
|
Stewart Greenhill wrote: -snip- > Ideally, what we need is something like this: > > /* ASH(x,n) */ > #define _ashl(_x,_n) (ST(_x) << _n) > #define _ashr(_x,_n) (ST(_x) >> _n) > #define _ash(_x,_n) (_n >= 0) ? _ashl(_x,_n) : _ashr(_x,- _n) > > /* SYSTEM.LSH(x,n) */ > #define _lshl(_x,_n,_type) ((_type)(UT(_x) << _n)) > #define _lshr(_x,_n,_type) ((_type)(UT(_x) >> _n)) > #define _lsh(_type,_x,_n) ((_n >= 0) ? _lshl(_x,_n,_type) : _lshr(_x,- > _n,_type)) > > Where ST(_x) and UT(_x) cast _x to the signed and unsigned > (respectively) types of the same size. Unfortunately, "C" doesn't > provide such an operator, so to make this work OOC would have to pass > this type as an argument to the ASH/LSH function. -snip- Thanks for the detailed explanation. Why not define one function for each type: _ash_OOC_INT8, _ash_OOC_INT16, _ash_OOC_INT32 and so on. As far as I understand the compiler will know which version to choose depending on the type of the first argument. Regards, August |