8000 [mypyc] Generate faster code for bool comparisons and arithmetic by JukkaL · Pull Request #14489 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

[mypyc] Generate faster code for bool comparisons and arithmetic #14489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 5, 2023
Prev Previous commit
Next Next commit
Merge branch 'master' into mypyc-bool2
  • Loading branch information
JukkaL authored Jan 26, 2023
commit 4c06cc92d4152de87f8441c91c4b65f580bd765b
104 changes: 104 additions & 0 deletions mypyc/test-data/irbuild-i64.test
Original file line number Diff line number Diff line change
Expand Up @@ -1769,3 +1769,107 @@ L1:
return r3
L2:
return 1

[case testI64Cast]
from typing import cast
from mypy_extensions import i64

def cast_object(o: object) -> i64:
return cast(i64, o)

def cast_int(x: int) -> i64:
return cast(i64, x)
[out]
def cast_object(o):
o :: object
r0 :: int64
L0:
r0 = unbox(int64, o)
return r0
def cast_int(x):
x :: int
r0 :: native_int
r1 :: bit
r2, r3 :: int64
r4 :: ptr
r5 :: c_ptr
r6 :: int64
L0:
r0 = x & 1
r1 = r0 == 0
if r1 goto L1 else goto L2 :: bool
L1:
r2 = x >> 1
r3 = r2
goto L3
L2:
r4 = x ^ 1
r5 = r4
r6 = CPyLong_AsInt64(r5)
r3 = r6
keep_alive x
L3:
return r3

[case testI64ExplicitConversionFromVariousTypes]
from mypy_extensions import i64

def bool_to_i64(b: bool) -> i64:
return i64(b)

def str_to_i64(s: str) -> i64:
return i64(s)

def str_to_i64_with_base(s: str) -> i64:
return i64(s, 2)

class C:
def __int__(self) -> i64:
return 5

def instance_to_i64(c: C) -> i64:
return i64(c)

def float_to_i64(x: float) -> i64:
return i64(x)
[out]
def bool_to_i64(b):
b :: bool
r0 :: int64
L0:
r0 = extend b: builtins.bool to int64
return r0
def str_to_i64(s):
s :: str
r0 :: object
r1 :: int64
L0:
r0 = CPyLong_FromStr(s)
r1 = unbox(int64, r0)
return r1
def str_to_i64_with_base(s):
s :: str
r0 :: object
r1 :: int64
L0:
r0 = CPyLong_FromStrWithBase(s, 4)
r1 = unbox(int64, r0)
return r1
def C.__int__(self):
self :: __main__.C
L0:
return 5
def instance_to_i64(c):
c :: __main__.C
r0 :: int64
L0:
r0 = c.__int__()
return r0
def float_to_i64(x):
x :: float
r0 :: object
r1 :: int64
L0:
r0 = CPyLong_FromFloat(x)
r1 = unbox(int64, r0)
return r1
You are viewing a condensed version of this merge commit. You can view the full changes here.
0