Yes, I just want to write code which is portable (as for example that
`& ...`) but still favors PyPy.

On Mon, Apr 4, 2016 at 3:49 PM, Maciej Fijalkowski <fij...@gmail.com> wrote:
> right, so there is no way to get wrap-around arithmetics in cpython
> without modifications
>
> On Mon, Apr 4, 2016 at 3:48 PM, Tuom Larsen <tuom.lar...@gmail.com> wrote:
>> I would like to avoid numpy, if possible. Even if it might be bundled
>> with PyPy (is it?) I still would like the code to run in CPython with
>> no dependencies.
>>
>> On Mon, Apr 4, 2016 at 3:45 PM, Maciej Fijalkowski <fij...@gmail.com> wrote:
>>> so numpy64 will give you wrap-around arithmetics. What else are you
>>> looking for? :-)
>>>
>>> On Mon, Apr 4, 2016 at 3:38 PM, Tuom Larsen <tuom.lar...@gmail.com> wrote:
>>>> You mean I should first store the result into numpy's `int64`, and
>>>> then to `array.array`? Like:
>>>>
>>>>     x = int64(2**63 << 1)
>>>>     a[0] = x
>>>>
>>>> Or:
>>>>
>>>>     x = int64(2**63)
>>>>     x[0] = x << 1
>>>>
>>>> What the "real types" goes, is this the only option?
>>>>
>>>> Thanks in any case!
>>>>
>>>>
>>>> On Mon, Apr 4, 2016 at 3:32 PM, Maciej Fijalkowski <fij...@gmail.com> 
>>>> wrote:
>>>>> one option would be to use integers from _numpypy module:
>>>>>
>>>>> from numpy import int64 after installing numpy.
>>>>>
>>>>> There are obscure ways to get it without installing numpy. Another
>>>>> avenue would be to use __pypy__.intop.int_mul etc.
>>>>>
>>>>> Feel free to complain "no, I want real types that I can work with" :-)
>>>>>
>>>>> Cheers,
>>>>> fijal
>>>>>
>>>>> On Mon, Apr 4, 2016 at 3:10 PM, Tuom Larsen <tuom.lar...@gmail.com> wrote:
>>>>>> Hello!
>>>>>>
>>>>>> Suppose I'm on 64-bit machine and there is an `a = arrar.array('L',
>>>>>> [0])` (item size is 8 bytes). In Python, when an integer does not fit
>>>>>> machine width it gets promoted to "long" integer of arbitrary size. So
>>>>>> this will fail:
>>>>>>
>>>>>>     a[0] = 2**63 << 1
>>>>>>
>>>>>> To fix this, one could instead write:
>>>>>>
>>>>>>     a[0] = (2**63 << 1) & (2**64 - 1)
>>>>>>
>>>>>> My question is, when I know that the result will be stored in
>>>>>> `array.array` anyway, how to prevent the promotion to long integers?
>>>>>> What is the most performat way to perform such calculations? Is PyPy
>>>>>> able to optimize away that `& (2**64 - 1)` when I use `'L'` typecode?
>>>>>>
>>>>>> I mean, in C I wouldn't have to worry about it as everything above the
>>>>>> 63rd bit will be simply cut off. I would like to help PyPy to generate
>>>>>> the best possible code, does anyone have some suggestions please?
>>>>>>
>>>>>> Thanks!
>>>>>> _______________________________________________
>>>>>> pypy-dev mailing list
>>>>>> pypy-dev@python.org
>>>>>> https://mail.python.org/mailman/listinfo/pypy-dev
_______________________________________________
pypy-dev mailing list
pypy-dev@python.org
https://mail.python.org/mailman/listinfo/pypy-dev

Reply via email to