Yes, you can see this using ripgrep: ➜ factor-master git:(master) ✗ cd vm ➜ vm git:(master) ✗ rg nano_count os-genunix.cpp 30:uint64_t nano_count() {
os-windows.hpp <----------------------- 70:uint64_t nano_count(); os-macosx.mm 77:uint64_t nano_count() { vm.cpp 31: last_nano_count(0), os-unix.hpp 49:uint64_t nano_count(); os-windows.cpp <------------------------ 147:uint64_t nano_count() { 155: // nano_count calls would show a difference of about 1 second, factor.cpp 67: srand((unsigned int)nano_count()); gc.cpp 10: start_time(nano_count()), 14: start_time = nano_count(); 17:void gc_event::reset_timer() { temp_time = nano_count(); } 20: times[phase] = (cell)(nano_count() - temp_time); 26: total_time = (cell)(nano_count() - start_time); 32: start_time = nano_count(); run.cpp 12:void factor_vm::primitive_nano_count() { 13: uint64_t nanos = nano_count(); 14: if (nanos < last_nano_count) { 16: std::cout << std::hex << last_nano_count; 21: last_nano_count = nanos; primitives.hpp 32: _(minor_gc) _(modify_code_heap) _(nano_count) _(quotation_code) \ vm.hpp 140: uint64_t last_nano_count; 176: void primitive_nano_count(); On Fri, Jun 5, 2020 at 5:14 PM Alexander Ilin <ajs...@yandex.ru> wrote: > Does it also return 8 bytes in 32-bit Windows? > > 06.06.2020, 01:09, "Doug Coleman" <doug.cole...@gmail.com>: > > Actually, I can be more helpful. ``nano-count`` returns a ``uint64_t`` so > you need 8 bytes. > > In vm/os-genunix.cpp: > > uint64_t nano_count() { > struct timespec t; > int ret = clock_gettime(CLOCK_MONOTONIC, &t); > if (ret != 0) > fatal_error("clock_gettime failed", 0); > return (uint64_t)t.tv_sec * 1000000000 + t.tv_nsec; > } > > On Fri, Jun 5, 2020 at 5:00 PM Doug Coleman <doug.cole...@gmail.com> > wrote: > > As long as you can fully round-trip the integer, it doesn't matter how > many bytes you use. > > nano-count dup 4 >be be> = . > f > > nano-count dup 8 >be be> = . > t > > nano-count dup 128 >be be> = . > t > > > > ``log2 1 +`` will give you the required number of bits to store an > integer. You will want to round up to a power of 8 bits or a power of two > bytes. > > USE: math.bitwise > nano-count dup dup log2 1 + bits = > > On Fri, Jun 5, 2020 at 4:44 PM Alexander Ilin <ajs...@yandex.ru> wrote: > > Hello again! > > My specific example is the following. I want to put the output of > `nano-count` into a `byte-array`, which is fed into a hash. The current > value of `nano-count` is one of the sources of randomness gathered from the > system and poured into the hash. To convert the integer value into a > `byte-array` there are `>le` and `>be`, but they require the number of > bytes as a parameter. The question is, what should I supply for the value > received from `nano-count`? > > And the bigger question is, given an integer value, is there a way to > interrogate it about its byte size, i.e. the minimum number of bytes it > takes to hold the value without truncation and without leading zeroes: > > Value -- MinSize > 0 -- 1 > 255 -- 1 > 256 -- 2 > 65535 -- 2 > 65536 -- 3 > etc. > > I would expect such information to be available somewhere without doing > the power of two calculations in a loop. > > 23.03.2020, 05:41, "Doug Coleman" <doug.cole...@gmail.com>: > > For Factor, integers are either fixnum or bignum size. For C, you tell it > how many bytes it occupies according to the C header. Generally the sizes > are the same across platforms. If they aren't, you might need two different > STRUCT: declarations like in basis/unix/stat/linux/32/32.factor > and basis/unix/stat/linux/64/64.factor. > > The main point -- function signatures and struct declarations usually > handle the integer sizes and you shouldn't have to think much about it. Do > you have a specific example? > > > > > Earlier I wrote: > > One more question. I want to convert an integer into a byte-array > containing its bytes. In my use case it was the return value of the > nano-count, but the question is general: how can I get the bytes of an > integer. > > For floats there are primitives like float>bits and double>bits, and for > integers there is >le and >be, but for the latter two I need to specify the > size in bytes. Is there a way to ask an integer how many bytes it occupies? > Because from the documentation it's not clear at all how many bytes > nano-count would return, and it may vary depending on the current platform. > What am I missing? > > _______________________________________________ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > ,, > > _______________________________________________ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk > > _______________________________________________ > Factor-talk mailing list > Factor-talk@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/factor-talk >
_______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk