mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-06-07 00:04:48 +00:00
Cutdown Rand functions, add RandU8
This commit is contained in:
parent
f03359889c
commit
7a66fdf3c4
Binary file not shown.
Binary file not shown.
BIN
src/Kernel.BIN.C
BIN
src/Kernel.BIN.C
Binary file not shown.
@ -74,75 +74,57 @@ I64 CeilI64(I64 num,I64 to)
|
||||
#define LIN_CONGRUE_A 6364136223846793005
|
||||
#define LIN_CONGRUE_C 1442695040888963407
|
||||
|
||||
I64 RandInt()
|
||||
{//Don't use this. Use the functions below.
|
||||
I64 res = Fs->rand_seed;
|
||||
res = LIN_CONGRUE_A * res ^ (res & 0xFFFFFFFF0000) >> 16 + LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags, TASKf_NONTIMER_RAND))
|
||||
res ^= GetTSC;
|
||||
Fs->rand_seed = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
U8 RandU8()
|
||||
{//Random U8.
|
||||
return RandInt & U8_MAX;
|
||||
}
|
||||
|
||||
I16 RandI16()
|
||||
{//Random I16.
|
||||
I64 res=Fs->rand_seed;
|
||||
res=LIN_CONGRUE_A*res^(res&0xFFFFFFFF0000)>>16+LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags,TASKf_NONTIMER_RAND))
|
||||
res^=GetTSC;
|
||||
Fs->rand_seed=res;
|
||||
I64 res = RandInt;
|
||||
return res.i16[0];
|
||||
}
|
||||
|
||||
U16 RandU16()
|
||||
{//Random U16.
|
||||
I64 res=Fs->rand_seed;
|
||||
res=LIN_CONGRUE_A*res^(res&0xFFFFFFFF0000)>>16+LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags,TASKf_NONTIMER_RAND))
|
||||
res^=GetTSC;
|
||||
Fs->rand_seed=res;
|
||||
return res.u16[0];
|
||||
return RandInt & U16_MAX;
|
||||
}
|
||||
|
||||
I32 RandI32()
|
||||
{//Random I32.
|
||||
I64 res=Fs->rand_seed;
|
||||
res=LIN_CONGRUE_A*res^(res&0xFFFFFFFF0000)>>16+LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags,TASKf_NONTIMER_RAND))
|
||||
res^=GetTSC;
|
||||
Fs->rand_seed=res;
|
||||
I64 res = RandInt;
|
||||
return res.i32[0];
|
||||
}
|
||||
|
||||
U32 RandU32()
|
||||
{//Random U32.
|
||||
I64 res=Fs->rand_seed;
|
||||
res=LIN_CONGRUE_A*res^(res&0xFFFFFFFF0000)>>16+LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags,TASKf_NONTIMER_RAND))
|
||||
res^=GetTSC;
|
||||
Fs->rand_seed=res;
|
||||
return res.u32[0];
|
||||
return RandInt & U32_MAX;
|
||||
}
|
||||
|
||||
I64 RandI64()
|
||||
{//Random I64.
|
||||
I64 res=Fs->rand_seed;
|
||||
res=LIN_CONGRUE_A*res^(res&0xFFFFFFFF0000)>>16+LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags,TASKf_NONTIMER_RAND))
|
||||
res^=GetTSC;
|
||||
Fs->rand_seed=res;
|
||||
return res;
|
||||
return RandInt;
|
||||
}
|
||||
|
||||
U64 RandU64()
|
||||
{//Random U64.
|
||||
I64 res=Fs->rand_seed;
|
||||
res=LIN_CONGRUE_A*res^(res&0xFFFFFFFF0000)>>16+LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags,TASKf_NONTIMER_RAND))
|
||||
res^=GetTSC;
|
||||
Fs->rand_seed=res;
|
||||
return res;
|
||||
return RandInt;
|
||||
}
|
||||
|
||||
F64 Rand()
|
||||
{//Random F64.
|
||||
I64 res=Fs->rand_seed;
|
||||
res=LIN_CONGRUE_A*res^(res&0xFFFFFFFF0000)>>16+LIN_CONGRUE_C;
|
||||
if (!Bt(&Fs->task_flags,TASKf_NONTIMER_RAND))
|
||||
res^=GetTSC;
|
||||
Fs->rand_seed=res;
|
||||
return (res&0x3FFFFFFFFFFFFFFF)/ToF64(0x4000000000000000);
|
||||
}
|
||||
return (RandInt & 0x3FFFFFFFFFFFFFFF) / ToF64(0x4000000000000000);
|
||||
}
|
||||
|
||||
I64 Seed(I64 seed=0,CTask *task=NULL)
|
||||
{//Set $LK,"Rand",A="MN:Rand"$() seed. Zero for timer-based.
|
||||
|
File diff suppressed because one or more lines are too long
@ -545,6 +545,7 @@ public extern F64 Max(F64 n1,F64 n2);
|
||||
public extern F64 Min(F64 n1,F64 n2);
|
||||
public extern F64 Pow10I64(I64 i);
|
||||
public extern F64 Rand(); //With timestamp
|
||||
public extern U8 RandU8();
|
||||
public extern I16 RandI16();
|
||||
public extern I32 RandI32();
|
||||
public extern I64 RandI64();
|
||||
@ -573,7 +574,7 @@ public _extern _FREE U0 Free(U8 *addr);
|
||||
public _extern _MALLOC U8 *MAlloc(I64 size,CTask *mem_task=NULL);
|
||||
public extern U8 *MAllocAligned(I64 size,I64 alignment,CTask *mem_task=NULL,I64 misalignment=0);
|
||||
public extern U8 *MAllocIdent(U8 *src,CTask *mem_task=NULL);
|
||||
public extern U8 *ReAlloc(U8 *src, U64 size, CTask *mem_task=NULL);
|
||||
public extern U8 *ReAlloc(U8 *src, U64 size, CTask *mem_task=NULL);
|
||||
public _extern _MHEAP_CTRL CHeapCtrl *MHeapCtrl(U8 *src);
|
||||
public _extern _MSIZE I64 MSize(U8 *src); //size of heap object
|
||||
public _extern _MSIZE2 I64 MSize2(U8 *src); //Internal size
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user