libc: change usize to 64-bit for amd64 and arm64, make memory(2) functions use usize

This commit is contained in:
cinap_lenrek 2021-07-25 15:54:22 +00:00
parent 8a8329ad95
commit e4b5f170cf
19 changed files with 57 additions and 59 deletions

View file

@ -8,7 +8,7 @@ typedef long long vlong;
typedef unsigned long long uvlong; typedef unsigned long long uvlong;
typedef long long intptr; typedef long long intptr;
typedef unsigned long long uintptr; typedef unsigned long long uintptr;
typedef unsigned long usize; typedef unsigned long long usize;
typedef uint Rune; typedef uint Rune;
typedef union FPdbleword FPdbleword; typedef union FPdbleword FPdbleword;
typedef uintptr jmp_buf[2]; typedef uintptr jmp_buf[2];

View file

@ -9,7 +9,7 @@ typedef long long vlong;
typedef unsigned long long uvlong; typedef unsigned long long uvlong;
typedef vlong intptr; typedef vlong intptr;
typedef uvlong uintptr; typedef uvlong uintptr;
typedef unsigned long usize; typedef unsigned long long usize;
typedef uint Rune; typedef uint Rune;
typedef union FPdbleword FPdbleword; typedef union FPdbleword FPdbleword;
typedef uintptr jmp_buf[2]; typedef uintptr jmp_buf[2];

View file

@ -8,12 +8,12 @@
/* /*
* mem routines * mem routines
*/ */
extern void* memccpy(void*, void*, int, ulong); extern void* memccpy(void*, void*, int, usize);
extern void* memset(void*, int, ulong); extern void* memset(void*, int, usize);
extern int memcmp(void*, void*, ulong); extern int memcmp(void*, void*, usize);
extern void* memcpy(void*, void*, ulong); extern void* memcpy(void*, void*, usize);
extern void* memmove(void*, void*, ulong); extern void* memmove(void*, void*, usize);
extern void* memchr(void*, int, ulong); extern void* memchr(void*, int, usize);
/* /*
* string routines * string routines

View file

@ -8,22 +8,22 @@ memccpy, memchr, memcmp, memcpy, memmove, memset, tsmemcmp \- memory operations
.PP .PP
.ta \w'\fLvoid* 'u .ta \w'\fLvoid* 'u
.B .B
void* memccpy(void *s1, void *s2, int c, ulong n) void* memccpy(void *s1, void *s2, int c, usize n)
.PP .PP
.B .B
void* memchr(void *s, int c, ulong n) void* memchr(void *s, int c, usize n)
.PP .PP
.B .B
int memcmp(void *s1, void *s2, ulong n) int memcmp(void *s1, void *s2, usize n)
.PP .PP
.B .B
void* memcpy(void *s1, void *s2, ulong n) void* memcpy(void *s1, void *s2, usize n)
.PP .PP
.B .B
void* memmove(void *s1, void *s2, ulong n) void* memmove(void *s1, void *s2, usize n)
.PP .PP
.B .B
void* memset(void *s, int c, ulong n) void* memset(void *s, int c, usize n)
.PP .PP
.B #include <libsec.h> .B #include <libsec.h>
.PP .PP

View file

@ -8,11 +8,11 @@
/* /*
* mem routines * mem routines
*/ */
extern void* memccpy(void*, void*, int, ulong); extern void* memccpy(void*, void*, int, usize);
extern void* memset(void*, int, ulong); extern void* memset(void*, int, usize);
extern int memcmp(void*, void*, ulong); extern int memcmp(void*, void*, usize);
extern void* memmove(void*, void*, ulong); extern void* memmove(void*, void*, usize);
extern void* memchr(void*, int, ulong); extern void* memchr(void*, int, usize);
/* /*
* string routines * string routines

View file

@ -349,13 +349,13 @@ Have:
} }
void* void*
evommem(void *a, void *b, ulong n) evommem(void *a, void *b, usize n)
{ {
return memmove(b, a, n); return memmove(b, a, n);
} }
int int
isnonzero(void *v, ulong n) isnonzero(void *v, usize n)
{ {
uchar *a, *ea; uchar *a, *ea;
@ -375,7 +375,7 @@ rdwrpart(Req *r)
vlong offset; vlong offset;
long count, tot, n, o; long count, tot, n, o;
uchar *blk, *dat; uchar *blk, *dat;
void *(*move)(void*, void*, ulong); void *(*move)(void*, void*, usize);
q = r->fid->qid.path-Qpart; q = r->fid->qid.path-Qpart;
if(q < 0 || q > nelem(tab) || !tab[q].inuse || tab[q].vers != r->fid->qid.vers){ if(q < 0 || q > nelem(tab) || !tab[q].inuse || tab[q].vers != r->fid->qid.vers){

View file

@ -1,7 +1,7 @@
TEXT memccpy(SB),$0 TEXT memccpy(SB),$0
MOVL n+24(FP), CX MOVQ n+24(FP), CX
CMPL CX, $0 CMPQ CX, $0
JEQ none JEQ none
MOVQ p2+8(FP), DI MOVQ p2+8(FP), DI
MOVBLZX c+16(FP), AX MOVBLZX c+16(FP), AX
@ -18,7 +18,7 @@
*/ */
none: none:
MOVL $0, AX MOVL $0, AX
MOVL n+24(FP), BX MOVQ n+24(FP), BX
JMP memcpy JMP memcpy
/* /*
@ -44,7 +44,7 @@ memcpy:
ORQ SI, DX ORQ SI, DX
ANDL $3, DX ANDL $3, DX
JNE c3 JNE c3
MOVL BX, CX MOVQ BX, CX
SHRQ $2, CX SHRQ $2, CX
REP; MOVSL REP; MOVSL
/* /*
@ -52,7 +52,7 @@ memcpy:
*/ */
ANDL $3, BX ANDL $3, BX
c3: c3:
MOVL BX, CX MOVQ BX, CX
REP; MOVSB REP; MOVSB
RET RET

View file

@ -1,7 +1,7 @@
TEXT memchr(SB),$0 TEXT memchr(SB),$0
MOVL n+16(FP), CX MOVQ n+16(FP), CX
CMPL CX, $0 CMPQ CX, $0
JEQ none JEQ none
MOVQ RARG, DI MOVQ RARG, DI
MOVBLZX c+8(FP), AX MOVBLZX c+8(FP), AX

View file

@ -1,7 +1,7 @@
TEXT memcmp(SB),$0 TEXT memcmp(SB),$0
MOVL n+16(FP), BX MOVQ n+16(FP), BX
CMPL BX, $0 CMPQ BX, $0
JEQ none JEQ none
MOVQ RARG, DI MOVQ RARG, DI
MOVQ p2+8(FP), SI MOVQ p2+8(FP), SI
@ -14,7 +14,7 @@
* first by longs * first by longs
*/ */
MOVL BX, CX MOVQ BX, CX
SHRQ $2, CX SHRQ $2, CX
REP; CMPSL REP; CMPSL
@ -25,7 +25,7 @@
*/ */
ANDL $3, BX ANDL $3, BX
c3: c3:
MOVL BX, CX MOVQ BX, CX
REP; CMPSB REP; CMPSB
JNE found1 JNE found1

View file

@ -2,8 +2,8 @@ TEXT memcpy(SB), $0
MOVQ RARG, DI MOVQ RARG, DI
MOVQ DI, AX /* return value */ MOVQ DI, AX /* return value */
MOVQ p2+8(FP), SI MOVQ p2+8(FP), SI
MOVL n+16(FP), BX MOVQ n+16(FP), BX
CMPL BX, $0 CMPQ BX, $0
JGT _ok JGT _ok
JEQ _return /* nothing to do if n == 0 */ JEQ _return /* nothing to do if n == 0 */
MOVL $0, SI /* fault if n < 0 */ MOVL $0, SI /* fault if n < 0 */
@ -40,7 +40,7 @@ _forward:
*/ */
JEQ _return /* flags set by above ANDL */ JEQ _return /* flags set by above ANDL */
c3f: c3f:
MOVL BX, CX MOVQ BX, CX
REP; MOVSB REP; MOVSB
RET RET
@ -62,7 +62,7 @@ _back:
ORQ SI, DX ORQ SI, DX
ANDL $3, DX ANDL $3, DX
JNE c3b JNE c3b
MOVL BX, CX MOVQ BX, CX
SHRQ $2, CX SHRQ $2, CX
ANDL $3, BX ANDL $3, BX
REP; MOVSL REP; MOVSL
@ -74,7 +74,7 @@ _back:
c3b: c3b:
ADDQ $3, DI ADDQ $3, DI
ADDQ $3, SI ADDQ $3, SI
MOVL BX, CX MOVQ BX, CX
REP; MOVSB REP; MOVSB
_return: _return:

View file

@ -2,8 +2,8 @@ TEXT memmove(SB), $0
MOVQ RARG, DI MOVQ RARG, DI
MOVQ DI, AX /* return value */ MOVQ DI, AX /* return value */
MOVQ p2+8(FP), SI MOVQ p2+8(FP), SI
MOVL n+16(FP), BX MOVQ n+16(FP), BX
CMPL BX, $0 CMPQ BX, $0
JGT _ok JGT _ok
JEQ _return /* nothing to do if n == 0 */ JEQ _return /* nothing to do if n == 0 */
MOVL $0, SI /* fault if n < 0 */ MOVL $0, SI /* fault if n < 0 */
@ -40,7 +40,7 @@ _forward:
*/ */
JEQ _return /* flags set by above ANDL */ JEQ _return /* flags set by above ANDL */
c3f: c3f:
MOVL BX, CX MOVQ BX, CX
REP; MOVSB REP; MOVSB
RET RET
@ -62,7 +62,7 @@ _back:
ORQ SI, DX ORQ SI, DX
ANDL $3, DX ANDL $3, DX
JNE c3b JNE c3b
MOVL BX, CX MOVQ BX, CX
SHRQ $2, CX SHRQ $2, CX
ANDL $3, BX ANDL $3, BX
REP; MOVSL REP; MOVSL
@ -74,7 +74,7 @@ _back:
c3b: c3b:
ADDQ $3, DI ADDQ $3, DI
ADDQ $3, SI ADDQ $3, SI
MOVL BX, CX MOVQ BX, CX
REP; MOVSB REP; MOVSB
_return: _return:

View file

@ -1,13 +1,13 @@
TEXT memset(SB),$0 TEXT memset(SB),$0
CLD CLD
MOVQ RARG, DI MOVQ RARG, DI
MOVBLZX c+8(FP), AX MOVBLZX c+8(FP), AX
MOVL n+16(FP), BX MOVQ n+16(FP), BX
/* /*
* if not enough bytes, just set bytes * if not enough bytes, just set bytes
*/ */
CMPL BX, $9 CMPQ BX, $9
JLS c3 JLS c3
/* /*
* if not aligned, just set bytes * if not aligned, just set bytes

View file

@ -1,7 +1,7 @@
TEXT memcpy(SB), $-4 TEXT memcpy(SB), $-4
TEXT memmove(SB), $-4 TEXT memmove(SB), $-4
MOV from+8(FP), R1 MOV from+8(FP), R1
MOVWU n+16(FP), R2 MOV n+16(FP), R2
CMP R0, R1 CMP R0, R1
BEQ _done BEQ _done

View file

@ -1,6 +1,6 @@
TEXT memset(SB), $-4 TEXT memset(SB), $-4
MOVBU c+8(FP), R1 MOVBU c+8(FP), R1
MOVWU n+16(FP), R2 MOV n+16(FP), R2
MOV R0, R5 MOV R0, R5
ADD R0, R2, R3 ADD R0, R2, R3

View file

@ -2,7 +2,7 @@
#include <libc.h> #include <libc.h>
void* void*
memccpy(void *a1, void *a2, int c, ulong n) memccpy(void *a1, void *a2, int c, usize n)
{ {
uchar *s1, *s2; uchar *s1, *s2;

View file

@ -2,7 +2,7 @@
#include <libc.h> #include <libc.h>
void* void*
memchr(void *ap, int c, ulong n) memchr(void *ap, int c, usize n)
{ {
uchar *sp; uchar *sp;

View file

@ -2,7 +2,7 @@
#include <libc.h> #include <libc.h>
int int
memcmp(void *a1, void *a2, ulong n) memcmp(void *a1, void *a2, usize n)
{ {
uchar *s1, *s2; uchar *s1, *s2;
uint c1, c2; uint c1, c2;

View file

@ -2,12 +2,10 @@
#include <libc.h> #include <libc.h>
void* void*
memmove(void *a1, void *a2, ulong n) memmove(void *a1, void *a2, usize n)
{ {
char *s1, *s2; char *s1, *s2;
if((long)n < 0)
abort();
s1 = a1; s1 = a1;
s2 = a2; s2 = a2;
if((s2 < s1) && (s2+n > s1)) if((s2 < s1) && (s2+n > s1))
@ -29,7 +27,7 @@ back:
} }
void* void*
memcpy(void *a1, void *a2, ulong n) memcpy(void *a1, void *a2, usize n)
{ {
return memmove(a1, a2, n); return memmove(a1, a2, n);
} }

View file

@ -2,7 +2,7 @@
#include <libc.h> #include <libc.h>
void* void*
memset(void *ap, int c, ulong n) memset(void *ap, int c, usize n)
{ {
char *p; char *p;