I still think Ref is the way to go.
const a = Ref{Float64}(0.0)
inc_ref() = a[] += 1
@code_llvm inc_ref()
define double @julia_inc_ref_50012() #0 {
top:
%0 = load double, double* inttoptr (i64 140310118277680 to double*),
align 16
%1 = fadd double %0, 1.000000e+00
store double %1, double* inttoptr (i64 140310118277680 to double*), align
16
ret double %1
}
type wrapper{T}
x::T
end
const w = wrapper(0.0)
function inc_global()
w.x += 1
end
@code_llvm inc_global()
define double @julia_inc_global_50045() #0 {
top:
%0 = load double, double* inttoptr (i64 139878620260272 to double*),
align 16
%1 = fadd double %0, 1.000000e+00
store double %1, double* inttoptr (i64 139878620260272 to double*), align
16
ret double %1
}
Hope I managed to paste everything correctly this time...
On Tuesday, June 14, 2016 at 6:51:32 AM UTC+2, Eric Forgy wrote:
>
> Creating a global instance of a special type seems reasonable to me. I
> also use global Dict's for this kind of thing.
>
> Instead of inc_global, I might define
>
> Base.(:+)(w::wrapper,s) = w.x + s
>
> so you can just do `w += 1` :)
>
> If you find a better way, I would love to see it.
>
> PS: Minor point, but looks like you have a typo. Should be `const w =
> wrapper(0.0)` I think. No biggie.
>
> On Tuesday, June 14, 2016 at 8:41:40 AM UTC+8, Arch Robison wrote:
>>
>> Indeed the one-element vector case was what inspired my wrapper. I
>> created the wrapper to avoid the run-time bounds check on the vector,
>> though I suppose I could sprinkle @inbounds to eliminate it.
>>
>> On Mon, Jun 13, 2016 at 6:40 PM, Eric Forgy <[email protected]> wrote:
>>
>>> Not sure if this is the best way (curious about 'Ref'), but you could
>>> also make x a 1-element vector:
>>>
>>> const x = [0]
>>>
>>> x[1] += 1
>>>
>>
>>