Skip to content

Commit

Permalink
Change Random to use dSFMT_jll
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Jul 27, 2023
1 parent 9ebc52e commit 30dfa21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkgimage.mk
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ $(eval $(call sysimg_builder,nghttp2_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,OpenLibm_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,PCRE2_jll,Artifacts Libdl))
$(eval $(call sysimg_builder,Zlib_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,dSFMT_jll,Artifacts Libdl))
$(eval $(call sysimg_builder,dSFMT_jll,Artifacts Libdl))
$(eval $(call pkgimg_builder,libLLVM_jll,Artifacts Libdl))
$(eval $(call sysimg_builder,libblastrampoline_jll,Artifacts Libdl))
$(eval $(call sysimg_builder,OpenBLAS_jll,Artifacts Libdl))
$(eval $(call sysimg_builder,Markdown,Base64))
$(eval $(call sysimg_builder,Printf,Unicode))
$(eval $(call sysimg_builder,Random,SHA))
$(eval $(call sysimg_builder,Tar,ArgTools,SHA))
$(eval $(call pkgimg_builder,DelimitedFiles,Mmap))

# 2-depth packages
$(eval $(call sysimg_builder,Random,SHA dSFMT_jll))
$(eval $(call pkgimg_builder,LLD_jll,Zlib_jll libLLVM_jll Artifacts Libdl))
$(eval $(call sysimg_builder,LibSSH2_jll,Artifacts Libdl MbedTLS_jll))
$(eval $(call pkgimg_builder,MPFR_jll,Artifacts Libdl GMP_jll))
Expand Down
1 change: 1 addition & 0 deletions stdlib/Random/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name = "Random"
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[deps]
dSFMT_jll = "05ff407c-b0c1-5878-9df8-858cc2e60c36"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[extras]
Expand Down
15 changes: 8 additions & 7 deletions stdlib/Random/src/DSFMT.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module DSFMT

import Base: copy, copy!, ==, hash
using Base.GMP.MPZ
using dSFMT_jll

export DSFMT_state, dsfmt_get_min_array_size, dsfmt_get_idstring,
dsfmt_init_gen_rand, dsfmt_init_by_array, dsfmt_gv_init_by_array,
Expand Down Expand Up @@ -44,36 +45,36 @@ hash(s::DSFMT_state, h::UInt) = hash(s.val, h)
## wrapper functions

function dsfmt_get_idstring()
idstring = ccall((:dsfmt_get_idstring,:libdSFMT),
idstring = ccall((:dsfmt_get_idstring,libdSFMT),
Ptr{UInt8},
())
return unsafe_string(idstring)
end

function dsfmt_get_min_array_size()
min_array_size = ccall((:dsfmt_get_min_array_size,:libdSFMT),
min_array_size = ccall((:dsfmt_get_min_array_size,libdSFMT),
Int32,
())
end

const dsfmt_min_array_size = dsfmt_get_min_array_size()

function dsfmt_init_gen_rand(s::DSFMT_state, seed::UInt32)
ccall((:dsfmt_init_gen_rand,:libdSFMT),
ccall((:dsfmt_init_gen_rand,libdSFMT),
Cvoid,
(Ptr{Cvoid}, UInt32,),
s.val, seed)
end

function dsfmt_init_by_array(s::DSFMT_state, seed::Vector{UInt32})
ccall((:dsfmt_init_by_array,:libdSFMT),
ccall((:dsfmt_init_by_array,libdSFMT),
Cvoid,
(Ptr{Cvoid}, Ptr{UInt32}, Int32),
s.val, seed, length(seed))
end

function dsfmt_gv_init_by_array(seed::Vector{UInt32})
ccall((:dsfmt_gv_init_by_array,:libdSFMT),
ccall((:dsfmt_gv_init_by_array,libdSFMT),
Cvoid,
(Ptr{UInt32}, Int32),
seed, length(seed))
Expand All @@ -82,7 +83,7 @@ end
function dsfmt_fill_array_close1_open2!(s::DSFMT_state, A::Ptr{Float64}, n::Int)
@assert Csize_t(A) % 16 == 0 # the underlying C array must be 16-byte aligned
@assert dsfmt_min_array_size <= n && iseven(n)
ccall((:dsfmt_fill_array_close1_open2,:libdSFMT),
ccall((:dsfmt_fill_array_close1_open2,libdSFMT),
Cvoid,
(Ptr{Cvoid}, Ptr{Float64}, Int),
s.val, A, n)
Expand All @@ -91,7 +92,7 @@ end
function dsfmt_fill_array_close_open!(s::DSFMT_state, A::Ptr{Float64}, n::Int)
@assert Csize_t(A) % 16 == 0 # the underlying C array must be 16-byte aligned
@assert dsfmt_min_array_size <= n && iseven(n)
ccall((:dsfmt_fill_array_close_open,:libdSFMT),
ccall((:dsfmt_fill_array_close_open,libdSFMT),
Cvoid,
(Ptr{Cvoid}, Ptr{Float64}, Int),
s.val, A, n)
Expand Down

0 comments on commit 30dfa21

Please sign in to comment.