@geastack/compiler 1.0.22 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,6 +51,19 @@ const nativeHandleProperty = (protocol, emit) => ({
51
51
  emit,
52
52
  resultRepresentation: { kind: 'native-handle', protocol, version: 1, native: null, bases: [], call: null, construct: null }
53
53
  });
54
+ /**
55
+ * A `Math` function: a first-class read is the `HostFunction` value, and a
56
+ * call with numeric arguments is a direct call of the same `detail::*_invoke`
57
+ * the value would forward to. Without the direct spelling every call in a
58
+ * pixel loop materialized a `CallableObject` and called through it -- Bloom's
59
+ * Gray-Scott step made forty of those per cell per frame.
60
+ */
61
+ const mathDirect = (name, arity) => ({
62
+ kind: 'property',
63
+ store: null,
64
+ emit: `gea::host::Math::${name}`,
65
+ numericDirectCall: { arity, emit: `gea::host::Math::detail::${name}_invoke(nullptr, ${arity === 1 ? '{arg0}' : '{arg0}, {arg1}'})` }
66
+ });
54
67
  export const coreHostMembers = new Map([
55
68
  // Atomics is a finite language primitive, not an any-shaped Node shim. The
56
69
  // call-site renderer verifies the concrete typed-array element carrier and
@@ -149,7 +162,7 @@ export const coreHostMembers = new Map([
149
162
  // these). Borrowed Object.prototype.toString calls use ObjectTag and its
150
163
  // native @@toStringTag lookup instead of this direct member path.
151
164
  ['Math.toString', { kind: 'method', emit: 'std::string("[object Math]")', arity: 0 }],
152
- ['Math.floor', { kind: 'property', store: null, emit: 'gea::host::Math::floor' }],
165
+ ['Math.floor', mathDirect('floor', 1)],
153
166
  [
154
167
  'Math.round',
155
168
  {
@@ -159,20 +172,20 @@ export const coreHostMembers = new Map([
159
172
  numericDirectCall: { arity: 1, emit: 'gea::host::Math::detail::round_invoke(nullptr, {arg0})' }
160
173
  }
161
174
  ],
162
- ['Math.sin', { kind: 'property', store: null, emit: 'gea::host::Math::sin' }],
163
- ['Math.cos', { kind: 'property', store: null, emit: 'gea::host::Math::cos' }],
164
- ['Math.sqrt', { kind: 'property', store: null, emit: 'gea::host::Math::sqrt' }],
165
- ['Math.abs', { kind: 'property', store: null, emit: 'gea::host::Math::abs' }],
166
- ['Math.ceil', { kind: 'property', store: null, emit: 'gea::host::Math::ceil' }],
167
- ['Math.pow', { kind: 'property', store: null, emit: 'gea::host::Math::pow' }],
168
- ['Math.atan2', { kind: 'property', store: null, emit: 'gea::host::Math::atan2' }],
175
+ ['Math.sin', mathDirect('sin', 1)],
176
+ ['Math.cos', mathDirect('cos', 1)],
177
+ ['Math.sqrt', mathDirect('sqrt', 1)],
178
+ ['Math.abs', mathDirect('abs', 1)],
179
+ ['Math.ceil', mathDirect('ceil', 1)],
180
+ ['Math.pow', mathDirect('pow', 2)],
181
+ ['Math.atan2', mathDirect('atan2', 2)],
169
182
  ['Math.random', { kind: 'property', store: null, emit: 'gea::host::Math::random' }],
170
- ['Math.tan', { kind: 'property', store: null, emit: 'gea::host::Math::tan' }],
171
- ['Math.asin', { kind: 'property', store: null, emit: 'gea::host::Math::asin' }],
172
- ['Math.acos', { kind: 'property', store: null, emit: 'gea::host::Math::acos' }],
173
- ['Math.atan', { kind: 'property', store: null, emit: 'gea::host::Math::atan' }],
174
- ['Math.sinh', { kind: 'property', store: null, emit: 'gea::host::Math::sinh' }],
175
- ['Math.log', { kind: 'property', store: null, emit: 'gea::host::Math::log' }],
183
+ ['Math.tan', mathDirect('tan', 1)],
184
+ ['Math.asin', mathDirect('asin', 1)],
185
+ ['Math.acos', mathDirect('acos', 1)],
186
+ ['Math.atan', mathDirect('atan', 1)],
187
+ ['Math.sinh', mathDirect('sinh', 1)],
188
+ ['Math.log', mathDirect('log', 1)],
176
189
  // All three retain their array-parameter callable values. Direct numeric
177
190
  // max/min calls can additionally borrow a stack sequence without allocating
178
191
  // the rest array; aliases and spreads keep the ordinary value spelling.
@@ -186,22 +199,22 @@ export const coreHostMembers = new Map([
186
199
  // Each row names a symbol that header really declares, in the same
187
200
  // `CallableObject<double(double)>` shape as the rows above -- `imul` is the
188
201
  // one binary member.
189
- ['Math.cbrt', { kind: 'property', store: null, emit: 'gea::host::Math::cbrt' }],
190
- ['Math.sign', { kind: 'property', store: null, emit: 'gea::host::Math::sign' }],
191
- ['Math.trunc', { kind: 'property', store: null, emit: 'gea::host::Math::trunc' }],
192
- ['Math.exp', { kind: 'property', store: null, emit: 'gea::host::Math::exp' }],
193
- ['Math.expm1', { kind: 'property', store: null, emit: 'gea::host::Math::expm1' }],
194
- ['Math.log10', { kind: 'property', store: null, emit: 'gea::host::Math::log10' }],
195
- ['Math.log1p', { kind: 'property', store: null, emit: 'gea::host::Math::log1p' }],
196
- ['Math.log2', { kind: 'property', store: null, emit: 'gea::host::Math::log2' }],
197
- ['Math.cosh', { kind: 'property', store: null, emit: 'gea::host::Math::cosh' }],
198
- ['Math.tanh', { kind: 'property', store: null, emit: 'gea::host::Math::tanh' }],
199
- ['Math.acosh', { kind: 'property', store: null, emit: 'gea::host::Math::acosh' }],
200
- ['Math.asinh', { kind: 'property', store: null, emit: 'gea::host::Math::asinh' }],
201
- ['Math.atanh', { kind: 'property', store: null, emit: 'gea::host::Math::atanh' }],
202
- ['Math.fround', { kind: 'property', store: null, emit: 'gea::host::Math::fround' }],
203
- ['Math.clz32', { kind: 'property', store: null, emit: 'gea::host::Math::clz32' }],
204
- ['Math.imul', { kind: 'property', store: null, emit: 'gea::host::Math::imul' }],
202
+ ['Math.cbrt', mathDirect('cbrt', 1)],
203
+ ['Math.sign', mathDirect('sign', 1)],
204
+ ['Math.trunc', mathDirect('trunc', 1)],
205
+ ['Math.exp', mathDirect('exp', 1)],
206
+ ['Math.expm1', mathDirect('expm1', 1)],
207
+ ['Math.log10', mathDirect('log10', 1)],
208
+ ['Math.log1p', mathDirect('log1p', 1)],
209
+ ['Math.log2', mathDirect('log2', 1)],
210
+ ['Math.cosh', mathDirect('cosh', 1)],
211
+ ['Math.tanh', mathDirect('tanh', 1)],
212
+ ['Math.acosh', mathDirect('acosh', 1)],
213
+ ['Math.asinh', mathDirect('asinh', 1)],
214
+ ['Math.atanh', mathDirect('atanh', 1)],
215
+ ['Math.fround', mathDirect('fround', 1)],
216
+ ['Math.clz32', mathDirect('clz32', 1)],
217
+ ['Math.imul', mathDirect('imul', 2)],
205
218
  // `readonly PI: number` -- a data property, and the one member here that is
206
219
  // not a callable at all.
207
220
  ['Math.PI', { kind: 'property', store: null, emit: 'gea::host::Math::PI' }],
@@ -327,4 +327,6 @@ export declare const cppTypeOf: (representation: Representation, ownership?: Own
327
327
  * unnarrowed form agree everywhere the census says they do.
328
328
  */
329
329
  export declare const cppNarrowedIntegerType = "long long";
330
+ /** The storage `ir/floats.ts` admits a float32-valued Number into. */
331
+ export declare const cppNarrowedFloatType = "float";
330
332
  export declare const cppBoxedType: (representation: Representation) => string;
@@ -1338,4 +1338,6 @@ export const cppTypeOf = (representation, ownership = null) => {
1338
1338
  * unnarrowed form agree everywhere the census says they do.
1339
1339
  */
1340
1340
  export const cppNarrowedIntegerType = 'long long';
1341
+ /** The storage `ir/floats.ts` admits a float32-valued Number into. */
1342
+ export const cppNarrowedFloatType = 'float';
1341
1343
  export const cppBoxedType = (representation) => `gea::Ref<${cppTypeOf(representation)}>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/compiler",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -79,20 +79,20 @@
79
79
  "fastify": "^5.0.0",
80
80
  "find-my-way": "9.6.0",
81
81
  "prettier": "^3.8.3",
82
- "@geastack/core": "0.1.35",
82
+ "@geastack/core": "0.1.37",
83
83
  "@geastack/host": "0.1.14",
84
- "@geastack/engine": "0.1.11",
85
- "@geastack/elements": "0.1.4",
84
+ "@geastack/engine": "0.1.13",
85
+ "@geastack/elements": "0.1.5",
86
86
  "@geastack/geaos": "0.1.3",
87
- "@geastack/apple": "0.2.13",
88
- "@geastack/geatsc-plugin-gea": "0.1.17",
87
+ "@geastack/apple": "0.2.14",
88
+ "@geastack/geatsc-plugin-gea": "0.1.19",
89
89
  "@geastack/geatsc-plugin-apple-native": "0.1.4",
90
- "@geastack/native-webgl-angle": "0.1.8"
90
+ "@geastack/native-webgl-angle": "0.1.9"
91
91
  },
92
92
  "peerDependencies": {
93
- "@geastack/apple": ">=0.2.13",
93
+ "@geastack/apple": ">=0.2.14",
94
94
  "@geastack/geatsc-plugin-apple-native": ">=0.1.4",
95
- "@geastack/geatsc-plugin-gea": ">=0.1.17"
95
+ "@geastack/geatsc-plugin-gea": ">=0.1.19"
96
96
  },
97
97
  "peerDependenciesMeta": {
98
98
  "@geastack/apple": {
@@ -98,6 +98,30 @@
98
98
 
99
99
  namespace gea {
100
100
 
101
+ /** A single-precision product the compiler may not fuse into a following add.
102
+ * `Math.fround(a * b) + c` is two roundings in ECMA-262; GCC's default
103
+ * `-ffp-contract=fast` turns the pair into one `fmadd.s`, a single rounding, so
104
+ * a float32 product (`ir/floats.ts`) passes through an empty asm that pins it
105
+ * in an FP register. That blocks the contraction for this value alone, where
106
+ * a translation-unit `-ffp-contract=off` would also take FMA away from every
107
+ * hand-written DSP loop in the engine. Clang's default contracts only within
108
+ * one expression, which an emitted statement-per-operation never offers. */
109
+ [[gnu::always_inline]] inline float float32Product(float value) {
110
+ // GEA_FLOAT32_ALLOW_CONTRACTION lets GCC fuse again, for measuring what the
111
+ // second rounding costs; results then differ from Node in the last bit.
112
+ #if defined(GEA_FLOAT32_ALLOW_CONTRACTION)
113
+ #elif (defined(__riscv) && defined(__riscv_flen)) || (defined(__xtensa__) && !defined(__XTENSA_SOFT_FLOAT__))
114
+ __asm__("" : "+f"(value));
115
+ #elif defined(__aarch64__)
116
+ __asm__("" : "+w"(value));
117
+ #elif defined(__arm__) && defined(__ARM_FP)
118
+ __asm__("" : "+t"(value));
119
+ #elif (defined(__x86_64__) || defined(__i386__)) && defined(__SSE__)
120
+ __asm__("" : "+x"(value));
121
+ #endif
122
+ return value;
123
+ }
124
+
101
125
  namespace detail {
102
126
 
103
127
  inline void collectReferenceCycles(bool full);
@@ -7891,6 +7915,26 @@ inline ClampedUint8 typedArrayElement<ClampedUint8>(double value) {
7891
7915
  if (value > floorValue + 0.5) return ClampedUint8{static_cast<std::uint8_t>(floorValue + 1.0)};
7892
7916
  return ClampedUint8{static_cast<std::uint8_t>(std::fmod(floorValue, 2.0) == 0.0 ? floorValue : floorValue + 1.0)};
7893
7917
  }
7918
+
7919
+ /**
7920
+ * `typedArrayElement` for a value the integer census already holds as an
7921
+ * integer. ToIntN/ToUintN of an integer is its low N bits, which is what an
7922
+ * unsigned conversion keeps; a float element is the integer rounded once,
7923
+ * exactly as converting its (exact) double would round it; a clamped byte
7924
+ * clamps, and an integer has no half to round. All in integer registers: the
7925
+ * `double` route costs a software modulo per element on a core with no double
7926
+ * FPU -- an RGB565 palette store paid four of them per pixel.
7927
+ */
7928
+ template <typename T>
7929
+ [[gnu::always_inline]] inline T typedArrayIntegerElement(long long value) {
7930
+ if constexpr (std::is_same_v<T, ClampedUint8>) {
7931
+ return ClampedUint8{static_cast<std::uint8_t>(value <= 0 ? 0 : value >= 255 ? 255 : value)};
7932
+ } else if constexpr (std::is_integral_v<T>) {
7933
+ return static_cast<T>(static_cast<std::make_unsigned_t<T>>(static_cast<unsigned long long>(value)));
7934
+ } else {
7935
+ return static_cast<T>(value);
7936
+ }
7937
+ }
7894
7938
  } // namespace detail
7895
7939
 
7896
7940
  /**
@@ -8176,6 +8220,16 @@ class TypedArray {
8176
8220
  const T converted = detail::typedArrayElement<T>(value);
8177
8221
  std::memcpy(reinterpret_cast<std::uint8_t*>(base) + index * sizeof(T), &converted, sizeof(T));
8178
8222
  }
8223
+ /** `writeInBounds` for a value the integer census holds as an integer (`detail::typedArrayIntegerElement`). */
8224
+ [[gnu::always_inline]] static void writeIntegerInBounds(T* base, std::size_t index, long long value) {
8225
+ const T converted = detail::typedArrayIntegerElement<T>(value);
8226
+ std::memcpy(reinterpret_cast<std::uint8_t*>(base) + index * sizeof(T), &converted, sizeof(T));
8227
+ }
8228
+ /** An integer element as the integer it is, for a result the integer census holds in a `long long`. */
8229
+ [[gnu::always_inline]] static long long readIntegerInBounds(const T* base, std::size_t index) {
8230
+ if constexpr (std::is_same_v<T, ClampedUint8>) return readInBounds(base, index).bits;
8231
+ else return static_cast<long long>(readInBounds(base, index));
8232
+ }
8179
8233
  T operator[](std::size_t index) const { return readUnchecked(index); }
8180
8234
  T operator[](std::size_t index) { return readUnchecked(index); }
8181
8235
  operator std::vector<T>() const {
@@ -8198,6 +8252,14 @@ class TypedArray {
8198
8252
  * byte of every message through this.
8199
8253
  */
8200
8254
  [[gnu::always_inline]] double elementAtIndex(long long key) const { return static_cast<double>(readUnchecked(requireIndexAt(key))); }
8255
+ /** `elementAtIndex` of an integer view, read into the integer a narrowed result is: no round trip through `double`. */
8256
+ [[gnu::always_inline]] long long elementIntegerAtIndex(long long key) const
8257
+ requires(std::is_integral_v<T> || std::is_same_v<T, ClampedUint8>)
8258
+ {
8259
+ const T value = readUnchecked(requireIndexAt(key));
8260
+ if constexpr (std::is_same_v<T, ClampedUint8>) return value.bits;
8261
+ else return static_cast<long long>(value);
8262
+ }
8201
8263
  /**
8202
8264
  * A key straight from `charCodeAt` -- a `gea::runtime::string::CodeUnit`, a
8203
8265
  * code unit or the out-of-range NaN carried as the sentinel 65536. Every
@@ -8220,6 +8282,11 @@ class TypedArray {
8220
8282
  if (static_cast<unsigned long long>(key) >= size()) return;
8221
8283
  writeUnchecked(static_cast<std::size_t>(key), detail::typedArrayElement<T>(value));
8222
8284
  }
8285
+ /** `setElementAtIndex` for an integer value (`detail::typedArrayIntegerElement`). */
8286
+ [[gnu::always_inline]] void setElementIntegerAtIndex(long long key, long long value) {
8287
+ if (static_cast<unsigned long long>(key) >= size()) return;
8288
+ writeUnchecked(static_cast<std::size_t>(key), detail::typedArrayIntegerElement<T>(value));
8289
+ }
8223
8290
 
8224
8291
  /**
8225
8292
  * Whether an indexed read would answer an element -- `requireIndex`'s abort
@@ -8481,17 +8548,26 @@ class TypedArray {
8481
8548
  // Shared accesses take the one mutex owned by their backing block. The raw
8482
8549
  // helpers remain the non-shared fast path and the implementation used while
8483
8550
  // an atomic operation already owns that mutex.
8484
- T readUnchecked(std::size_t index) const {
8485
- if (!sharedBuffer_) return readInBounds(data(), index);
8551
+ // Inline for the ordinary view, the shared view's lock out of line: with
8552
+ // the lock inside, `-Os` kept the whole function a call, and every element
8553
+ // read a loop could not window paid one.
8554
+ [[gnu::always_inline]] T readUnchecked(std::size_t index) const {
8555
+ if (!sharedBuffer_) [[likely]] return readInBounds(data(), index);
8556
+ return readSharedUnchecked(index);
8557
+ }
8558
+ [[gnu::noinline]] T readSharedUnchecked(std::size_t index) const {
8486
8559
  std::lock_guard lock(sharedBuffer_->memoryMutex());
8487
8560
  return readInBounds(data(), index);
8488
8561
  }
8489
- void writeUnchecked(std::size_t index, T value) {
8562
+ [[gnu::always_inline]] void writeUnchecked(std::size_t index, T value) {
8490
8563
  bytes_->requireAttached();
8491
- if (!sharedBuffer_) {
8564
+ if (!sharedBuffer_) [[likely]] {
8492
8565
  std::memcpy(base_ + index * sizeof(T), &value, sizeof(T));
8493
8566
  return;
8494
8567
  }
8568
+ writeSharedUnchecked(index, value);
8569
+ }
8570
+ [[gnu::noinline]] void writeSharedUnchecked(std::size_t index, T value) {
8495
8571
  std::lock_guard lock(sharedBuffer_->memoryMutex());
8496
8572
  std::memcpy(base_ + index * sizeof(T), &value, sizeof(T));
8497
8573
  }