How Does Intrinsic Work

How does intrinsic work?

It looks like the intrinsic value is part of the newer CSS3 sizing module:

http://dev.w3.org/csswg/css-sizing/

I have not used it yet but perhaps the reference will provide you with more information.

Based on a quick review, this module would make it easier to specify how content fills the width and height of a parent containing block.

At the moment, JavaScript functions are often used to compute widths and heights of container blocks based on % values for variable child elements content.

How does the _mm_cmpgt_epi64 intrinsic work

It appears you're printing it in 32-bit chunks, not 64-bit, so that's weird.

But anyway, it's a signed two's complement integer compare, as documented in the manual: http://felixcloutier.com/x86/PCMPGTQ.html

0x8000000000000000 is the most negative 64-bit integer, while 0x7fffffffffffffff is the largest positive.

If you want an unsigned compare, you need to range-shift both inputs by flipping their sign bit. Logically this is subtracting 2^63 to go from 0..2^64-1 to -2^63 .. 2^63-1. But we can do it with a more efficient XOR, because XOR is add-without-carry, and the carry/borrow-out goes off the end of the register.

const __m128i rangeshift = _mm_set1_epi64x(0x8000000000000000);
const __m128i mask = _mm_cmpgt_epi64(_mm_xor_si128(bflip, rangeshift), _mm_xor_si128(sumflip, rangeshift));

Or use AVX512F __mmask8 _mm512_cmp[eq|ge|gt|le|lt|neq]_epu64_mask( __m512i a, __m512i b)

What are intrinsics?

Normally, "intrinsics" refers to functions that are built-in -- i.e. most standard library functions that the compiler can/will generate inline instead of calling an actual function in the library. For example, a call like: memset(array1, 10, 0) could be compiled for an x86 as something like:

 mov ecx, 10
xor eax, eax
mov edi, offset FLAT:array1
rep stosb

Intrinsics like this are purely an optimization. "Needing" intrinsics would most likely be a situation where the compiler supports intrinsics that let you generate code that the compiler can't (or usually won't) generate directly. For an obvious example, quite a few compilers for x86 have "MMX Intrinsics" that let you use "functions" that are really just direct representations of MMX instructions.

What does intrinsic lock actually mean for a Java class?

So just to repeat my comment above as an answer. Intrinsic locking means that you don't have to create an object to synchronize your methods on. In comparison you can use an extrinsic lock by calling synchronized(myLock) {...}.

This is an excerpt from the book Java Concurrency in Practice: "The fact that every object has a built-in lock is just a convenience so that you needn't explicitly create lock objects"

The book also says:

There is no inherent relationship between an object's intrinsic lock
and its state; an object's fields need not be guarded by its intrinsic
lock, though this is a perfectly valid locking convention that is used
by many classes. Acquiring the lock associated with an object does not
prevent other threads from accessing that objectthe only thing that
acquiring a lock prevents any other thread from doing is acquiring
that same lock. The fact that every object has a built-in lock is just
a convenience so that you needn't explicitly create lock objects. [9]
It is up to you to construct locking protocols or synchronization
policies that let you access shared state safely, and to use them
consistently throughout your program.

But in the footnote it says:

[9] In retrospect, this design decision was probably a bad one: not
only can it be confusing, but it forces JVM implementors to make
tradeoffs between object size and locking performance.

And to answer your last questions: you won't be able to call the synchronized methods from another thread, but you can keep entering from the same thread (intrinsic locks are re-entrant). So you have to imagine locking in this case as serializing method access from different caller threads.

If you use locking improperly and then you introduce liveness hazards, then yes it is defeated. That's why you have to make sure that your concurrent threads are not contending with each other too hard.

As Brian Goetz puts in this blog entry:

In tuning an application's use of synchronization, then, we should try
hard to reduce the amount of actual contention, rather than simply try
to avoid using synchronization at all

What is the difference between Java intrinsic and native methods?

The JIT knows about intrinsics, so it can inline the relevant machine instruction into the code it's JITing, and optimize around it as part of a hot loop.

A JNI function is a 100% black box for the compiler, with significant call/return overhead (especially if you use it for just a scalar).

But even if it were just a call to a function like int bitcount(unsigned x){ return __builtin_popcount(x); } that compiled to x86-64 popcnt eax, edi ; ret (x86-64 System V calling convention) the caller (which the JIT compiler is emitting) would still have to assume that all the call-clobbered registers were clobbered. On x86-64, that's most of the integer registers and all the FP/vector registers. (Just like the cost for an ahead-of-time C++ compiler for calling a black-box function vs. an intrinsic). But I suspect the cost for calling a JNI function includes some extra overhead on top of that.

And of course a call to any unknown function means that variables which were in registers might need to be synced to memory if the JIT compiler can't prove that nothing else has a reference to them. (Escape analysis.)

Plus, intrinsics mean the JVM understands what the function does, and can optimize through it. e.g. with constant propagation, it knows that popcount(5) = 2 set bits. But with an actual JNI function, it would still have to call it. And every call is a visible side-effect unless there's some way to declare the function as "pure" so it can CSE.

With heavy inlining, compile time constants are not rare.

Is the intrinsic object creation order mentioned by the ECMAScript Specification defined somewhere?

No, there is no specific order. It is not observable by user code, so it does not matter at all.

Implementers have to decide this on their own. There are many possible orders. You even may create objects and their properties separate from each other, as there are circular references (e.g. between a .prototype and its .constructor, or between Function and Object).

How do min-content and max-content work?

Note: "width" in this text refers to the "logical width", not CSS's width; that is, the values are also valid for CSS's height, if the language direction is vertical (like east-asian languages) or in flexbox or grid. min-content and max-content are valid values for width, height, min-width, min-height, max-width, max-height and even more properties (like flex-basis).

What are the intrinsic dimensions of a box?

CSS sizing level 3 introduced the concept of intrinsic dimensions - the opposite of extrinsic. An extrinsic dimension of a box is calculated on the box's parent box. For example width: 80% is said an extrinsic dimension as the width of the subject depends on the width of its containing box.

Contrarily to that, width: min-content is said intrinsic as the width of the box is calculated on the dimension of the contents that the box itself contains.

Intrinsic dimensions are properties of the box itself, extrinsic dimensions are only available if the box is placed in the document and in a context that permits these values to be calculated. For example, in CSS-flow (the classic CSS layout mode), as you probably know, height: 20% has only effect if height is defined in the parent element (i.e. it's inheritable); that is a case of an extrinsic dimension that is not calculable (when an extrinsic value is not available, CSS fallbacks to its intrinsic equivalent). Instead height: min-content is always calculable, as it is intrinsic to the box itself, and it is always the same regardless of the box's placement (or the box's absence) in the document.


The definition of min-content and max-content has changed many times over the years but the result always stayed the same, and it is pretty straightforward to grasp. They were originally requested by the community as keywords for width, whose computed value would match the widths of a box when the box is floating. And indeed, the definition of these two properties was originally based on the behavior of float; now they are more generically defined as follows:

min-content

https://www.w3.org/TR/css-sizing-3/#min-content

The smallest size a box could take that doesn’t lead to overflow that could be avoided by choosing a larger size.

In other words, the smallest width of a box where the box's contents don't overflow the box itself.

A good way to visualize this is using, in fact, float.

/* the computed width of #red in this example 
equals to specifying #red { width: min-content } */
#blue { width: 0px; }
#blue > #red { float: left; }

min-content

(GIF source: http://jsfiddle.net/6srop4zu/)

In the above GIF, the red box's min-content width equals the red box's width at the time the blue box's width is 0px (234px in the GIF, might be different in the jsfiddle).

As you can see, if the red box was made smaller, the word supercalifragilisticexpialidocious would overflow the red box, hence in this case the min-content equals the width of that particular word, as it is the one that takes the most space horizontally.

max-content

https://www.w3.org/TR/css-sizing-3/#max-content

A box’s “ideal” size in a given axis when given infinite available space. Usually this is the smallest size the box could take in that axis while still fitting around its contents, i.e. minimizing unfilled space while avoiding overflow.

/* the computed width of #red in this example
equals to specifying #red { width: max-content } */

#blue { width: 99999999999999999px; } /* ~infinite */
#blue > #red { float: left; }

max-content

(GIF source: http://jsfiddle.net/nktsrzvg/)

In the above GIF, the red box's max-content width equals the red box's width when the blue box's width is infinite (386px in the GIF, might be different in the jsfiddle).

Here, the red box fully takes advantage of the available space on the x axis in the blue box, but without wasting it. The contents are allowed to expand on the relevant axis without restrictions, and the red box wraps them and at the point of maximum expansion.


What about fit-content, stretch and others? These properties are currently being revisited and as such they are not stable (date: July 2018). They will be added here when they get a bit more mature (hopefully soon).



Related Topics



Leave a reply



Submit