Composite operations on s32 integers for i386. More...

`#include <linux/types.h>`

Go to the source code of this file.

## Defines | |

#define | l_shl_div(num, SHF, den) |

Computes '(num << SHF) / den' as s32 (32 bits). | |

#define | l_mul_div(x, num, den) |

Computes '(x * num) / den' as s32 (32 bits). | |

#define | l_mul_shr(x, y, SHF) |

Computes '(x * y) >> SHF' as s32 (32 bits). |

Composite operations on s32 integers for i386.

These are implemented in assembler with intermediate results on 64 bits, using native 32-bit multiply and divide operations of the processor. Resulting implementation is hopefully more appropriate than general long-long arithmetics functions coming with gcc, which would not be available anycase inside the kernel (their use would require linking the gcc long-long module within a kernel module).

Definition in file qos_l_i386.h.

#define l_mul_div | ( | x, | |||

num, | |||||

den | ) |

({ \ __volatile__ __s32 _ul_x = (x); \ __volatile__ __s32 _ul_num = (num); \ __volatile__ __s32 _ul_den = (den); \ __volatile__ __s32 _ul_res; \ __asm__ __volatile__("\n" \ " imull %%edx \n" \ " idivl %3 \n" \ : "=a" (_ul_res) \ : "0" (_ul_x), "d" (_ul_num), "r" (_ul_den)); \ _ul_res; \ })

Computes '(x * num) / den' as s32 (32 bits).

Computation is carried on with intermediate result (x * num) on 64 bits.

**Parameters:**-
*x*an s32 integer (32 bits) *num*an s32 integer (32 bits) *den*an s32 integer (32 bits)

**Returns:**- the result as an s32 integer (32 bits)

**Note:**- No overflow check is made after the division.

**Todo:**- Investigate on volatiles, that do not allow optimizations. They should not be required, but without them bw2Q(), which uses l_mul_shr, outputs zero instead of the correct value.

Definition at line 72 of file qos_l_i386.h.

#define l_mul_shr | ( | x, | |||

y, | |||||

SHF | ) |

({ \ __volatile__ __s32 _ul_x = (x); \ __volatile__ __s32 _ul_y = (y); \ __volatile__ __s32 _ul_res; \ __asm__ __volatile__ ("\n" \ " imull %%edx \n" \ " shrdl %2, %%edx, %%eax \n" \ : "=a" (_ul_res) \ : "0" (_ul_x), "I" ((SHF)), "d" (_ul_y)); \ _ul_res; \ })

Computes '(x * y) >> SHF' as s32 (32 bits).

The computation is carried on with intermediate result (x*y) on 64 bits.

This macro is useful for multiplying two integers where one of them represents a real in fixed precision with SHF decimal bits (i.e. 1.0 is represented as 1ul<<SHF).

**Parameters:**-
*x*an s32 integer (32 bits) *y*an s32 integer (32 bits) *SHF*a macro which evaluates to an integer within 1 and 31

**Returns:**- the result as an s32 integer (32 bits)

**Note:**- No overflow check is made after the shift.

**Todo:**- Investigate on volatiles, that do not allow optimizations. They should not be required, but without them bw2Q(), which uses l_mul_shr, outputs zero instead of the correct value.

Definition at line 105 of file qos_l_i386.h.

Referenced by main().

#define l_shl_div | ( | num, | |||

SHF, | |||||

den | ) |

({ \ __volatile__ __s32 _ul_num = (num); \ __volatile__ __s32 _ul_den = (den); \ __volatile__ __s32 _ul_res; \ __asm__ __volatile__("\n" \ " cdq \n" \ " shldl %2, %%eax, %%edx \n" \ " shll %2, %%eax \n" \ " idivl %3 \n" \ : "=a" (_ul_res) \ : "0" (_ul_num), "I" ((SHF)), "r" (_ul_den) \ : "%edx"); \ _ul_res; \ })

Computes '(num << SHF) / den' as s32 (32 bits).

Computation is carried on with intermediate result (num << SHF) on 64 bits. This macro is useful for representing the result of the division num/dev as a real in fixed precision with SHF decimal bits (i.e. 1.0 is represented as 1ul<<SHF).

**Parameters:**-
*num*an s32 integer (32 bits) *SHF*a macro which evaluates to an integer within 1 and 31 *den*an s32 integer (32 bits)

**Returns:**- the result as an s32 integer (32 bits)

**Note:**- No overflow check is made after the division.

**Todo:**- Investigate on volatiles, that do not allow optimizations. They should not be required, but without them bw2Q(), which uses l_mul_shr, outputs zero instead of the correct value.

Definition at line 41 of file qos_l_i386.h.

Referenced by main().

Generated on Mon Aug 2 22:39:17 2010 for qosres by 1.6.3