Anonymous | Login | Signup for a new account 2016-09-30 18:54 CEST
 Main | My View | View Issues | Change Log | Roadmap

View Issue Details  Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006125OCamlOcaml optimizationpublic2013-08-06 20:032015-12-03 13:50
Reportervbrankov
Assigned To
PrioritynormalSeverityminorReproducibilityalways
StatusacknowledgedResolutionopen
PlatformOSOS Version
Product Version4.00.1
Target VersionlaterFixed in Version
Summary0006125: Slow LEA on Sandy Bridge hurts(?) OCaml's integer arithmetic
DescriptionFrom Intel's manuals:

"Some instructions have an increased latency in IntelĀ® microarchitecture code name Sandy Bridge. Some LEA instructions, most notably three-operand LEA instructions, have increased latency and reduced dispatch port choices compared to other LEAs."

That's exactly what OCaml uses for integer arithmetic. Let's benchmark:

1. for j = 0 to len - 1 do
s := !s + a.(j);
s := !s + a.(j);
s := !s + a.(j);
s := !s + a.(j);
done

2. for j = 0 to len - 1 do
s := Int64.add !s a.(j);
s := Int64.add !s a.(j);
s := Int64.add !s a.(j);
s := Int64.add !s a.(j);
done

3. for j = 0 to len - 1 do
s := !s + a.x;
s := !s + a.x;
s := !s + a.x;
s := !s + a.x;
done

4. for j = 0 to len - 1 do
s := Int64.add !s a.y;
s := Int64.add !s a.y;integer
s := Int64.add !s a.y;
s := Int64.add !s a.y;
done

Nehalem:

1. 0.001237
2. 0.002479
3. 0.001237
4. 0.002452

vs. Sandy Bridge:

1. 0.004084
2. 0.001523
3. 0.004060
4. 0.001564

Ups, 63-bit code just got three times slower. 64-bit int got faster.

When we hack OCaml compiler to turn off LEA for integer arithmetic the situation gets better on Sandy Bridge.

Nehalem:

1. 0.002458
2. 0.002495
3. 0.002447
4. 0.002477

Sandy Bridge:

1. 0.002737
2. 0.001474
3. 0.002726
4. 0.001545

The only idea to tackle this, apart from switching to 64-bit integers, is to optionally turn off three operand LEA for integer arithmetic or to replace it with two operand LEA + int operation.
Tagspatch
Attached Files test.ml [^] (1,546 bytes) 2013-08-06 20:03
lea-patch.txt [^] (1,317 bytes) 2013-08-14 15:50
lea-bench.ml [^] (1,008 bytes) 2013-08-14 15:51
lea-patch-2.txt [^] (1,316 bytes) 2013-08-14 17:29

 Relationships