Replaced common u64.h functions with operators.

Change-Id: I71b7b4879209eeff89ce5748d67102afebf871dc
This commit is contained in:
Gerard 2013-11-21 12:09:58 +01:00 committed by Lionel Sambuc
parent cd36dd7703
commit 78da142dab
37 changed files with 141 additions and 273 deletions

View file

@ -27,7 +27,6 @@
#include <minix/config.h>
#include <minix/const.h>
#include <minix/partition.h>
#include <minix/u64.h>
#include <minix/com.h>
#include <machine/partition.h>
#include <termios.h>
@ -525,8 +524,10 @@ void geometry(void)
if (ioctl(device, DIOCGETP, &geometry) < 0)
err= errno;
else {
table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
table[0].size= div64u(geometry.size, SECTOR_SIZE);
table[0].lowsec= (unsigned long)(geometry.base /
SECTOR_SIZE);
table[0].size = (unsigned long)(geometry.size /
SECTOR_SIZE);
cylinders= geometry.cylinders;
heads= geometry.heads;
sectors= geometry.sectors;
@ -578,8 +579,8 @@ exit(1);
* This makes sense for subpartitioning primary partitions.
*/
if (precise && ioctl(device, DIOCGETP, &geometry) >= 0) {
table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
table[0].size= div64u(geometry.size, SECTOR_SIZE);
table[0].lowsec= (unsigned long)(geometry.base / SECTOR_SIZE);
table[0].size = (unsigned long)(geometry.size / SECTOR_SIZE);
} else {
precise= 0;
}
@ -2149,8 +2150,8 @@ sanitycheck_failed(char *dev, struct part_entry *pe)
close(fd);
it_lowsec = div64u(part.base, SECTOR_SIZE);
it_secsize = div64u(part.size, SECTOR_SIZE);
it_lowsec = (unsigned long)(part.base / SECTOR_SIZE);
it_secsize = (unsigned long)(part.size / SECTOR_SIZE);
if(it_lowsec != pe->lowsec || it_secsize != pe->size) {
fprintf(stderr, "\nReturned and set numbers don't match up!\n");

View file

@ -46,7 +46,6 @@
#include <minix/config.h>
#include <minix/const.h>
#include <minix/type.h>
#include <minix/u64.h>
#include "mfs/const.h"
#include "mfs/inode.h"
#include "mfs/type.h"
@ -97,7 +96,7 @@ static struct super_block sb;
* btoa64 gives the byte address of a block
*/
#define ztob(z) ((block_nr) (z) << sb.s_log_zone_size)
#define btoa64(b) (mul64u(b, block_size))
#define btoa64(b) ((u64_t)(b) * block_size)
#define SCALE ((int) ztob(1)) /* # blocks in a zone */
#define FIRST ((zone_nr) sb.s_firstdatazone) /* as the name says */
@ -656,12 +655,12 @@ void chksuper()
int inoblock(int inn)
{
return div64u(mul64u(inn - 1, INODE_SIZE), block_size) + BLK_ILIST;
return (int)(((u64_t)(inn - 1) * INODE_SIZE) / block_size) + BLK_ILIST;
}
int inooff(int inn)
{
return rem64u(mul64u(inn - 1, INODE_SIZE), block_size);
return (int)(((u64_t)(inn - 1) * INODE_SIZE) % block_size);
}
/* Make a listing of the inodes given by `clist'. If `repair' is set, ask

View file

@ -22,7 +22,6 @@
#include <minix/config.h>
#include <minix/const.h>
#include <minix/partition.h>
#include <minix/u64.h>
#include <machine/partition.h>
#include <termios.h>
@ -477,8 +476,10 @@ void geometry(void)
if (ioctl(device, DIOCGETP, &geometry) < 0)
err= errno;
else {
table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
table[0].size= div64u(geometry.size, SECTOR_SIZE);
table[0].lowsec= (unsigned long)(geometry.base /
SECTOR_SIZE);
table[0].size= (unsigned long)(geometry.size /
SECTOR_SIZE);
cylinders= geometry.cylinders;
heads= geometry.heads;
sectors= geometry.sectors;
@ -546,8 +547,8 @@ void geometry(void)
* This makes sense for subpartitioning primary partitions.
*/
if (precise && ioctl(device, DIOCGETP, &geometry) >= 0) {
table[0].lowsec= div64u(geometry.base, SECTOR_SIZE);
table[0].size= div64u(geometry.size, SECTOR_SIZE);
table[0].lowsec= (unsigned long)(geometry.base / SECTOR_SIZE);
table[0].size = (unsigned long)(geometry.size / SECTOR_SIZE);
} else {
precise= 0;
}

View file

@ -20,7 +20,6 @@
#include <minix/config.h>
#include <minix/const.h>
#include <minix/partition.h>
#include <minix/u64.h>
#else
#include "partition.h"
#define NR_PARTITIONS 4
@ -322,8 +321,8 @@ void geometry(void)
geometry.cylinders= (sb.st_size-1)/SECTOR_SIZE/
(geometry.sectors*geometry.heads) + 1;
}
primary.lowsec= div64u(geometry.base, SECTOR_SIZE);
primary.size= div64u(geometry.size, SECTOR_SIZE);
primary.lowsec= (unsigned long)(geometry.base / SECTOR_SIZE);
primary.size = (unsigned long)(geometry.size / SECTOR_SIZE);
cylinders= geometry.cylinders;
heads= geometry.heads;
sectors= geometry.sectors;

View file

@ -11,7 +11,6 @@
#include <unistd.h>
#include <sys/wait.h>
#include <minix/minlib.h>
// #include <minix/u64.h>
#include <stdio.h>
/* -DNEW prints time to 0.01 sec. */

View file

@ -27,7 +27,6 @@
#include <sys/ioctl.h>
#include <sys/mtio.h>
#include <minix/partition.h>
#include <minix/u64.h>
/* Preferred block size to variable block length tapes, block devices or files.
*/

View file

@ -92,8 +92,8 @@ static int rule_match(struct fbd_rule *rule, u64_t pos, size_t size, int flag)
*/
/* Ranges must overlap (start < pos+size && end > pos). */
if (cmp64(rule->start, pos + size) >= 0 ||
(cmp64u(rule->end, 0) && cmp64(rule->end, pos) <= 0))
if (rule->start >= pos + size ||
(rule->end != 0 && rule->end <= pos))
return FALSE;
/* Flags must match. */

View file

@ -155,7 +155,7 @@ static ssize_t filter_transfer(devminor_t UNUSED(minor), int do_write,
for(size = 0, i = 0; i < count; i++)
size += iov[i].iov_size;
if (rem64u(pos, SECTOR_SIZE) != 0 || size % SECTOR_SIZE != 0) {
if (pos % SECTOR_SIZE != 0 || size % SECTOR_SIZE != 0) {
printf("Filter: unaligned request from caller!\n");
return EINVAL;
}

View file

@ -8,8 +8,8 @@
#define SEC2SUM_NR(nr) ((nr)/NR_SUM_SEC*(NR_SUM_SEC+1) + NR_SUM_SEC)
#define LOG2PHYS(nr) ((nr)/NR_SUM_SEC*(NR_SUM_SEC+1) + (nr)%NR_SUM_SEC)
#define POS2SEC(nr) div64u((nr), SECTOR_SIZE)
#define SEC2POS(nr) mul64u((nr), SECTOR_SIZE)
#define POS2SEC(nr) (unsigned long)((nr) / SECTOR_SIZE)
#define SEC2POS(nr) ((u64_t)(nr) * SECTOR_SIZE)
/* Data buffers. */
static char *ext_array, *ext_buffer; /* interspersed buffer */

View file

@ -406,8 +406,8 @@ static struct device *f_prepare(devminor_t device)
if (f_fp->fl_density < NT) {
f_dp = &fdensity[f_fp->fl_density];
f_sectors = f_dp->secpt;
f_fp->fl_geom.dv_size = mul64u((long) (NR_HEADS * f_sectors
* f_dp->cyls), SECTOR_SIZE);
f_fp->fl_geom.dv_size = (u64_t)(NR_HEADS * f_sectors * f_dp->cyls) *
SECTOR_SIZE;
}
/* A partition? */
@ -496,7 +496,7 @@ static ssize_t f_transfer(
/* Which block on disk and how close to EOF? */
if (position >= dv_size) return(total); /* At EOF */
if (position + nbytes > dv_size) nbytes = dv_size - position;
block = div64u(f_dv->dv_base + position, SECTOR_SIZE);
block = (unsigned long)((f_dv->dv_base + position) / SECTOR_SIZE);
if ((nbytes & SECTOR_MASK) != 0) return(EINVAL);

View file

@ -84,7 +84,7 @@ clock_t tmrs_settimer(minix_timer_t **tmrs, minix_timer_t *tp, clock_t exp_time,
read_tsc_64(&_starttime); \
do { timed_code_block } while(0); \
read_tsc_64(&_endtime); \
_dt = sub64(_endtime, _starttime); \
_dt = _endtime - _starttime; \
if(_cum_instances == 0) { \
RESET_STATS(_starttime, _cum_instances, _cum_spenttime, _cum_starttime); \
} \
@ -95,8 +95,8 @@ clock_t tmrs_settimer(minix_timer_t **tmrs, minix_timer_t *tp, clock_t exp_time,
} \
_cum_spenttime = add64(_cum_spenttime, _dt); \
_cum_instances++; \
_cum_dt = sub64(_endtime, _cum_starttime); \
if(cmp64(_cum_dt, make64(0, 120)) > 0) { \
_cum_dt = _endtime - _cum_starttime; \
if(_cum_dt > make64(0, 120)) { \
PRINT_STATS(_cum_spenttime, _cum_instances); \
RESET_STATS(_starttime, _cum_instances, _cum_spenttime, _cum_starttime); \
} \

View file

@ -7,81 +7,6 @@
#include <sys/types.h>
#include <limits.h>
static inline int bsr64(u64_t i)
{
int index;
u64_t mask;
for (index = 63, mask = 1ULL << 63; index >= 0; --index, mask >>= 1) {
if (i & mask)
return index;
}
return -1;
}
static inline int cmp64(u64_t i, u64_t j)
{
if (i > j)
return 1;
else if (i < j)
return -1;
else /* (i == j) */
return 0;
}
static inline int cmp64u(u64_t i, unsigned j)
{
if (i > j)
return 1;
else if (i < j)
return -1;
else /* (i == j) */
return 0;
}
static inline int cmp64ul(u64_t i, unsigned long j)
{
if (i > j)
return 1;
else if (i < j)
return -1;
else /* (i == j) */
return 0;
}
static inline unsigned diff64(u64_t i, u64_t j)
{
return (unsigned)(i - j);
}
static inline u64_t div64(u64_t i, u64_t j)
{
return i / j;
}
static inline u64_t rem64(u64_t i, u64_t j)
{
return i % j;
}
static inline unsigned long div64u(u64_t i, unsigned j)
{
return (unsigned long)(i / j);
}
static inline u64_t div64u64(u64_t i, unsigned j)
{
return i / j;
}
static inline unsigned rem64u(u64_t i, unsigned j)
{
return (unsigned)(i % j);
}
static inline unsigned long ex64lo(u64_t i)
{
return (unsigned long)i;
@ -97,35 +22,4 @@ static inline u64_t make64(unsigned long lo, unsigned long hi)
return ((u64_t)hi << 32) | (u64_t)lo;
}
static inline u64_t mul64(u64_t i, u64_t j)
{
return i * j;
}
static inline u64_t mul64u(unsigned long i, unsigned j)
{
return (u64_t)i * j;
}
static inline u64_t sub64(u64_t i, u64_t j)
{
return i - j;
}
static inline u64_t sub64u(u64_t i, unsigned j)
{
return i - j;
}
static inline u64_t sub64ul(u64_t i, unsigned long j)
{
return i - j;
}
u64_t rrotate64(u64_t x, unsigned short b);
u64_t rshift64(u64_t x, unsigned short b);
u64_t xor64(u64_t a, u64_t b);
u64_t and64(u64_t a, u64_t b);
u64_t not64(u64_t a);
#endif /* _MINIX__U64_H */

View file

@ -127,12 +127,12 @@ int register_local_timer_handler(const irq_handler_t handler)
u64_t ms_2_cpu_time(unsigned ms)
{
return mul64u(tsc_per_ms[cpuid], ms);
return (u64_t)(tsc_per_ms[cpuid]) * ms;
}
unsigned cpu_time_2_ms(u64_t cpu_time)
{
return div64u(cpu_time, tsc_per_ms[cpuid]);
return (unsigned long)(cpu_time / tsc_per_ms[cpuid]);
}
short cpu_load(void)

View file

@ -515,14 +515,14 @@ static void apic_calibrate_clocks(unsigned cpu)
rm_irq_handler(&spurious_irq);
lapic_delta = lapic_tctr0 - lapic_tctr1;
tsc_delta = sub64(tsc1, tsc0);
tsc_delta = tsc1 - tsc0;
lapic_bus_freq[cpuid] = system_hz * lapic_delta / (PROBE_TICKS - 1);
BOOT_VERBOSE(printf("APIC bus freq %u MHz\n",
lapic_bus_freq[cpuid] / 1000000));
cpu_freq = mul64(div64u64(tsc_delta, PROBE_TICKS - 1), make64(system_hz, 0));
cpu_freq = (tsc_delta / (PROBE_TICKS - 1)) * make64(system_hz, 0);
cpu_set_freq(cpuid, cpu_freq);
cpu_info[cpuid].freq = div64u(cpu_freq, 1000000);
cpu_info[cpuid].freq = (unsigned long)(cpu_freq / 1000000);
BOOT_VERBOSE(cpu_print_freq(cpuid));
}

View file

@ -33,7 +33,7 @@ static void intel_arch_watchdog_init(const unsigned cpu)
*/
cpuf = cpu_get_freq(cpu);
while (ex64hi(cpuf) || ex64lo(cpuf) > 0x7fffffffU)
cpuf = div64u64(cpuf, 2);
cpuf /= 2;
cpuf = make64(-ex64lo(cpuf), ex64hi(cpuf));
watchdog->resetval = watchdog->watchdog_resetval = cpuf;
@ -159,7 +159,7 @@ static int intel_arch_watchdog_profile_init(const unsigned freq)
/* FIXME works only if all CPUs have the same freq */
cpuf = cpu_get_freq(cpuid);
cpuf = div64u64(cpuf, freq);
cpuf /= freq;
/*
* if freq is too low and the cpu freq too high we may get in a range of
@ -223,7 +223,7 @@ static int amd_watchdog_profile_init(const unsigned freq)
/* FIXME works only if all CPUs have the same freq */
cpuf = cpu_get_freq(cpuid);
cpuf = -div64u64(cpuf, freq);
cpuf = -cpuf / freq;
watchdog->profile_resetval = cpuf;

View file

@ -500,7 +500,7 @@ void cpu_print_freq(unsigned cpu)
u64_t freq;
freq = cpu_get_freq(cpu);
printf("CPU %d freq %lu MHz\n", cpu, div64u(freq, 1000000));
printf("CPU %d freq %lu MHz\n", cpu, (unsigned long)(freq / 1000000));
}
int is_fpu(void)

View file

@ -293,7 +293,8 @@ static int do_dioctl(struct blockdriver *bdp, dev_t minor,
(*bdp->bdr_geometry)(minor, &entry);
} else {
/* The driver doesn't care -- make up fake geometry. */
entry.cylinders = div64u(entry.size, SECTOR_SIZE) / (64 * 32);
entry.cylinders = (unsigned long)(entry.size / SECTOR_SIZE) /
(64 * 32);
entry.heads = 64;
entry.sectors = 32;
}

View file

@ -72,9 +72,9 @@ u8_t *tmp_buf; /* temporary buffer */
/* Get the geometry of the device to partition */
if ((dv = (*bdp->bdr_part)(device)) == NULL
|| cmp64u(dv->dv_size, 0) == 0) return;
base = div64u(dv->dv_base, SECTOR_SIZE);
limit = base + div64u(dv->dv_size, SECTOR_SIZE);
|| dv->dv_size == 0) return;
base = (unsigned long)(dv->dv_base / SECTOR_SIZE);
limit = base + (unsigned long)(dv->dv_size / SECTOR_SIZE);
/* Read the partition table for the device. */
if(!get_part_table(bdp, device, 0L, table, tmp_buf)) {
@ -109,8 +109,8 @@ u8_t *tmp_buf; /* temporary buffer */
if (pe->lowsec < base) pe->lowsec = base;
if (part_limit < pe->lowsec) part_limit = pe->lowsec;
dv->dv_base = mul64u(pe->lowsec, SECTOR_SIZE);
dv->dv_size = mul64u(part_limit - pe->lowsec, SECTOR_SIZE);
dv->dv_base = (u64_t)pe->lowsec * SECTOR_SIZE;
dv->dv_size = (u64_t)(part_limit - pe->lowsec) * SECTOR_SIZE;
if (style == P_PRIMARY) {
/* Each Minix primary partition can be subpartitioned. */
@ -163,9 +163,9 @@ u8_t *tmp_buf; /* temporary buffer */
if (pe->sysind != NO_PART) {
if ((dv = (*bdp->bdr_part)(subdev)) == NULL) return;
dv->dv_base = mul64u(extbase + offset + pe->lowsec,
SECTOR_SIZE);
dv->dv_size = mul64u(pe->size, SECTOR_SIZE);
dv->dv_base = (u64_t)(extbase + offset + pe->lowsec) *
SECTOR_SIZE;
dv->dv_size = (u64_t)pe->size * SECTOR_SIZE;
/* Out of devices? */
if (++subdev % NR_PARTITIONS == 0) return;
@ -191,7 +191,7 @@ u8_t *tmp_buf; /* temporary buffer */
u64_t position;
int r;
position = mul64u(offset, SECTOR_SIZE);
position = (u64_t)offset * SECTOR_SIZE;
iovec1.iov_addr = (vir_bytes) tmp_buf;
iovec1.iov_size = CD_SECTOR_SIZE;
r = (*bdp->bdr_transfer)(device, FALSE /*do_write*/, position, SELF,

View file

@ -40,7 +40,7 @@ static u32_t trace_gettime(void)
read_tsc_64(&tsc);
tsc = sub64(tsc, trace_tsc);
tsc -= trace_tsc;
return tsc_64_to_micros(tsc);
}

View file

@ -18,7 +18,7 @@ void time_init(void)
* the difference between that time and the UNIX epoch, in 100ns units.
*/
/* FIXME: we currently do not take into account timezones. */
time_offset = mul64u(116444736, 1000000000);
time_offset = (u64_t)116444736 * 1000000000;
}
/*===========================================================================*
@ -33,7 +33,7 @@ void time_put(struct timespec *tsp)
u64_t hgfstime;
if (tsp != NULL) {
hgfstime = mul64u(tsp->tv_sec, 10000000) + (tsp->tv_nsec / 100);
hgfstime = ((u64_t)tsp->tv_sec * 10000000) + (tsp->tv_nsec / 100);
hgfstime += time_offset;
RPC_NEXT32 = ex64lo(hgfstime);
@ -60,10 +60,10 @@ void time_get(struct timespec *tsp)
time_lo = RPC_NEXT32;
time_hi = RPC_NEXT32;
hgfstime = sub64(make64(time_lo, time_hi), time_offset);
hgfstime = make64(time_lo, time_hi) - time_offset;
tsp->tv_sec = div64u(hgfstime, 10000000);
tsp->tv_nsec = rem64u(hgfstime, 10000000) * 100;
tsp->tv_sec = (unsigned long)(hgfstime / 10000000);
tsp->tv_nsec = (unsigned)(hgfstime % 10000000) * 100;
}
else RPC_ADVANCE(sizeof(u32_t) * 2);
}

View file

@ -76,8 +76,8 @@ static u32_t fs_bufs_heuristic(int minbufs, u32_t btotal, u64_t bfree,
vsi.vsi_pagesize / 1024;
/* check fs usage. */
kbytes_used_fs = div64u(mul64u(bused, blocksize), 1024);
kbytes_total_fs = div64u(mul64u(btotal, blocksize), 1024);
kbytes_used_fs = (unsigned long)(((u64_t)bused * blocksize) / 1024);
kbytes_total_fs = (unsigned long)(((u64_t)btotal * blocksize) / 1024);
/* heuristic for a desired cache size based on FS usage;
* but never bigger than half of the total filesystem
@ -518,7 +518,7 @@ register struct buf *bp; /* buffer pointer */
ASSERT(bp->lmfs_bytes == fs_block_size);
ASSERT(fs_block_size > 0);
pos = mul64u(bp->lmfs_blocknr, fs_block_size);
pos = (u64_t)bp->lmfs_blocknr * fs_block_size;
if(fs_block_size > PAGE_SIZE) {
#define MAXPAGES 20
vir_bytes blockrem, vaddr = (vir_bytes) bp->data;
@ -704,7 +704,7 @@ void lmfs_rw_scattered(
assert(nblocks > 0);
assert(niovecs > 0);
pos = mul64u(bufq[0]->lmfs_blocknr, fs_block_size);
pos = (u64_t)bufq[0]->lmfs_blocknr * fs_block_size;
if (rw_flag == READING)
r = bdev_gather(dev, pos, iovec, niovecs, BDEV_NOFLAGS);
else

View file

@ -19,7 +19,7 @@ SRCS+= dhcp_gettag.c dhcp_settag.c
SRCS+= gcov.c gcov_flush.c
# Various utils
SRCS+= itoa.c u64util.c read_tsc_64.c
SRCS+= itoa.c read_tsc_64.c
# servxcheck
SRCS+= servxcheck.c

View file

@ -1,34 +0,0 @@
/* Few u64 utils implemented in C
* Author: Gautam BT
*/
#include <minix/u64.h>
u64_t rrotate64(u64_t x, unsigned short b)
{
b %= 64;
if ((b &= 63) == 0)
return x;
return (x >> b) | (x << (64 - b));
}
u64_t rshift64(u64_t x, unsigned short b)
{
if (b >= 64)
return 0;
return x >> b;
}
u64_t xor64(u64_t a, u64_t b)
{
return a ^ b;
}
u64_t and64(u64_t a, u64_t b)
{
return a & b;
}
u64_t not64(u64_t a)
{
return ~a;
}

View file

@ -47,8 +47,8 @@ int do_statvfs()
statvfs.f_bsize = BLOCK_SIZE;
statvfs.f_frsize = BLOCK_SIZE;
statvfs.f_iosize = BLOCK_SIZE;
statvfs.f_blocks = div64u(total, BLOCK_SIZE);
statvfs.f_bfree = div64u(free, BLOCK_SIZE);
statvfs.f_blocks = (unsigned long)(total / BLOCK_SIZE);
statvfs.f_bfree = (unsigned long)(free / BLOCK_SIZE);
statvfs.f_bavail = statvfs.f_bfree;
statvfs.f_namemax = NAME_MAX;

View file

@ -70,7 +70,7 @@ int do_stat()
stat.st_uid = sffs_params->p_uid;
stat.st_gid = sffs_params->p_gid;
stat.st_rdev = NO_DEV;
if (cmp64u(attr.a_size, LONG_MAX) > 0)
if (attr.a_size > LONG_MAX)
stat.st_size = LONG_MAX;
else
stat.st_size = ex64lo(attr.a_size);

View file

@ -138,7 +138,7 @@ int do_ftrunc()
start = make64(m_in.REQ_TRC_START_LO, m_in.REQ_TRC_START_HI);
end = make64(m_in.REQ_TRC_END_LO, m_in.REQ_TRC_END_HI);
if (cmp64u(end, 0) == 0) {
if (end == 0) {
/* Truncate or expand the file. */
if ((r = verify_inode(ino, path, NULL)) != OK)
return r;
@ -149,9 +149,9 @@ int do_ftrunc()
r = sffs_table->t_setattr(path, &attr);
} else {
/* Write zeroes to the file. We can't create holes. */
if (cmp64(end, start) <= 0) return EINVAL;
if (end <= start) return EINVAL;
delta = sub64(end, start);
delta = end - start;
if (ex64hi(delta) != 0) return EINVAL;

View file

@ -67,10 +67,10 @@ double getidle(void)
if ((r = sys_getidletsc(&idle2)) != OK)
return -1.0;
idelta = sub64(idle2, idle);
tdelta = sub64(stop, start);
idelta = idle2 - idle;
tdelta = stop - start;
if (cmp64(idelta, tdelta) >= 0)
if (idelta >= tdelta)
return 100.0;
ifp = make_double(idelta);

View file

@ -191,9 +191,9 @@ void procexit (char *UNUSED(name))
*/
/* Calculate "small" difference. */
spent = sub64(stop, cprof_stk[cprof_stk_top].start_2);
spent = stop - cprof_stk[cprof_stk_top].start_2;
cprof_stk[cprof_stk_top].slot->cycles +=
sub64(spent, cprof_stk[cprof_stk_top].spent_deeper);
spent - cprof_stk[cprof_stk_top].spent_deeper;
/* Clear spent_deeper for call level we're leaving. */
cprof_stk[cprof_stk_top].spent_deeper = ((u64_t)(0));
@ -216,7 +216,7 @@ void procexit (char *UNUSED(name))
stop = make64(tsc_lo, tsc_hi);
/* Calculate "big" difference. */
spent = sub64(stop, cprof_stk[cprof_stk_top].start_1);
spent = stop - cprof_stk[cprof_stk_top].start_1;
cprof_stk_top--; /* decrease stack */
if (cprof_stk_top >= 0) /* don't update non-existent level -1 */
cprof_stk[cprof_stk_top].spent_deeper += spent;

View file

@ -61,7 +61,7 @@ int spin_check(spin_t *s)
case STATE_TS:
read_tsc_64(&cur_tsc);
tsc_delta = sub64(cur_tsc, s->s_base_tsc);
tsc_delta = cur_tsc - s->s_base_tsc;
micro_delta = tsc_64_to_micros(tsc_delta);

View file

@ -63,7 +63,7 @@ micro_delay(u32_t micros)
CALIBRATE;
/* We have to know when to end the delay. */
end = now + mul64u(micros, calib_mhz);
end = now + ((u64_t)micros * calib_mhz);
/* If we have to wait for at least one HZ tick, use the regular
* tickdelay first. Round downwards on purpose, so the average
@ -75,7 +75,7 @@ micro_delay(u32_t micros)
tickdelay(micros*Hz/MICROHZ);
/* Wait (the rest) of the delay time using busywait. */
while(cmp64(now, end) < 0)
while(now < end)
read_tsc_64(&now);
return OK;
@ -87,7 +87,7 @@ u32_t tsc_64_to_micros(u64_t tsc)
CALIBRATE;
tmp = div64u64(tsc, calib_mhz);
tmp = tsc / calib_mhz;
if (ex64hi(tmp)) {
printf("tsc_64_to_micros: more than 2^32ms\n");
return ~0UL;

View file

@ -31,7 +31,7 @@ micros_to_ticks(u32_t micros)
{
u32_t ticks;
ticks = div64u(mul64u(micros, sys_hz()), 1000000);
ticks = (u32_t)(((u64_t)micros * sys_hz()) / 1000000);
if(ticks < 1) ticks = 1;
return ticks;

View file

@ -10,8 +10,8 @@ static void
get_time(struct timespec *tsp, u64_t nsecs)
{
tsp->tv_sec = div64u(nsecs, 1000000000);
tsp->tv_nsec = rem64u(nsecs, 1000000000);
tsp->tv_sec = (unsigned long)(nsecs / 1000000000);
tsp->tv_nsec = (unsigned)(nsecs % 1000000000);
}
/*
@ -21,7 +21,7 @@ static u64_t
set_time(struct timespec *tsp)
{
return mul64u(tsp->tv_sec, 1000000000) + tsp->tv_nsec;
return ((u64_t)tsp->tv_sec * 1000000000) + tsp->tv_nsec;
}
/*

View file

@ -175,7 +175,7 @@ int fs_breadwrite(void)
cum_io = 0;
/* Split the transfer into chunks that don't span two blocks. */
while (nrbytes > 0) {
off = rem64u(position, block_size); /* offset in blk*/
off = (unsigned int)(position % block_size); /* offset in blk*/
chunk = min(nrbytes, block_size - off);
/* Read or write 'chunk' bytes. */
@ -240,7 +240,7 @@ int *completed; /* number of bytes copied */
block_spec = (rip->i_mode & I_TYPE) == I_BLOCK_SPECIAL;
if (block_spec) {
b = div64u(position, block_size);
b = (unsigned long)(position / block_size);
dev = (dev_t) rip->i_block[0];
} else {
if (ex64hi(position) != 0)

View file

@ -107,7 +107,7 @@ int fs_bread(void)
cum_io = 0;
/* Split the transfer into chunks that don't span two blocks. */
while (nrbytes != 0) {
off = rem64u(position, block_size); /* offset in blk*/
off = (unsigned int)(position % block_size); /* offset in blk*/
chunk = MIN(nrbytes, block_size - off);
if (chunk < 0) chunk = block_size - off;
@ -312,20 +312,20 @@ int rw; /* READING or PEEKING */
if ((ex64lo(position) <= dir->d_file_size) &&
(ex64lo(position) > dir->data_length_l)) {
while ((dir->d_next != NULL) && (ex64lo(position) > dir->data_length_l)) {
position = sub64ul(position, dir->data_length_l);
position -= dir->data_length_l;
dir = dir->d_next;
}
}
if (dir->inter_gap_size != 0) {
rel_block = div64u(position, block_size);
rel_block = (unsigned long)(position / block_size);
file_unit = rel_block / dir->data_length_l;
offset = rel_block % dir->file_unit_size;
b = dir->loc_extent_l + (dir->file_unit_size +
dir->inter_gap_size) * file_unit + offset;
} else {
b = dir->loc_extent_l + div64u(position, block_size); /* Physical position
* to read. */
b = dir->loc_extent_l + (unsigned long)(position / block_size);
/* Physical position to read. */
}
bp = get_block(b);

View file

@ -184,7 +184,7 @@ int fs_breadwrite(void)
cum_io = 0;
/* Split the transfer into chunks that don't span two blocks. */
while (nrbytes > 0) {
off = rem64u(position, block_size); /* offset in blk*/
off = (unsigned int)(position % block_size); /* offset in blk*/
chunk = min(nrbytes, block_size - off);
/* Read or write 'chunk' bytes. */
@ -249,7 +249,7 @@ int *completed; /* number of bytes copied */
block_spec = (rip->i_mode & I_TYPE) == I_BLOCK_SPECIAL;
if (block_spec) {
b = div64u(position, block_size);
b = (unsigned long)(position / block_size);
dev = (dev_t) rip->i_zone[0];
} else {
if (ex64hi(position) != 0)

View file

@ -110,54 +110,68 @@ static void handler_SIGFPE(int signum)
exit(-1);
}
static inline int bsr64(u64_t i)
{
int index;
u64_t mask;
for (index = 63, mask = 1ULL << 63; index >= 0; --index, mask >>= 1) {
if (i & mask)
return index;
}
return -1;
}
static void testmul(void)
{
int kdone, kidx;
u32_t ilo = ex64lo(i), jlo = ex64lo(j);
u64_t prod = mul64(i, j);
u64_t prod = i * j;
int prodbits;
/* compute maximum index of highest-order bit */
prodbits = bsr64(i) + bsr64(j) + 1;
if (cmp64u(i, 0) == 0 || cmp64u(j, 0) == 0) prodbits = -1;
if (i == 0 || j == 0) prodbits = -1;
if (bsr64(prod) > prodbits) ERR;
/* compare to 32-bit multiplication if possible */
if (ex64hi(i) == 0 && ex64hi(j) == 0) {
if (cmp64(prod, mul64u(ilo, jlo)) != 0) ERR;
if (prod != (u64_t)ilo * jlo) ERR;
/* if there is no overflow we can check against pure 32-bit */
if (prodbits < 32 && cmp64u(prod, ilo * jlo) != 0) ERR;
if (prodbits < 32 && prod != ilo * jlo) ERR;
}
/* in 32-bit arith low-order DWORD matches regardless of overflow */
if (ex64lo(prod) != ilo * jlo) ERR;
/* multiplication by zero yields zero */
if (prodbits < 0 && cmp64u(prod, 0) != 0) ERR;
if (prodbits < 0 && prod != 0) ERR;
/* if there is no overflow, check absence of zero divisors */
if (prodbits >= 0 && prodbits < 64 && cmp64u(prod, 0) == 0) ERR;
if (prodbits >= 0 && prodbits < 64 && prod == 0) ERR;
/* commutativity */
if (cmp64(prod, mul64(j, i)) != 0) ERR;
if (prod != j * i) ERR;
/* loop though all argument value combinations for third argument */
for (kdone = 0, kidx = 0; k = getargval(kidx, &kdone), !kdone; kidx++) {
/* associativity */
if (cmp64(mul64(mul64(i, j), k), mul64(i, mul64(j, k))) != 0) ERR;
if ((i * j) * k != i * (j * k)) ERR;
/* left and right distributivity */
if (cmp64(mul64(i + j, k), mul64(i, k) + mul64(j, k)) != 0) ERR;
if (cmp64(mul64(i, j + k), mul64(i, j) + mul64(i, k)) != 0) ERR;
if ((i + j) * k != (i * k) + (j * k)) ERR;
if (i * (j + k) != (i * j) + (i * k)) ERR;
}
}
static void testdiv0(void)
{
int funcidx;
u64_t res;
assert(cmp64u(j, 0) == 0);
assert(j == 0);
/* loop through the 5 different division functions */
for (funcidx = 0; funcidx < 5; funcidx++) {
@ -165,11 +179,11 @@ static void testdiv0(void)
if (setjmp(jmpbuf_SIGFPE) == 0) {
/* divide by zero using various functions */
switch (funcidx) {
case 0: div64(i, j); ERR; break;
case 1: div64u64(i, ex64lo(j)); ERR; break;
case 2: div64u(i, ex64lo(j)); ERR; break;
case 3: rem64(i, j); ERR; break;
case 4: rem64u(i, ex64lo(j)); ERR; break;
case 0: res = i / j; ERR; break;
case 1: res = i / ex64lo(j); ERR; break;
case 2: res = i / ex64lo(j); ERR; break;
case 3: res = i % j; ERR; break;
case 4: res = i % ex64lo(j); ERR; break;
default: assert(0); ERR; break;
}
@ -200,14 +214,14 @@ static void testdiv(void)
#endif
/* division by zero has a separate test */
if (cmp64u(j, 0) == 0) {
if (j == 0) {
testdiv0();
return;
}
/* perform division, store q in k to make ERR more informative */
q = div64(i, j);
r = rem64(i, j);
q = i / j;
r = i % j;
k = q;
#if TIMED
@ -227,22 +241,22 @@ static void testdiv(void)
/* compare to 64/32-bit division if possible */
if (!ex64hi(j)) {
if (cmp64(q, div64u64(i, ex64lo(j))) != 0) ERR;
if (q != i / ex64lo(j)) ERR;
if (!ex64hi(q)) {
if (cmp64u(q, div64u(i, ex64lo(j))) != 0) ERR;
if (q != i / ex64lo(j)) ERR;
}
if (cmp64u(r, rem64u(i, ex64lo(j))) != 0) ERR;
if (r != i % ex64lo(j)) ERR;
/* compare to 32-bit division if possible */
if (!ex64hi(i)) {
if (cmp64u(q, ex64lo(i) / ex64lo(j)) != 0) ERR;
if (cmp64u(r, ex64lo(i) % ex64lo(j)) != 0) ERR;
if (q != ex64lo(i) / ex64lo(j)) ERR;
if (r != ex64lo(i) % ex64lo(j)) ERR;
}
}
/* check results using i = q j + r and r < j */
if (cmp64(i, mul64(q, j) + r) != 0) ERR;
if (cmp64(r, j) >= 0) ERR;
if (i != (q * j) + r) ERR;
if (r >= j) ERR;
}
static void test(void)

View file

@ -13,7 +13,6 @@
#if defined(__minix)
#include <minix/minlib.h>
#include <minix/partition.h>
#include <minix/u64.h>
#include <sys/ioctl.h>
#elif defined(__linux__)
#include <mntent.h>
@ -50,10 +49,6 @@
#define BIN 2
#define BINGRP 2
#if !defined(__minix)
#define mul64u(a,b) ((uint64_t)(a) * (b))
#endif
/* some Minix specific types that do not conflict with Posix */
#ifndef block_t
typedef uint32_t block_t; /* block number */
@ -389,13 +384,13 @@ main(int argc, char *argv[])
testb = alloc_block();
/* Try writing the last block of partition or diskette. */
mkfs_seek(mul64u(blocks - 1, block_size), SEEK_SET);
mkfs_seek((uint64_t)(blocks - 1) * block_size, SEEK_SET);
testb[0] = 0x3245;
testb[1] = 0x11FF;
testb[block_size/2-1] = 0x1F2F;
w=mkfs_write(testb, block_size);
sync(); /* flush write, so if error next read fails */
mkfs_seek(mul64u(blocks - 1, block_size), SEEK_SET);
mkfs_seek((uint64_t)(blocks - 1) * block_size, SEEK_SET);
testb[0] = 0;
testb[1] = 0;
testb[block_size/2-1] = 0;
@ -407,7 +402,7 @@ main(int argc, char *argv[])
testb[0], testb[1], testb[block_size-1]);
errx(1, "File system is too big for minor device (read)");
}
mkfs_seek(mul64u(blocks - 1, block_size), SEEK_SET);
mkfs_seek((uint64_t)(blocks - 1) * block_size, SEEK_SET);
testb[0] = 0;
testb[1] = 0;
testb[block_size/2-1] = 0;
@ -543,8 +538,8 @@ sizeup(char * device)
{
block_t d;
#if defined(__minix)
u64_t bytes, resize;
u32_t rem;
uint64_t bytes, resize;
uint32_t rem;
#else
off_t size;
#endif
@ -562,11 +557,11 @@ sizeup(char * device)
return 0;
}
d = div64u(bytes, block_size);
rem = rem64u(bytes, block_size);
d = (uint32_t)(bytes / block_size);
rem = (uint32_t)(bytes % block_size);
resize = mul64u(d, block_size) + rem;
if(cmp64(resize, bytes) != 0) {
resize = ((uint64_t)d * block_size) + rem;
if(resize != bytes) {
/* Assume block_t is unsigned */
d = (block_t)(-1ul);
fprintf(stderr, "%s: truncating FS at %lu blocks\n",
@ -1579,7 +1574,7 @@ get_block(block_t n, void *buf)
memcpy(buf, zero, block_size);
return;
}
mkfs_seek(mul64u(n, block_size), SEEK_SET);
mkfs_seek((uint64_t)(n) * block_size, SEEK_SET);
k = read(fd, buf, block_size);
if (k != block_size)
pexit("get_block couldn't read block #%u", (unsigned)n);
@ -1604,7 +1599,7 @@ put_block(block_t n, void *buf)
(void) read_and_set(n);
mkfs_seek(mul64u(n, block_size), SEEK_SET);
mkfs_seek((uint64_t)(n) * block_size, SEEK_SET);
mkfs_write(buf, block_size);
}