Code: Select all
uint64_t st[25];
uint8_t temp[144];
int i;
for (i = 0; i < 19; i++) {
st[i] ^= ((uint64_t *) temp)[i];
}
Code: Select all
uint64_t st[25];
uint8_t temp[144];
int i;
for (i = 0; i < 19; i++) {
st[i] ^= ((uint64_t *) temp)[i];
}
If i use two quad, the result is not same in C.IdeasVacuum wrote:Well, it appears to be casting between two un-signed integer types (would need the type definition header file stdint.h). I think you can use quads in PB and not need the cast?
Code: Select all
Structure st_25_t
q.q[25]
EndStructure
Structure temp_144_t
b.b[144]
EndStructure
Global st_25.st_25_t
Global temp_144.temp_144_t
Global i.l
For i=0 To 18
st_25\q[i] ! temp_144\b[i]
Next
Code: Select all
Global Dim st_25.q(24)
Global Dim temp_144.b(143)
Global i.l
For i=0 To 18
st_25(i) ! temp_144(i)
Next
Code: Select all
Structure st_25_t
q.q[25]
EndStructure
Structure temp_144_t
b.b[144]
EndStructure
Global st_25.st_25_t
Global temp_144.temp_144_t
Global *st_25.Quad = @st_25
Global *temp_144.Byte = @temp_144
Global i.l
#SIZE_OF_QUAD = SizeOf(Quad)
#SIZE_OF_BYTE = SizeOf(Byte)
i = 0
While i < 19
*st_25\q ! *temp_144\b
*st_25 + #SIZE_OF_QUAD : *temp_144 + #SIZE_OF_BYTE : i + 1
Wend
You are right, indeed.tinman wrote:@grabiller: Your code uses the byte pointers incorrectly. The C code casts temp to an (uint64_t *) so it is addressing it as a pointer to uint64_t's, not bytes. So when you do the increment it should be by sizeof(QUAD), not sizeof(byte).
Code: Select all
Structure st_25_t
q.q[25]
EndStructure
Structure temp_144_t
b.b[144]
EndStructure
Global st_25.st_25_t
Global temp_144.temp_144_t
Global *st_25.Quad = @st_25
Global *temp_144.Byte = @temp_144
Global i.l
#SIZE_OF_QUAD = SizeOf(Quad)
#SIZE_OF_BYTE = SizeOf(Byte)
i = 0
While i < 19
*st_25\q ! *temp_144\b
*st_25 + #SIZE_OF_QUAD : *temp_144 + #SIZE_OF_QUAD : i + 1
Wend
Code: Select all
Dim st.q(24)
Dim temp.b(143)
For i = 0 To 18
st(i) ! PeekQ(@temp(i * SizeOf(Quad)))
Next
Code: Select all
Dim temp.c(7)
temp(0) = 0
temp(1) = 0
temp(2) = 0
temp(3) = 0
temp(4) = 0
temp(5) = 0
temp(6) = 0
temp(7) = $80
Debug PeekQ(@temp())
C output with %llu, printf("%llu\n", ((uint64_t *) temp)[0]);-9223372036854775808
How to convert that PB sign? in PB, I tried & $FFFFFFFFFFFFFFFF but output is incorrect (-9223372036854775808)9223372036854775808
Thanks, I want to know sure that the number's value is stored correct.IdeasVacuum wrote:SkyWalk wrote a sprintf function for PB: http://www.purebasic.fr/english/viewtopic.php?p=315920
Search this forum for "large numbers", I recall that someone has worked on this requirement.
A possibility is to work with strings, as the integer/quad value is too big for 32bit
Code: Select all
Dim temp.c(7)
temp(0) = 0
temp(1) = 0
temp(2) = 0
temp(3) = 0
temp(4) = 0
temp(5) = 0
temp(6) = 0
temp(7) = $80
a.q = PeekQ(@temp())
Debug StrU(a)
Right, so it should be:tinman wrote:Edit: I should also say that in your corrected version you are only readnig a byte from *temp_144\b whereas the C code reads a uint64_t, so it's really PeekQ() that's needed or assigning the temp pointer to a quad pointer.
Code: Select all
Global *temp_144.Quad = @temp_144
Code: Select all
*st_25\q ! *temp_144\q
*st_25 + #SIZE_OF_QUAD : *temp_144 + #SIZE_OF_QUAD : i + 1
Code: Select all
ImportC ""
sprintf(*out,format.p-Ascii,val.q)
EndImport
Procedure.s outQ(v.q)
Protected sout.s,*output
*output = AllocateMemory(64)
sprintf(*output,"%llu",v)
sout = PeekS(*output,-1,#PB_Ascii)
FreeMemory(*output)
ProcedureReturn sout
EndProcedure
Macro ROTL64(x, y)
((x) << (y)) | ((x) >> (64 - (y)))
EndMacro
Dim temp.c(7)
temp(0) = 0
temp(1) = 0
temp(2) = 0
temp(3) = 0
temp(4) = 0
temp(5) = 0
temp(6) = 0
temp(7) = $80
v.q = PeekQ(@temp())
vrol.q = ROTL64(v,1)
Debug StrU(vrol) ;[b]18446744073709551615[/b] << seem this range limit of PB
debug OutQ(vrol) ; 18446744073709551615
Code: Select all
Macro RotLeft64(var,pp)
!if defined v_#var
!rol qword [v_#var],pp
!else
!rol qword [p.v_#var],pp
!end if
EndMacro
Dim temp.a(7)
temp(0) = 0
temp(1) = 0
temp(2) = 0
temp(3) = 0
temp(4) = 0
temp(5) = 0
temp(6) = 0
temp(7) = $80
v.q = PeekQ(@temp())
Debug RSet(Bin(v,#PB_Quad),64,"0");
RotLeft64(v,1)
Debug RSet(Bin(v,#PB_Quad),64,"0");
@idle: it gotidle wrote:try this macro
Code: Select all
Macro RotLeft64(var,pp) !if defined v_#var !rol qword [v_#var],pp !else !rol qword [p.v_#var],pp !end if EndMacro Dim temp.a(7) temp(0) = 0 temp(1) = 0 temp(2) = 0 temp(3) = 0 temp(4) = 0 temp(5) = 0 temp(6) = 0 temp(7) = $80 v.q = PeekQ(@temp()) Debug RSet(Bin(v,#PB_Quad),64,"0"); RotLeft64(v,1) Debug RSet(Bin(v,#PB_Quad),64,"0");
Thanks,PureBasic.asm [194]:
rol qword [p.v_v],pp
error: illegal instruction