AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
arith.c File Reference

i386: 64-bit division, for the code GCC generates. More...

#include <stdint.h>

Go to the source code of this file.

Functions

static uint32_t divl (uint64_t n, uint32_t d)
 Divides the 64-bit n by the 32-bit d with the x86 DIVL instruction, and returns the 32-bit quotient.
static int nlz (uint32_t x)
 Returns the number of leading zero bits in x, which must not be 0.
static uint64_t udiv64 (uint64_t n, uint64_t d)
 Divides the unsigned 64-bit n by the unsigned 64-bit d, and returns the quotient.
static uint64_t umod64 (uint64_t n, uint64_t d)
 Divides the unsigned 64-bit n by the unsigned 64-bit d, and returns the remainder.
static int64_t sdiv64 (int64_t n, int64_t d)
 Divides the signed 64-bit n by the signed 64-bit d, and returns the quotient.
static int64_t smod64 (int64_t n, int64_t d)
 Divides the signed 64-bit n by the signed 64-bit d, and returns the remainder.
long long __divdi3 (long long n, long long d)
 Divides two signed 64-bit integers.
long long __moddi3 (long long n, long long d)
 Computes the remainder of two signed 64-bit integers.
unsigned long long __udivdi3 (unsigned long long n, unsigned long long d)
 Divides two unsigned 64-bit integers.
unsigned long long __umoddi3 (unsigned long long n, unsigned long long d)
 Computes the remainder of two unsigned 64-bit integers.
unsigned long long __udivmoddi4 (unsigned long long n, unsigned long long d, unsigned long long *rem)
 Divides two unsigned 64-bit integers, giving both the quotient and the remainder.

Detailed Description

i386: 64-bit division, for the code GCC generates.

A 32-bit CPU has no instruction that divides 64-bit numbers, so GCC calls these helpers (__divdi3() and the others) for / and % on 64-bit integers. User programs get them from libgcc; the kernel isn't linked with it, so it has its own. They come from Pintos (https://www.ida.liu.se/~TDIU25/pintos/src/lib/arithmetic.c).

Definition in file arith.c.

Function Documentation

◆ __divdi3()

long long __divdi3 ( long long n,
long long d )

Divides two signed 64-bit integers.

Parameters
nthe dividend
dthe divisor
Returns
the quotient

Definition at line 150 of file arith.c.

References __divdi3(), and sdiv64().

Referenced by __divdi3().

◆ __moddi3()

long long __moddi3 ( long long n,
long long d )

Computes the remainder of two signed 64-bit integers.

Parameters
nthe dividend
dthe divisor
Returns
the remainder

Definition at line 162 of file arith.c.

References __moddi3(), and smod64().

Referenced by __moddi3().

◆ __udivdi3()

unsigned long long __udivdi3 ( unsigned long long n,
unsigned long long d )

Divides two unsigned 64-bit integers.

Parameters
nthe dividend
dthe divisor
Returns
the quotient

Definition at line 174 of file arith.c.

References __udivdi3(), and udiv64().

Referenced by __udivdi3().

◆ __udivmoddi4()

unsigned long long __udivmoddi4 ( unsigned long long n,
unsigned long long d,
unsigned long long * rem )

Divides two unsigned 64-bit integers, giving both the quotient and the remainder.

Parameters
nthe dividend
dthe divisor
remif not NULL, set to the remainder
Returns
the quotient

Definition at line 200 of file arith.c.

References __udivmoddi4(), and udiv64().

Referenced by __udivmoddi4().

◆ __umoddi3()

unsigned long long __umoddi3 ( unsigned long long n,
unsigned long long d )

Computes the remainder of two unsigned 64-bit integers.

Parameters
nthe dividend
dthe divisor
Returns
the remainder

Definition at line 186 of file arith.c.

References __umoddi3(), and umod64().

Referenced by __umoddi3().

◆ divl()

uint32_t divl ( uint64_t n,
uint32_t d )
inlinestatic

Divides the 64-bit n by the 32-bit d with the x86 DIVL instruction, and returns the 32-bit quotient.

It traps with a divide error (#DE) if the quotient doesn't fit in 32 bits.

Definition at line 16 of file arith.c.

References divl().

Referenced by divl(), and udiv64().

◆ nlz()

int nlz ( uint32_t x)
static

Returns the number of leading zero bits in x, which must not be 0.

Definition at line 31 of file arith.c.

References nlz().

Referenced by nlz(), and udiv64().

◆ sdiv64()

int64_t sdiv64 ( int64_t n,
int64_t d )
static

Divides the signed 64-bit n by the signed 64-bit d, and returns the quotient.

Definition at line 120 of file arith.c.

References sdiv64(), and udiv64().

Referenced by __divdi3(), sdiv64(), and smod64().

◆ smod64()

int64_t smod64 ( int64_t n,
int64_t d )
static

Divides the signed 64-bit n by the signed 64-bit d, and returns the remainder.

Definition at line 130 of file arith.c.

References sdiv64(), and smod64().

Referenced by __moddi3(), and smod64().

◆ udiv64()

uint64_t udiv64 ( uint64_t n,
uint64_t d )
static

Divides the unsigned 64-bit n by the unsigned 64-bit d, and returns the quotient.

Definition at line 62 of file arith.c.

References divl(), nlz(), and udiv64().

Referenced by __udivdi3(), __udivmoddi4(), sdiv64(), udiv64(), and umod64().

◆ umod64()

uint64_t umod64 ( uint64_t n,
uint64_t d )
static

Divides the unsigned 64-bit n by the unsigned 64-bit d, and returns the remainder.

Definition at line 113 of file arith.c.

References udiv64(), and umod64().

Referenced by __umoddi3(), and umod64().