Skip to content

Commit

Permalink
small_SUITE: Improve tests of multiplication
Browse files Browse the repository at this point in the history
On x86_64, multiplication with some small integers are optimized
using LEA, so we want to ensure that all of those integers values
are tested. Multiplication with 9 was not tested.
  • Loading branch information
bjorng committed Mar 4, 2025
1 parent bc555c1 commit 3f4c643
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion erts/emulator/test/small_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ mul_gen_pairs() ->

%% Generate pairs of numbers whose product is small.
SmallPairs = [{N, MaxSmall div N} ||
N <- [1,2,3,4,5,8,16,17,32,63,64,1111,22222]],
N <- [1,2,3,4,5,6,7,8,9,16,17,32,63,64,1111,22222]],
Pairs1 = [{N,M-1} || {N,M} <- SmallPairs] ++ SmallPairs ++ Pairs0,

%% Add prime factors of 2^59 - 1 (MAX_SMALL for 64-bit architecture
Expand Down Expand Up @@ -595,6 +595,17 @@ gen_mul_add_function({Name,{A,B,C}}) ->
Res = id(Z + X * Y),
Res = id(Z + Y * X),
Res;
'@Name@'(int_vii_plus_z, X, fixed, fixed)
when is_integer(X), -_@APlusOne@ < X, X < _@APlusOne@ ->
Y = _@B@,
Z = _@C@,
Res = id(X * Y + Z),
Res = id(Y * X + Z),
Res = id(Z + X * Y),
Res = id(Z + Y * X),
Res = '@Name@'(any_vvi_plus_z, X, id(Y), fixed),
Res = '@Name@'(any_vvv_minus_z, X, id(Y), id(-Z)),
Res;
'@Name@'(any_vvv_plus_z, X, Y, Z) ->
Res = id(X * Y + Z),
Res = id(Y * X + Z),
Expand Down Expand Up @@ -656,6 +667,7 @@ test_mul_add([{Name,{A,B,C}}|T], Mod) ->
Res0 = A * B + C,
Res0 = F(any_vii_plus_z, A, fixed, fixed),
Res0 = F(pos_int_vvv_plus_z, A, B, C),
Res0 = F(int_vii_plus_z, A, fixed, fixed),
ok = F({guard_plus_z,Res0}, A, B, C),
ok = F({guard_plus_z,Res0}, -A, -B, C),

Expand Down

0 comments on commit 3f4c643

Please sign in to comment.