aboutsummaryrefslogtreecommitdiff
path: root/src/BuiltinFn.zig
AgeCommit message (Collapse)Author
2023-11-24frontend: move BuiltinFn to std.zig namespaceMeghan Denny
2023-10-01Sema: add `@errorCast` which works for both error sets and error unionsVeikka Tuominen
Closes #17343
2023-09-27Rename `@fabs` to `@abs` and accept integersantlilja
Replaces the @fabs builtin with a new @abs builtins which accepts floats, signed integers and vectors of said types.
2023-07-12Remove len parameter from splat builtin functionantlilja
Resolve the result type of the splat builtin instead of requiring a length parameter.
2023-06-24compiler: remove destination type from cast builtinsmlugg
Resolves: #5909
2023-06-19compiler: rename "@XToY" to "@YFromX", zig fmt: rewrite themEric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-02Implement multi-argument @min/@max and notice boundsmlugg
Resolves: #14039
2023-04-25change semantics of `@memcpy` and `@memset`Andrew Kelley
Now they use slices or array pointers with any element type instead of requiring byte pointers. This is a breaking enhancement to the language. The safety check for overlapping pointers will be implemented in a future commit. closes #14040
2023-04-23Add `@inComptime` builtinmlugg
Resolves: #868
2023-03-30new builtins: @workItemId, @workGroupId, @workGroupSizeRobin Voetter
* @workItemId returns the index of the work item in a work group for a dimension. * @workGroupId returns the index of the work group in the kernel dispatch for a dimension. * @workGroupSize returns the size of the work group for a dimension. These builtins are mainly useful for GPU backends. They are currently only implemented for the AMDGCN LLVM backend.
2023-03-04add @trap builtinr00ster91
This introduces a new builtin function that compiles down to something that results in an illegal instruction exception/interrupt. It can be used to exit a program abnormally. This implements the builtin for all backends.
2023-02-15split `@qualCast` into `@constCast` and `@volatileCast`Veikka Tuominen
2023-01-30implement `@qualCast`Veikka Tuominen
2022-12-27Sema: make overflow arithmetic builtins return tuplesVeikka Tuominen
2022-12-17implement defining C variadic functionsVeikka Tuominen
2022-10-18all: rename `@maximum` to `@max` and `@minimum` to `@min`Ali Chraghi
2022-10-12stage2: add @addrSpaceCast builtinRobin Voetter
2022-08-22stage2+stage1: remove type parameter from bit builtinsVeikka Tuominen
Closes #12529 Closes #12511 Closes #6835
2022-04-27add new builtin function `@tan`Andrew Kelley
The reason for having `@tan` is that we already have `@sin` and `@cos` because some targets have machine code instructions for them, but in the case that the implementation needs to go into compiler-rt, sin, cos, and tan all share a common dependency which includes a table of data. To avoid duplicating this table of data, we promote tan to become a builtin alongside sin and cos. ZIR: The tag enum is at capacity so this commit moves `field_call_bind_named` to be `extended`. I measured this as one of the least used tags in the zig codebase. Fix libc math suffix for `f32` being wrong in both stage1 and stage2. stage1: add missing libc prefix for float functions.
2021-12-10AstGen: implement @prefetch() builtinIsaac Freund
2021-10-25AstGen: move nodeMayEvalToError logic for builtinsAndrew Kelley
to the declarative BuiltinFn.zig file which lists info about all the builtin functions.
2021-09-28AstGen: improved logic for nodeMayNeedMemoryLocationAndrew Kelley
* `@as` and `@bitCast` no longer unconditionally return `true` from this function; they forward the question to their sub-expression. * fix `@splat` incorrectly being marked as needing a memory location (this function returns a SIMD vector; it definitely does not want a memory location). Makes AstGen generate slightly nicer ZIR, which in turn generates slightly nicer AIR, generating slightly nicer machine code in debug builds. It also means I can procrastinate implementing the bitcast_result_ptr ZIR instruction semantic analysis :^)
2021-09-28saturating arithmetic modificationsAndrew Kelley
* Remove the builtins `@addWithSaturation`, `@subWithSaturation`, `@mulWithSaturation`, and `@shlWithSaturation` now that we have first-class syntax for saturating arithmetic. * langref: Clarify the behavior of `@shlExact`. * Ast: rename `bit_shift_left` to `shl` and `bit_shift_right` to `shr` for consistency. * Air: rename to include underscore separator with consistency with the rest of the ops. * Air: add shl_exact instruction * Use non-extended tags for saturating arithmetic, to keep it simple so that all the arithmetic operations can be done the same way. - Sema: unify analyzeArithmetic with analyzeSatArithmetic - implement comptime `+|`, `-|`, and `*|` - allow float operands to saturating arithmetic * `<<|` allows any integer type for the RHS. * C backend: fix rebase conflicts * LLVM backend: reduce the amount of branching for arithmetic ops * zig.h: fix magic number not matching actual size of C integer types
2021-09-01saturating arithmetic builtins: add, sub, mul, shl (#9619)travisstaloch
- adds 1 simple behavior tests for each which does integer and vector ops at runtime and comptime - adds bigint_*_sat() methods for each - use CreateIntrinsic() which accepts a variable number of arguments to pass the scale parameter * update langref - added case to test/compile_errors.zig given floats - explain upstream bug in llvm.smul.fix.sat and link to #9643 in langref and commented out test cases * sat-arithmetic: skip mul tests if arch == .wasm32 because ci is erroring with 'LLVM ERROR: Unable to expand fixed point multiplication' when compiling for wasm32
2021-07-26minimum/maximum builtinsRobin Voetter
2021-07-26Add @selectRobin Voetter
@select( comptime T: type, pred: std.meta.Vector(len, bool), a: std.meta.Vector(len, T), b: std.meta.Vector(len, T) ) std.meta.Vector(len, T) Constructs a vector from a & b, based on the values in the predicate vector. For indices where the predicate value is true, the corresponding element from the a vector is selected, and otherwise from b.
2021-07-01stage2: fix `@asyncCall` parameter countVeikka Tuominen
Closes #9269
2021-06-12Renamed @byteOffsetOf to @offsetOfExonorid
2021-05-31std.sync.atomic: extended atomic helper functions (#8866)protty
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint` - added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int - in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer - added fence() and compilerFence() to std.atomic
2021-04-24AstGen: implement `@Vector`Andrew Kelley
2021-04-22std: fix compile errors caught by stage2 AstGenAndrew Kelley
Follow-up from 507a8096d2f9624bafaf963c3e189a477ef6b7bf
2021-04-22AstGen: implement `@extern` builtinAndrew Kelley
2021-04-21AstGen: fix `@floatCast` having wrong arityAndrew Kelley
It's not time for #5909 yet.
2021-04-19stage2: make `@alignCast` accept 2 parametersAndrew Kelley
It is not yet time to implement #5909.
2021-04-06stage2: implement simple enumsAndrew Kelley
A simple enum is an enum which has an automatic integer tag type, all tag values automatically assigned, and no top level declarations. Such enums are created directly in AstGen and shared by all the generic/comptime instantiations of the surrounding ZIR code. This commit implements, but does not yet add any test cases for, simple enums. A full enum is an enum for which any of the above conditions are not true. Full enums are created in Sema, and therefore will create a unique type per generic/comptime instantiation. This commit does not implement full enums. However the `enum_decl_nonexhaustive` ZIR instruction is added and the respective Type functions are filled out. This commit makes an improvement to ZIR code, removing the decls array and removing the decl_map from AstGen. Instead, decl_ref and decl_val ZIR instructions index into the `owner_decl.dependencies` ArrayHashMap. We already need this dependencies array for incremental compilation purposes, and so repurposing it to also use it for ZIR decl indexes makes for efficient memory usage. Similarly, this commit fixes up incorrect memory management by removing the `const` ZIR instruction. The two places it was used stored memory in the AstGen arena, which may get freed after Sema. Now it properly sets up a new anonymous Decl for error sets and uses a normal decl_val instruction. The other usage of `const` ZIR instruction was float literals. These are now changed to use `float` ZIR instruction when the value fits inside `zir.Inst.Data` and `float128` otherwise. AstGen + Sema: implement int_to_enum and enum_to_int. No tests yet; I expect to have to make some fixes before they will pass tests. Will do that in the branch before merging. AstGen: fix struct astgen incorrectly counting decls as fields. Type/Value: give up on trying to exhaustively list every tag all the time. This makes the file more manageable. Also found a bug with i128/u128 this way, since the name of the function was more obvious when looking at the tag values. Type: implement abiAlignment and abiSize for structs. This will need to get more sophisticated at some point, but for now it is progress. Value: add new `enum_field_index` tag. Value: add hash_u32, needed when using ArrayHashMap.
2021-03-17@intCast takes two argsDimenus
2021-02-18stage2: astgen: fix most of the remaining compile errorsAndrew Kelley
more progress on converting astgen to the new AST memory layout. only a few code paths left to update.
2021-02-15astgen: update more expression types to new mem layoutAndrew Kelley
additionally introduce a new file to centralize all the data about builtin functions that we have, including: * enum tag identifying the builtin function * number of parameters. * whether the expression may need a memory location. * whether the expression allows an lvalue (currently only true for `@field`). Now there is only one ComptimeStringMap that has this data as the value, and we dispatch on the enum tag in order to asgen the builtin function. In particular this simplifies the logic for checking the number of parameters. This removes some untested code paths from if and while, which need to be restored with #7929 in mind. After this there are only a handful left of expression types to rework to the new memory layout, and then it will be only compile errors left to solve.