RFR 8239090: Improve CPU feature support in VM_version

Igor Veresov igor.veresov at oracle.com
Fri Aug 28 01:20:48 UTC 2020


You can actually make a constexpr array of feature objects and then use constexpr function with a loop to look it up. The c++ compiler will generate an O(1) table lookup for it.
That would be a good way to get rid of the ugly macro (we allow c++14 now).

For example foo() in this example:

enum E { a, b, c };

struct P {
  E _e; // key
  int _v; // value
  constexpr P(E e, int v) : _e(e), _v(v) { }
};


constexpr static P ps[3] = { P(a, 0xdead), P(b, 0xbeef), P(c, 0xf00d)};

constexpr int match(E e) {
  for (const auto& p : ps) {
    if (p._e == e) {
      return p._v;
    }
  }
  return -1;
}


int foo(E e) {
  return match(e);
}

Will be compiled into:

__Z3foo1E:                              ## @_Z3foo1E
	.cfi_startproc
## %bb.0:
	movl	$-1, %eax
	cmpl	$2, %edi
	ja	LBB0_2
## %bb.1:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	movslq	%edi, %rax
	leaq	l_switch.table._Z3foo1E(%rip), %rcx
	movq	(%rcx,%rax,8), %rax
	movl	4(%rax), %eax
	popq	%rbp
LBB0_2:
	retq
	.cfi_endproc
                                        ## -- End function
	.section	__TEXT,__const
	.p2align	4               ## @_ZL2ps
__ZL2ps:
	.long	0                       ## 0x0
	.long	57005                   ## 0xdead
	.long	1                       ## 0x1
	.long	48879                   ## 0xbeef
	.long	2                       ## 0x2
	.long	61453                   ## 0xf00d

	.section	__DATA,__const
	.p2align	3               ## @switch.table._Z3foo1E
l_switch.table._Z3foo1E:
	.quad	__ZL2ps
	.quad	__ZL2ps+8
	.quad	__ZL2ps+16


igor


> On Aug 27, 2020, at 11:08 AM, Eric, Chan <jingxinc at amazon.com> wrote:
> 
> Hi,
> 
> Requesting review for
> 
> Webrev : http://cr.openjdk.java.net/~phh/8239090/webrev.00/
> JBS : https://bugs.openjdk.java.net/browse/JDK-8239090
> 
> Yesterday I sent a wrong one, so I send it again,
> I improve the “get_processor_features” method by store every cpu features in an enum array so that we don’t have to count how many “%s” that need to added. I passed the tier1 test successfully.
> 
> Regards,
> Eric Chen
> 



More information about the hotspot-compiler-dev mailing list