#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>
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;
* 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;
}
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");
#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"
* 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 */
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
#include <minix/config.h>
#include <minix/const.h>
#include <minix/partition.h>
-#include <minix/u64.h>
#include <machine/partition.h>
#include <termios.h>
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;
* 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;
}
#include <minix/config.h>
#include <minix/const.h>
#include <minix/partition.h>
-#include <minix/u64.h>
#else
#include "partition.h"
#define NR_PARTITIONS 4
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;
#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. */
#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.
*/
*/
/* 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. */
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;
}
#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 */
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? */
/* 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);
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); \
} \
} \
_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); \
} \
#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;
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 */
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)
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));
}
*/
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;
/* 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
/* 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;
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)
(*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;
}
/* 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)) {
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. */
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;
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,
read_tsc_64(&tsc);
- tsc = sub64(tsc, trace_tsc);
+ tsc -= trace_tsc;
return tsc_64_to_micros(tsc);
}
* 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;
}
/*===========================================================================*
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);
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);
}
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
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;
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
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
+++ /dev/null
-/* 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;
-}
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;
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);
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;
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;
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);
*/
/* 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));
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;
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);
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
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;
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;
{
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;
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);
}
/*
set_time(struct timespec *tsp)
{
- return mul64u(tsp->tv_sec, 1000000000) + tsp->tv_nsec;
+ return ((u64_t)tsp->tv_sec * 1000000000) + tsp->tv_nsec;
}
/*
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. */
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)
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;
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);
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. */
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)
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++) {
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;
}
#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
/* 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)
#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>
#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 */
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;
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;
{
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
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",
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);
(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);
}