Right now this is how I'm doing it, but it definitely doesn't look very... efficient:
(Value is just a uint64)
proc writeValue(v:Value) =
CD.add(Byte(v shr 56))
CD.add(Byte(v and Value(0x00ff000000000000)))
CD.add(Byte(v and Value(0x0000ff0000000000)))
CD.add(Byte(v and Value(0x000000ff00000000)))
CD.add(Byte(v and Value(0x00000000ff000000)))
CD.add(Byte(v and Value(0x0000000000ff0000)))
CD.add(Byte(v and Value(0x000000000000ff00)))
CD.add(Byte(v and Value(0x00000000000000ff)))
template readValue():Value =
inc(IP,8); (Value(CD[IP-8]) shl 56) or (Value(CD[IP-7]) shl 48) or (Value(CD[IP-6]) shl 40) or (Value(CD[IP-5]) shl 32) or (Value(CD[IP-4]) shl 24) or (Value(CD[IP-3]) shl 16) or (Value(CD[IP-2]) shl 8) or Value(CD[IP-1])
Any suggestions?
I perfectly understand what you're saying. I've benchmarked seq s myself a lot and my conclusions are pretty much the same. The add s were left there for the sake of the example - my main concern was to get it working, and optimize the masking part first.
But I obviously see your point - I'll optimize it afteer the initial issues have been solved.
More compact source code you may get with something like
var a: array[32, byte]
var p: ptr uint64
var myUint64: uint64 = 123456
p = cast[ptr uint64](addr a[8])
p[] = myUint64
but so you have no influence on endianess and of course you have to care that you do write only to valid memory regions. The final assembler code may be identical to your above bit masking operations.
https://stackoverflow.com/questions/tagged/nim-lang
I just saw that you polluted stackoverflow with lots of mostly un-anwered, duplicated questions, at the same time advertising yourself with a Dr degree, giving the questions a serious touch.
I hope you will answer them all carefully yourself, as Araq and maratsim may be busy.
For me unanswered questions on stackoverflow is a strong indication that a language or library is death. At the same time many questions there generates the impression that a better place, like a forum or mailing list does not exists any longer.
That is my personal view, but I know some people thinking similar.
Well, I guess I won't... pollute any place any more with my questions anymore, in case anyone else discovers how many self-entitled, pretentious people are in here. (With the sole exception of @mratsim)
The sure thing is with that type of mindset nothing will ever advance.
So... Have a great day from me!
Well, I wrote that above is [only] my personal view. I am in no way part of the the Nim team, only an observer.
Obviously you have a different point of view, that is fine.
But what do you think when you see a lot serious unanswered questions on stackoverflow? Are you not thinking that this project seems to be in a bad state?
It is easy to cure that, just add fine anwers to stackoverflow, or maybe a link to the answer in this forum if available.
Maybe you even tried to advertise Nim on stackoverflow with your questions? I can remember some years ago someone tried that, he posted dozens of Nim questions on stackoverflow in a short time period. But personally I doubt that this will work without fine answers.
Finally, for the wording: Pollute may be indeed a too negative expression -- I have no other term available currently, as you know from my bad English I am not a native speaker :-)