소스 검색

turns out the imult routines (which I never used) were incorrect.

Noted by Matthew Dempsky
  open_* from open.h now open in large file mode
master
Felix von Leitner 16 년 전
부모
커밋
237ff729b3
  1. 3
      CHANGES
  2. 9
      mult/imult16.c
  3. 9
      mult/imult32.c
  4. 3
      mult/imult64.c
  5. 1
      open/open_append.c
  6. 1
      open/open_excl.c
  7. 1
      open/open_read.c
  8. 1
      open/open_rw.c
  9. 1
      open/open_trunc.c
  10. 1
      open/open_write.c
  11. 18
      t.c
  12. 26
      test/mult.c

3
CHANGES

@ -4,6 +4,9 @@
if _XOPEN_SOURCE is defined, which is needed for Solaris.
OpenBSD sucks. I checked in a _really_ kludge now. Please do not
use OpenBSD if you have a choice. Or Solaris, for that matter.
turns out the imult routines (which I never used) were incorrect.
Noted by Matthew Dempsky
open_* from open.h now open in large file mode
0.23:
also recognize EPFNOSUPPORT as EAFNOSUPPORT (groan)

9
mult/imult16.c

@ -1,11 +1,8 @@
#include "safemult.h"
int imult16(int16 a,int16 b,int16* c) {
int neg=(a<0);
uint16 d;
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult16(a,b,&d)) return 0;
*c=(neg?-d:d);
int32 x=(int32)a*b;
if ((int16)x != x) return 0;
*c=x;
return 1;
}

9
mult/imult32.c

@ -1,11 +1,8 @@
#include "safemult.h"
int imult32(int32 a,int32 b,int32* c) {
int neg=(a<0);
uint32 d;
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult32(a,b,&d)) return 0;
*c=(neg?-d:d);
int64 x=(int64)a*b;
if ((int32)x != x) return 0;
*c=x;
return 1;
}

3
mult/imult64.c

@ -5,7 +5,8 @@ int imult64(int64 a,int64 b,int64* c) {
uint64 d;
if (neg) a=-a;
if (b<0) { neg^=1; b=-b; }
if (umult64(a,b,&d)) return 0;
if (!umult64(a,b,&d)) return 0;
if (d > 0x7fffffffffffffffULL + neg) return 0;
*c=(neg?-d:d);
return 1;
}

1
open/open_append.c

@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"

1
open/open_excl.c

@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"

1
open/open_read.c

@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"

1
open/open_rw.c

@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"

1
open/open_trunc.c

@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"

1
open/open_write.c

@ -1,3 +1,4 @@
#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <fcntl.h>
#include "open.h"

18
t.c

@ -21,6 +21,7 @@
#include <assert.h>
#include "errmsg.h"
#include "iob.h"
#include "safemult.h"
#define rdtscl(low) \
__asm__ __volatile__ ("rdtsc" : "=a" (low) : : "edx")
@ -328,8 +329,25 @@ int main(int argc,char* argv[]) {
write(1,tmp,x);
}
#endif
#if 0
printf("%d %d\n",strcmp("foo","bar"),str_diff("foo","bar"));
printf("%d %d\n",strcmp("foo","üar"),str_diff("foo","üar"));
return 0;
#endif
{
int16 a;
int32 b;
int64 c;
assert(imult16(4,10000,&a)==0);
assert(imult16(-4,10000,&a)==0);
assert(imult16(5,10,&a)==1 && a==50);
assert(imult16(-3,10000,&a)==1 && a==-30000);
assert(imult32(0x40000000,2,&b)==0);
assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe);
assert(imult64(0x4000000000000000ll,2,&c)==0);
assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell);
}
}

26
test/mult.c

@ -0,0 +1,26 @@
#include <assert.h>
#include "safemult.h"
int main() {
int16 a;
int32 b;
int64 c;
uint16 d;
uint32 e;
uint64 f;
assert(imult16(4,10000,&a)==0);
assert(imult16(-4,10000,&a)==0);
assert(imult16(5,10,&a)==1 && a==50);
assert(imult16(-3,10000,&a)==1 && a==-30000);
assert(imult32(0x40000000,2,&b)==0);
assert(imult32(-0x40000000,2,&b)==1 && b==-0x80000000);
assert(imult32(0x3fffffff,2,&b)==1 && b==0x7ffffffe);
assert(imult64(0x4000000000000000ll,2,&c)==0);
assert(imult64(-0x4000000000000000ll,2,&c)==1 && c==-0x8000000000000000ll);
assert(imult64(0x3fffffffffffffffll,2,&c)==1 && c==0x7ffffffffffffffell);
return 0;
}
불러오는 중...
취소
저장