Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Sources/QyvoraBenchmarks/BlackBox.swift8// Module : Qyvora Benchmarks9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Synchronization4243/// Sink that makes the result of a measured operation observable, so that the optimizer cannot44/// remove the work: each call folds a few bytes of the result into a process-wide atomic45/// accumulator that the report exposes (`BlackBox.checksum`). The functions are never inlined.46public enum BlackBox {47 private static let accumulator = Atomic<UInt64>(0)4849 /// Value of the accumulator; only meaningful as proof that the results were consumed.50 public static var checksum: UInt64 { accumulator.load(ordering: .relaxed) }5152 @inline(never)53 public static func consume(_ value: UInt64) {54 accumulator.wrappingAdd(value | 1, ordering: .relaxed)55 }5657 @inline(never)58 public static func consume(_ bytes: [UInt8]) {59 let first = UInt64(bytes.first ?? 0)60 let last = UInt64(bytes.last ?? 0)61 accumulator.wrappingAdd((UInt64(truncatingIfNeeded: bytes.count) << 16) | (first << 8) | last | 1, ordering: .relaxed)62 }6364 @inline(never)65 public static func consume(_ flag: Bool) {66 accumulator.wrappingAdd(flag ? 3 : 1, ordering: .relaxed)67 }68}69