My Project  debian-1:4.1.1-p2+ds-4build3
Macros | Functions
cf_inline.cc File Reference
#include "config.h"
#include "cf_assert.h"
#include "canonicalform.h"
#include "int_cf.h"
#include "imm.h"
#include "cf_factory.h"

Go to the source code of this file.

Macros

#define CF_INLINE
 

Functions

CF_INLINE CanonicalForm operator- (const CanonicalForm &cf)
 CF_INLINE CanonicalForm operator - ( const CanonicalForm & cf ) More...
 
CF_INLINE CanonicalForm operator+ (const CanonicalForm &lhs, const CanonicalForm &rhs)
 CF_INLINE CanonicalForm operator +, -, *, /, % ( const CanonicalForm & lhs, const CanonicalForm & rhs ) More...
 
CF_INLINE CanonicalForm operator- (const CanonicalForm &lhs, const CanonicalForm &rhs)
 
CF_INLINE CanonicalForm operator* (const CanonicalForm &lhs, const CanonicalForm &rhs)
 
CF_INLINE CanonicalForm operator/ (const CanonicalForm &lhs, const CanonicalForm &rhs)
 
CF_INLINE CanonicalForm operator% (const CanonicalForm &lhs, const CanonicalForm &rhs)
 
CF_INLINE CanonicalForm div (const CanonicalForm &lhs, const CanonicalForm &rhs)
 CF_INLINE CanonicalForm div, mod ( const CanonicalForm & lhs, const CanonicalForm & rhs ) More...
 
CF_INLINE CanonicalForm mod (const CanonicalForm &lhs, const CanonicalForm &rhs)
 

Detailed Description

definition of configurable inline ‘CanonicalForm’ methods.

Hierarchy: canonicalform

Header file: canonicalform.h

Developers note:

The central class in Factory is, of course, ‘CanonicalForm’. Hence it is a quiet reasonable to assume that inlining its most important methods will improve execution speed. The same holds for some methods of the ‘CFIterator’ class. Everything on configurable inline ‘CanonicalForm’ methods explained here applies mutatis mutandis to the ‘CFIterator’ methods.

However, inlining ‘CanonicalForm’ methods has two major drawbacks:

o If ‘CanonicalForm’ methods simply would have been declared ‘inline’ it would have been necessary to include the definition of ‘InternalCF’ in ‘factory.h’. This would have been quite a contradiction to the internal nature of the class. Hence it seemed desirable to introduce a mechanism to have both the inlined versions for internal use and compiled versions for the library.

o Second, inlining in most cases leads to larger object code. E.g., inlining ‘CanonicalForm::~CanonicalForm()’ increases the object code by approx. 15% without any effect on computation speed. Thus another design aim was to keep things configurable. That is why the methods defined here are called "configurable inline methods".

The low level solution to both problems is the macro ‘CF_INLINE’ which either expands to ‘inline’ or nothing. The counterpart ‘CF_NO_INLINE’ exists only for convenience, it always expands to nothing. ‘CF_INLINE’ is set immediately before defining resp. declaring the methods to exclude any esoteric influences from included files.

The high level interface is the macro ‘CF_USE_INLINE’. If it is defined any header file that uses configurable inline methods defines them to be ‘inline’, otherwise they are defined as ordinary methods. ‘CF_USE_INLINE’ is defined in ‘config.h’ only.

To switch on (off) all configurable inline methods, it is sufficient to define (undefine) ‘CF_USE_INLINE’ in ‘config.h’. To switch off separate configurable inline methods it is necessary to prefix their declaration in ‘canonicalform.h’ by ‘CF_NO_INLINE’ instead of ‘CF_INLINE’. Furthermore, to avoid duplicate symbols at link time, their definition in this file has to be wrapped by an ‘#ifndef INCL_CF_INLINE_CC’.

It turned out that inlining the following methods (and only them) results in the best time to size ratio on Linux and HP machines: o all ‘CanonicalForm’ constructors o the binary ‘CanonicalForm’ operators ‘+’ and ‘*’

Definition in file cf_inline.cc.

Macro Definition Documentation

◆ CF_INLINE

#define CF_INLINE

Definition at line 113 of file cf_inline.cc.

Function Documentation

◆ div()

CF_INLINE CanonicalForm div, mod ( const CanonicalForm & lhs, const CanonicalForm & rhs )

See also
mod(), operator/(), CanonicalForm::operator /=()

Definition at line 553 of file cf_inline.cc.

554 {
555  CanonicalForm result( lhs );
556  result.div( rhs );
557  return result;
558 }

◆ mod()

See also
div(), operator%(), CanonicalForm::operator %=()

Definition at line 564 of file cf_inline.cc.

565 {
566  CanonicalForm result( lhs );
567  result.mod( rhs );
568  return result;
569 }

◆ operator%()

CF_INLINE CanonicalForm operator% ( const CanonicalForm lhs,
const CanonicalForm rhs 
)
See also
CanonicalForm::operator %=()

Definition at line 540 of file cf_inline.cc.

541 {
542  CanonicalForm result( lhs );
543  result %= rhs;
544  return result;
545 }

◆ operator*()

CF_INLINE CanonicalForm operator* ( const CanonicalForm lhs,
const CanonicalForm rhs 
)
See also
CanonicalForm::operator *=()

Definition at line 517 of file cf_inline.cc.

518 {
519  CanonicalForm result( lhs );
520  result *= rhs;
521  return result;
522 }

◆ operator+()

CF_INLINE CanonicalForm operator+ ( const CanonicalForm lhs,
const CanonicalForm rhs 
)

CF_INLINE CanonicalForm operator +, -, *, /, % ( const CanonicalForm & lhs, const CanonicalForm & rhs )

operators +, -, *, /, %(), div(), mod() - binary arithmetic operators.

The binary operators have their standard (mathematical) semantics. As explained for the corresponding arithmetic assignment operators, the operators ‘/’ and ‘%’ return the quotient resp. remainder of (polynomial) division with remainder, whereas ‘div()’ and ‘mod()’ may be used for exact division and term-wise remaindering, resp.

It is faster to use the arithmetic assignment operators (e.g., ‘f += g;’) instead of the binary operators (‘f = f+g;’ ).

Type info:

lhs, rhs: CurrentPP

There are weaker preconditions for some cases (e.g., arithmetic operations with elements from Q or Z work in any domain), but type ‘CurrentPP’ is the only one guaranteed to work for all cases.

Developers note:

All binary operators have their corresponding ‘CanonicalForm’ assignment operators (e.g., ‘operator +()’ corresponds to ‘CanonicalForm::operator +=()’, ‘div()’ corresponds to `CanonicalFormdiv()).

And that is how they are implemented, too: Each of the binary operators first creates a copy of ‘lhs’, adds ‘rhs’ to this copy using the assignment operator, and returns the result.

See also
CanonicalForm::operator +=()

Definition at line 496 of file cf_inline.cc.

497 {
498  CanonicalForm result( lhs );
499  result += rhs;
500  return result;
501 }

◆ operator-() [1/2]

CF_INLINE CanonicalForm operator - ( const CanonicalForm & cf )

operator -() - return additive inverse of ‘cf’.

Returns the additive inverse of ‘cf’. One should keep in mind that to negate a canonical form a complete (deep) copy of it has to be created.

Type info:

cf: CurrentPP

In fact, the type is almost ‘Anything’, but it is, e.g., not possible to invert an element from a finite field when the characteristic of the current domain has changed.

Internal implementation:

All internal methods check whether the reference counter equals one. If so CO is negated in-place. Otherwise, a new copy of CO is created and negated.

imm_neg() Trivial.

imm_neg_p() Use ‘ff_neg()’ to negate CO.

imm_neg_gf() Use ‘gf_neg()’ to negate CO.

InternalInteger::neg() Use ‘mpz_neg()’ to negate the underlying mpi.

InternalRational::neg () Use ‘mpz_neg()’ to negate the denominator.

InternalPrimePower::neg() Subtract CO from ‘primepow’ using ‘mpz_sub’.

InternalPoly::neg() If reference counter is one use ‘negateTermList()’ to negate the terms, otherwise create a negated copy using ‘copyTermList()’.

See also
CanonicalForm::operator -=()

Definition at line 438 of file cf_inline.cc.

439 {
441  int what = is_imm( result.value );
442 
443  if ( ! what )
444  result.value = result.value->neg();
445  else if ( what == INTMARK )
446  result.value = imm_neg( result.value );
447  else if ( what == FFMARK )
448  result.value = imm_neg_p( result.value );
449  else
450  result.value = imm_neg_gf( result.value );
451 
452  return result;
453 }

◆ operator-() [2/2]

CF_INLINE CanonicalForm operator- ( const CanonicalForm lhs,
const CanonicalForm rhs 
)

Definition at line 505 of file cf_inline.cc.

506 {
507  CanonicalForm result( lhs );
508  result -= rhs;
509  return result;
510 }

◆ operator/()

CF_INLINE CanonicalForm operator/ ( const CanonicalForm lhs,
const CanonicalForm rhs 
)
See also
CanonicalForm::operator /=()

Definition at line 529 of file cf_inline.cc.

530 {
531  CanonicalForm result( lhs );
532  result /= rhs;
533  return result;
534 }
result
return result
Definition: facAbsBiFact.cc:76
cf
CanonicalForm cf
Definition: cfModGcd.cc:4024
imm_neg_gf
InternalCF * imm_neg_gf(const InternalCF *const op)
Definition: imm.h:467
imm_neg_p
InternalCF * imm_neg_p(const InternalCF *const op)
Definition: imm.h:461
CanonicalForm
factory's main class
Definition: canonicalform.h:83
INTMARK
const long INTMARK
Definition: imm.h:37
FFMARK
const long FFMARK
Definition: imm.h:38
is_imm
int is_imm(const InternalCF *const ptr)
Definition: canonicalform.h:62
imm_neg
InternalCF * imm_neg(const InternalCF *const op)
Definition: imm.h:455