summaryrefslogtreecommitdiff
path: root/erts/emulator/beam/jit/x86/predicates.tab
blob: cd1230cd1a43afd63c7d51ec310879ab69886d77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// -*- c -*-
//
// %CopyrightBegin%
//
// Copyright Ericsson AB 2020-2021. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// %CopyrightEnd%
//

pred.is_mfa_bif(M, F, A) {
    Export *e;

    ASSERT(M.type == TAG_a && F.type == TAG_a && A.type == TAG_u);
    e = erts_active_export_entry(M.val, F.val, A.val);

    if (e != NULL) {
        return e->bif_number != -1;
    }

    return 0;
}

pred.never_fails(Bif) {
    static Eterm nofail_bifs[] =
	{am_Neqeq,
	 am_Le,
	 am_Neq,
	 am_Eq,
	 am_Le,
	 am_Eqeq,
	 am_Gt,
	 am_Ge,
	 am_is_atom,
	 am_is_boolean,
	 am_is_binary,
	 am_is_bitstring,
	 am_is_float,
	 am_is_integer,
	 am_is_list,
	 am_is_map,
	 am_is_number,
	 am_is_pid,
	 am_is_port,
	 am_is_reference,
	 am_is_tuple,
	};

    Uint index = Bif.val;

    if (Bif.type == TAG_u && index < S->beam.imports.count) {
	BeamFile_ImportEntry *entry = &S->beam.imports.entries[index];
	int i;

	if (entry->module != am_erlang) {
	    return 0;
	}

	if (entry->function == am_is_function) {
	    /* Note that is_function/2 may fail. */
	    return entry->arity == 1;
	}

	for (i = 0; i < sizeof(nofail_bifs) / sizeof(nofail_bifs[0]); i++) {
	    if (entry->function == nofail_bifs[i]) {
		return 1;
	    }
	}
    }
    return 0;
}

pred.is_eq_exact_bif(Bif) {
    Uint index = Bif.val;

    if (Bif.type == TAG_u && index < S->beam.imports.count) {
	BeamFile_ImportEntry *entry = &S->beam.imports.entries[index];

	return entry->module == am_erlang && entry->function == am_Eq && entry->arity == 2;
    }
    return 0;
}

pred.is_ne_exact_bif(Bif) {
    Uint index = Bif.val;

    if (Bif.type == TAG_u && index < S->beam.imports.count) {
	BeamFile_ImportEntry *entry = &S->beam.imports.entries[index];

	return entry->module == am_erlang && entry->function == am_Neq && entry->arity == 2;
    }
    return 0;
}

pred.consecutive_words(S1, D1, S2, D2) {
    return S1.type == S2.type && S1.val + 1 == S2.val &&
	D1.type == D2.type && D1.val + 1 == D2.val;
}