FLOP types¶
This page provides detailed information about how each floating-point
operation (FLOP) type is counted and analyzed in the counted-float package.
All math.* entries below assume an active FlopCountingContext (outside
one, the math module is not instrumented — see
Math patching semantics). For each flop type, you will
find:
- Relevant scalar instructions for ARM (v8+) and x86 (SSE2+)
- Python operations that are counted for this flop type
- Python operations that are not counted for this flop type
FlopType.ABS (abs(x))¶
- Relevant CPU instructions
- ARM:
FABS - x86:
ANDPD
- ARM:
- Counted Python operations:
abs(x)wherexis aCountedFloat - Not counted:
numpy.abs, complex abs, abs on non-CountedFloat
FlopType.MINUS (-x)¶
- Relevant CPU instructions
- ARM:
FNEG - x86:
XORPD
- ARM:
- Counted Python operations: Unary minus (
-x) forCountedFloat - Not counted: Negation on non-CountedFloat, numpy negation
FlopType.COMP (x<=y, x>y, x==y, x==0.0, ...)¶
- Relevant CPU instructions
- ARM:
FCMP - x86:
(U)COMISD
- ARM:
- Counted Python operations:
x == y,x != y,x <= y, ... andmin(x,y),max(x,y)forCountedFloat - Not counted: Comparisons on non-CountedFloat, numpy comparisons
FlopType.RND (round)¶
- Relevant CPU instructions
- ARM:
FRINT - x86:
ROUNDSD
- ARM:
- Counted Python operations:
round(x, 0)forCountedFloat(returns float) - Not counted:
numpy.round, rounding with decimals, rounding on non-CountedFloat
FlopType.F2I (float->int)¶
- Relevant CPU instructions
- ARM:
FCVTZS - x86:
CVTSD2SI
- ARM:
- Counted Python operations:
int(x),math.floor(x),math.ceil(x),math.trunc(x),round(x)forCountedFloat(returns int) - Not counted: Conversions on non-CountedFloat, numpy conversions
FlopType.I2F (int->float)¶
- Relevant CPU instructions
- ARM:
SCVTF - x86:
CVTSI2SD
- ARM:
- Counted Python operations: Construction of
CountedFloatfrom int, any binary operation where one operand is an int and the other aCountedFloat(e.g.,x + 3,3 * x, etc.) - Not counted:
float(n), unitary operations (e.g.math.sqrton integers -> convert toCountedFloatfirst)
FlopType.ADD (x+y)¶
- Relevant CPU instructions
- ARM:
FADD - x86:
ADDSD
- ARM:
- Counted Python operations:
x + yory + xforCountedFloat - Not counted: Addition on non-CountedFloat, numpy addition
FlopType.SUB (x-y)¶
- Relevant CPU instructions
- ARM:
FSUB - x86:
SUBSD
- ARM:
- Counted Python operations:
x - yory - xforCountedFloat - Not counted: Subtraction on non-CountedFloat, numpy subtraction
FlopType.MUL (x*y)¶
- Relevant CPU instructions
- ARM:
FMUL - x86:
MULSD
- ARM:
- Counted Python operations:
x * yory * xforCountedFloat - Not counted: Multiplication on non-CountedFloat, numpy multiplication
FlopType.DIV (x/y)¶
- Relevant CPU instructions
- ARM:
FDIV - x86:
DIVSD
- ARM:
- Counted Python operations:
x / yory / xforCountedFloat - Not counted: Division on non-CountedFloat, numpy division
FlopType.SQRT (sqrt(x))¶
- Relevant CPU instructions
- ARM:
FSQRT - x86:
SQRTSD
- ARM:
- Counted Python operations:
math.sqrt(x)forCountedFloat - Not counted:
numpy.sqrt, sqrt on non-CountedFloat
FlopType.CBRT (cbrt(x))¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.cbrt(x)forCountedFloat - Not counted:
numpy.cbrt, cbrt on non-CountedFloat
FlopType.EXP (e^x)¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.exp(x)forCountedFloat - Not counted:
math.exp(x)on non-CountedFloat,numpy.exp,math.expm1,math.e ** x
FlopType.EXP2 (2^x)¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
2 ** x,pow(2, x)ormath.exp2(x)forCountedFloat - Not counted:
exp2on non-CountedFloat,numpy.exp2
FlopType.EXP10 (10^x)¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
10 ** x,pow(10, x)forCountedFloat - Not counted:
10 ** xon non-CountedFloat
FlopType.LOG (log(x))¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.log(x)forCountedFloat;math.log(x, base)forCountedFloatdecomposes per the constant-detection heuristic (int base 2/10 -> LOG2/LOG10; other int base -> LOG+MUL; float base -> LOG per counted operand + DIV) - Not counted:
numpy.log, log on non-CountedFloat
FlopType.LOG2 (log2(x))¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.log2(x)forCountedFloat;math.log(x, 2)(int base) forCountedFloat - Not counted:
numpy.log2, log2 on non-CountedFloat
FlopType.LOG10 (log10(x))¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.log10(x)forCountedFloat;math.log(x, 10)(int base) forCountedFloat - Not counted:
numpy.log10, log10 on non-CountedFloat
FlopType.POW (x^y)¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
x ** y,pow(x, y)forCountedFloat - Not counted:
powon non-CountedFloat,numpy.pow
FlopType.SIN (sin(x))¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.sin(x)forCountedFloat - Not counted:
sinon non-CountedFloat,numpy.sin
FlopType.COS (cos(x))¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.cos(x)forCountedFloat - Not counted:
coson non-CountedFloat,numpy.cos
FlopType.TAN (tan(x))¶
- Relevant CPU instructions
- ARM: (software)
- x86: (software)
- Counted Python operations:
math.tan(x)forCountedFloat - Not counted:
tanon non-CountedFloat,numpy.tan